Temporary Internet Files Path구하기
#include <ShFolder.h>
ShFolder.lib
SHGetFolderPath(NULL, CSIDL_INTERNET_CACHE, NULL, 0, szPath);
케이피
OOP, Debugging... 인생의 숙제들..... [블로그의 글을 맹신하면 곤란]
BOOL CPCOptimizerDlg::DelTempFiles()
{
BOOL bResult = FALSE;
BOOL bDone = FALSE;
LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
DWORD dwTrySize, dwEntrySize = 4096; // 시작 버퍼 크기
HANDLE hCacheDir = NULL;
DWORD dwError = ERROR_INSUFFICIENT_BUFFER;
do
{
switch (dwError)
{
// 좀더 큰 버퍼가 필요하다.
case ERROR_INSUFFICIENT_BUFFER:
delete [] lpCacheEntry;
lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
lpCacheEntry->dwStructSize = dwEntrySize;
dwTrySize = dwEntrySize;
BOOL bSuccess;
if (hCacheDir == NULL)
bSuccess = (hCacheDir
= FindFirstUrlCacheEntry(NULL, lpCacheEntry,
&dwTrySize)) != NULL;
else
bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
if (bSuccess)
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // 새 버퍼 크기
}
break;
// 작업 완료
case ERROR_NO_MORE_ITEMS:
bDone = TRUE;
bResult = TRUE;
break;
// 엔트리 확보
case ERROR_SUCCESS:
// 쿠키 파일 삭제 금지
if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
// 다음 엔트리 얻기
dwTrySize = dwEntrySize;
if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
dwError = ERROR_SUCCESS;
else
{
dwError = GetLastError();
dwEntrySize = dwTrySize; // 새로운 사이즈
}
break;
// 에러
default:
bDone = TRUE;
break;
}
if (bDone)
{
delete [] lpCacheEntry;
if (hCacheDir)
FindCloseUrlCache(hCacheDir);
}
} while (!bDone);
return bResult;
}
쿠키 파일만 빼고 다 지우는거다.
From CodeGuru
#include <IPHlpApi.h> // for GetAdaptersInfo()
#pragma comment(lib, "iphlpapi.lib" )
CString CMacIPTestDlg::GetMACAddress()
{
CString strMac;
DWORD size = sizeof(PIP_ADAPTER_INFO);
PIP_ADAPTER_INFO Info;
ZeroMemory( &Info, size );
int result = GetAdaptersInfo( Info, &size ); // 첫번째 랜카드 MAC address 가져오기
if (result == ERROR_BUFFER_OVERFLOW) // GetAdaptersInfo가 메모리가 부족하면 재 할당하고 재호출
{
Info = (PIP_ADAPTER_INFO)malloc(size);
GetAdaptersInfo( Info, &size );
}
if(!Info)
return strMac;
strMac.Format("%0.2X-%0.2X-%0.2X-%0.2X-%0.2X-%0.2X", Info->Address[0], Info->Address[1], Info->Address[2], Info->Address[3], Info->Address[4], Info->Address[5] );
return strMac;
}
1. Windows SDK or Vista SDK 등을 설치해야한다.
2. include, lib 폴더를 포함하고 최상위로 이동시킨다.
3. 그래도 안돼면
include하는 디렉토리 중에 microsoftvisualstudio/vc98/include 아래 있는 iprtrmib.h 를 지우고 microsoftsdk/include/iprtrmib.h를 copy하고 컴파일하면 해결될 것임.
#include <windows.h>
#include <wininet.h>
#include <iostream.h>
DWORD WINAPI WorkerFunction( LPVOID );
HINTERNET g_hOpen, g_hConnect;
typedef struct
{
CHAR* pHost;
CHAR* pUser;
CHAR* pPass;
} PARM;
void main()
{
CHAR szHost[] = "localhost";
CHAR szUser[] = "JoeB";
CHAR szPass[] = "test";
CHAR szLocalFile[] = "localfile";
CHAR szRemoteFile[] = "remotefile";
DWORD dwExitCode;
DWORD dwTimeout;
PARM threadParm;
g_hOpen = 0;
if ( !( g_hOpen = InternetOpen ( "FTP sample",
LOCAL_INTERNET_ACCESS,
NULL,
0,
0 ) ) )
{
cerr << "Error on InternetOpen: " << GetLastError() << endl;
return ;
}
// Create a worker thread
HANDLE hThread;
DWORD dwThreadID;
threadParm.pHost = szHost;
threadParm.pUser = szUser;
threadParm.pPass = szPass;
hThread = CreateThread(
NULL, // Pointer to thread security attributes
0, // Initial thread stack size, in bytes
WorkerFunction, // Pointer to thread function
&threadParm, // The argument for the new thread
0, // Creation flags
&dwThreadID // Pointer to returned thread identifier
);
// Wait for the call to InternetConnect in worker function to complete
dwTimeout = 5000; // in milliseconds
if ( WaitForSingleObject ( hThread, dwTimeout ) == WAIT_TIMEOUT )
{
cout << "Can not connect to server in "
<< dwTimeout << " milliseconds" << endl;
if ( g_hOpen )
InternetCloseHandle ( g_hOpen );
// Wait until the worker thread exits
WaitForSingleObject ( hThread, INFINITE );
cout << "Thread has exited" << endl;
return ;
}
// The state of the specified object (thread) is signaled
dwExitCode = 0;
if ( !GetExitCodeThread( hThread, &dwExitCode ) )
{
cerr << "Error on GetExitCodeThread: " << GetLastError() << endl;
return ;
}
CloseHandle (hThread);
if ( dwExitCode )
// Worker function failed
return ;
if ( !FtpGetFile ( g_hConnect,
szRemoteFile,
szLocalFile,
FALSE,INTERNET_FLAG_RELOAD,
FTP_TRANSFER_TYPE_ASCII,
0 ) )
{
cerr << "Error on FtpGetFile: " << GetLastError() << endl;
return ;
}
if ( g_hConnect )
InternetCloseHandle( g_hConnect );
if ( g_hOpen )
InternetCloseHandle( g_hOpen );
return ;
}
/////////////////// WorkerFunction //////////////////////
DWORD WINAPI
WorkerFunction(
IN LPVOID vThreadParm
)
/*
Purpose:
Call InternetConnect to establish a FTP session
Arguments:
vThreadParm - points to PARM passed to thread
Returns:
returns 0
*/
{
PARM* pThreadParm;
// Initialize local pointer to void pointer passed to thread
pThreadParm = (PARM*)vThreadParm;
g_hConnect = 0;
if ( !( g_hConnect = InternetConnect (
g_hOpen,
pThreadParm->pHost,
INTERNET_INVALID_PORT_NUMBER,
pThreadParm->pUser,
pThreadParm->pPass,
INTERNET_SERVICE_FTP,
0,
0 ) ) )
{
cerr << "Error on InternetConnnect: " << GetLastError() << endl;
return 1; // failure
}
return 0; // success
}
GDIPlus 사용
메뉴의
Project>Settins 메뉴에서 Link 탭을 선택한후
Object/Library Modules 란에
gdiplus.lib 라고 쳐 넣는다..
xxxxApp 클래스에서..
InitInstance() 함수를 오버라이딩 하여
AfxDll Import하기전 상단에... (이게 은근중요 가끔 안될때 있다...ㅎㅎ)
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
위의 코드 2줄을 쳐 넣고..
ExitInstance() 를 함수를 오버라이딩 하여
GdiplusShutdown(m_gdiplusToken);
위의 코드를 넣는다..
그리고.. 멤버변수 하나를 다음과 같이 만듭니다.
ULONG_PTR m_gdiplusToken;
위의 코딩은 전부 xxxApp 클래스에서 작성합니다..
다음 마지막으로..
stdAfx.h 에
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#endif
#include <gdiplus.h>
using namespace Gdiplus;
를 추가하면 OK!
그럼 사용할수 있습니다.
이렇게 하면 GDI PLUS 에 대해 Intellisense 기능을 사용 못하더라구여..
머 일일히 헤더를 추가하면 사용할수 있을겁니다..
MSDN 을 참조하여 작업하시면 됩니다..
그럼 참조하세요..
GDI+를 이제서야 사용해보다니... 부끄럽도다... ㅠ.ㅠ
MFC
사용하지 않는 DLL의 LIB를 link 시켜놨을 때
디버그 모드와는 달리 릴리즈 모드에선 경고를 뱉는다.
< LINK : warning LNK4089: all references to "안쓰는DLL.dll" discarded by /OPT:REF >
이 때 무시하고 그냥 릴리즈 모드의 프로그램을 VS에서 실행이 아닌
단독으로 실행 시키면 전혀 관계없는 곳에서 죽을 수도 있다... 진짜 전혀 관계없는곳에서...
(나같은 경우는 PC가 스스로 종료하려 했음... -0-;;;)
얕은 지식덕에 자세한건 모르겠지만... 메모리가 얽키는듯...
이놈의 얕은 지식... 누구 확실히 아는 사람 없나... ㅠ_ㅠ
무조건 저 경고를 없애야 한다...
릴리즈모드의 Project Setting - Link탭 - Incrementally를 켜면 경고는 안뜨지만...
죽지 않는다고 보장할수없다...