GetProcAddress fails
Jun 11, 2011 at 7:04pm UTC
Hi,
I'm developing a non-mfc application that uses a dll file (which I made too).
when I try to load the dll file LoadLibrary is successful (does not return NULL), however GetProcAddress fails (returns NULL).
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
if (hook_setup_func == NULL)
{
HINSTANCE hook_instance;
if (((hook_instance = LoadLibrary(_T("hook.dll" ))) != NULL) &&
((hook_uninstall_func = (hook_uninstall_type)GetProcAddress(hook_instance,"hook_uninstall" )) != NULL) &&
((hook_install_func = (hook_install_type)GetProcAddress(hook_instance,"hook_install" )) != NULL))
{
if ((hook_setup_func = (hook_setup_type)GetProcAddress(hook_instance,"hook_setup" )) == NULL)
{
throw std::runtime_error("Couldn't install the hook, case 1" );
}
}
else
{
//this throws error
throw std::runtime_error("Couldn't install the hook, case 2" );
}
}
here's the corressponding declaration:
1 2 3 4 5 6
typedef void (*hook_setup_type)(HWND, BOOL);
typedef BOOL (*hook_install_type)();
typedef void (*hook_uninstall_type)();
hook_setup_type hook_setup_func;
hook_install_type hook_install_func;
hook_uninstall_type hook_uninstall_func;
and in the dll file:
1 2 3 4 5
__declspec(dllexport) void hook_setup(HWND hwnd, BOOL use_the_hook);
__declspec(dllexport) BOOL hook_install();
__declspec(dllexport) void hook_uninstall();
EDIT:
error code is 127
any ideas why it fails?
Best regards,
Yours3!f
Last edited on Jun 11, 2011 at 7:16pm UTC
Jun 11, 2011 at 7:55pm UTC
Have you put the DLL lines inside
Otherwise, the symbol names are "scrambled" by the compiler (they have a load of numbers and symbols stuck on depending on return type, etc). Thus they are not called what you expect without the extern "C" bit.
Jun 11, 2011 at 8:02pm UTC
thank you Xander314, extern "C" solved the problem :)
Topic archived. No new replies allowed.