1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include "Windows.h"
#include "Shlobj.h"
#include <cstdio>
#pragma comment(lib, "shell32.lib")
typedef BOOL (WINAPI * pSHGetSpecialFolderPathW)(HWND rsv, LPWSTR folderBuff, int CSIDL, BOOL Create);
class SHELL32
{
private:
HMODULE MODULE_SHELL32;
pSHGetSpecialFolderPathW SHGetSpecialFolderPathW;
public:
SHELL32();
~SHELL32();
bool callSpecialFolder(HWND rsv, LPWSTR folderBuff, int CSIDL, bool Create);
};
SHELL32::SHELL32() : MODULE_SHELL32(NULL), SHGetSpecialFolderPathW(NULL)
{
MODULE_SHELL32 = LoadLibraryW(L"C:\\Windows\\System32\\Shell32.dll");
}
SHELL32::~SHELL32()
{
if(NULL != MODULE_SHELL32)
FreeLibrary(MODULE_SHELL32); // to be tidy
}
bool SHELL32::callSpecialFolder(HWND rsv, LPWSTR folderBuff, int CSIDL, bool Create)
{
printf("%x\n", MODULE_SHELL32);
pSHGetSpecialFolderPathW SHGetSpecialFolderPathW = (pSHGetSpecialFolderPathW)GetProcAddress(MODULE_SHELL32, "SHGetSpecialFolderPathW");
printf("%x\n", SHGetSpecialFolderPathW);
BOOL stat = Create ? TRUE : FALSE;
BOOL retCode = SHGetSpecialFolderPathW(rsv, folderBuff, CSIDL, stat);
// was CSIDL_LOCAL_APPDATA rather than
printf("%d\n", retCode);
return (FALSE != retCode);
}
//#include "stdafx.h"
//#include <Windows.h>
//#include "Shell32.h"
int main()
{
//LPWSTR folderBuff = NULL;
WCHAR folderBuff[MAX_PATH] = {0};
SHELL32 ShellDll;
ShellDll.callSpecialFolder(NULL, folderBuff, CSIDL_LOCAL_APPDATA, FALSE);
printf("%S\n", folderBuff); // was %s (need %S for Unicode)
return 0;
}
|