PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Dynamic API (help)



luxury11
30.05.2010, 20:45
Versuche SHGetSpecialFolderA zu laden.
Doch GetModuleFileNameA() gibt bei "Shell32.dll" nicht die Addresse,
sonder Fehler -> NULL. Habe das schon für CopyFileA geschrieben, bei dem alles funktioniert hat.



#include <Windows.h>
#include <ShlObj.h>

typedef
BOOL SHGetSpecialFolderPath_t(
HWND hwndOwner,
__out LPSTR lpszPath,
__in int csidl,
__in BOOL fCreate
/* Shell32.dll
TRUE if successful; otherwise, FALSE.
*/
);


bool dynamic_SHGetSpecialFolderPath(char* cPath)
{
HMODULE h_Load;
SHGetSpecialFolderPath_t* mySHGetSpecialFolderPath = 0;
h_Load = GetModuleHandleA((LPCTSTR)"Shell32.dll"); //<---
if (h_Load == false)
{
MessageBoxA(NULL,"failed","lol",0);
return false;
}
*(FARPROC*)&mySHGetSpecialFolderPath = GetProcAddress(h_Load, (LPCSTR)"SHGetSpecialFolderPathA");
mySHGetSpecialFolderPath(NULL,(LPSTR)cPath,CSIDL_A PPDATA|CSIDL_FLAG_CREATE,0);
return true;
}

blackberry
30.05.2010, 20:54
Versuch's mal mit LoadLibrary (bzw. LoadLibraryA)
GetModuleHandle gibt nur Handles von bereits geladenen Modulen zurück - also NULL, wenn shell32.dll nicht schon geladen wurde.

luxury11
30.05.2010, 21:17
Funktioniert nun einwandfrei mit LoadLibraryA().

Um keine Pfad für die DLL anzugeben kann ich auch den aliasnamen nehmen.
Den man unter
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Session Manager\KnownDLLs finden kann. Siehe MSDN-Dynamic-Link Library Redirection