A
AG
Hi all,
I have this classic code : load a dll, and get a pointer on a specific
function in that DLL.
The GetProcAddress() returns NULL, but the GetLastWin32Error()
function says : operation successful.
Then if I try to use the SetHookDll() function, my application
crashes. If I change the call to GetProcAdress with "SetHookDll2"
instead of the correct "SetHookDll", I get the right error message
from GetLastWin32Error() : cannot find the appropriate function.
Any Hint ?
Thanks in advance.
AG.
if((hinstDLL = LoadLibrary((LPCTSTR) FICHIER))==NULL)
{
print_error("Error loading library");
FreeLibrary(hinstDLL);
}
HINSTANCE module_dll;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,LPSTR("KHook"),&module_dll);
if(module_dll==NULL)
{
print_error("Error loading module");
FreeLibrary(hinstDLL);
}
if((SetHookDll=(SETHOOK_FCT)GetProcAddress(module_dll,LPSTR("SetHookDll")))==NULL)
{
print_error("Error get SetHookDll pointer");
FreeLibrary(hinstDLL);
}
FreeLibrary(hinstDLL);
with print_error defined like this :
void print_error(LPCSTR title)
{
Win32Exception^ winex = gcnew
Win32Exception(Marshal::GetLastWin32Error());
String^ errorMessage = winex->Message;
String^ myTitle = gcnew String(title);
MessageBox::Show(errorMessage,myTitle,MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
delete myTitle;
delete winex;
}
I have this classic code : load a dll, and get a pointer on a specific
function in that DLL.
The GetProcAddress() returns NULL, but the GetLastWin32Error()
function says : operation successful.
Then if I try to use the SetHookDll() function, my application
crashes. If I change the call to GetProcAdress with "SetHookDll2"
instead of the correct "SetHookDll", I get the right error message
from GetLastWin32Error() : cannot find the appropriate function.
Any Hint ?
Thanks in advance.
AG.
if((hinstDLL = LoadLibrary((LPCTSTR) FICHIER))==NULL)
{
print_error("Error loading library");
FreeLibrary(hinstDLL);
}
HINSTANCE module_dll;
GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,LPSTR("KHook"),&module_dll);
if(module_dll==NULL)
{
print_error("Error loading module");
FreeLibrary(hinstDLL);
}
if((SetHookDll=(SETHOOK_FCT)GetProcAddress(module_dll,LPSTR("SetHookDll")))==NULL)
{
print_error("Error get SetHookDll pointer");
FreeLibrary(hinstDLL);
}
FreeLibrary(hinstDLL);
with print_error defined like this :
void print_error(LPCSTR title)
{
Win32Exception^ winex = gcnew
Win32Exception(Marshal::GetLastWin32Error());
String^ errorMessage = winex->Message;
String^ myTitle = gcnew String(title);
MessageBox::Show(errorMessage,myTitle,MessageBoxButtons::OK,MessageBoxIcon::Asterisk);
delete myTitle;
delete winex;
}