Click to See Complete Forum and Search --> : SHSetFolderPath -- What's wrong with my code?


royalbox
September 19th, 2005, 09:02 PM
Hello all. I've tried everything I can think of to get SHSetFolderPath to work. Perhaps someone could look this over and let me know why GetLastError returns: error 126 (The specified module could not be found).

typedef HRESULT (*MYPROC)(int, HANDLE , DWORD , LPCTSTR );

BOOL DoCreateFolders(void)
{
HMODULE hinstLib = 0;
MYPROC ProcAddress = 0;
HRESULT hResult = 0;

hinstLib = LoadLibrary(TEXT("shell32"));

if (hinstLib == 0)
{
return FALSE;
}

MessageBox(0, TEXT("hinstLib is ok"), 0, MB_OK);
ProcAddress = (MYPROC) GetProcAddress(hinstLib, LPCTSTR(232));

if (ProcAddress == 0)
{
FreeLibrary(hinstLib);
return FALSE;
}

MessageBox(0, TEXT("ProcAddress is ok"), 0, MB_OK);
hResult = (ProcAddress)
(CSIDL_TEMPLATES | CSIDL_FLAG_CREATE,
0, 0, TEXT("C:\\Monkey"));

if (hResult == 0)
{
FreeLibrary(hinstLib);
return FALSE;
}

MessageBox(0, TEXT("hResult is ok"), 0, MB_OK);
ErrorExit(TEXT("DoCreateFolders")); // function to display last error
FreeLibrary(hinstLib);
return TRUE;
}


All the included MessageBox's pop up when run.
I only found one other mention of SHSetFolderPath when I searched, and that was left un-resolved.

Thanks for any help.

wildfrog
September 20th, 2005, 03:44 PM
Not sure if it solves your problem, but...

typedef HRESULT (WINAPI *MYPROC)(int, HANDLE , DWORD , LPCTSTR );
...and you should use NULL and S_OK etc., not 0.

- petter