This question already has an answer here:
I am trying to call the LoadLibrary for a dll which is placed in the exe path. it is giving error as ERROR_FUNCTION_FAILED. Below is the code, Please let me know the cause for 1627
typedef int (__stdcall *func)();
int DynamicLoad_Lib()
{
func call;
int iReturn;
cout<<"\n\n DynamicLoad_Lib \n\n";
HINSTANCE hinstLib = LoadLibrary(L"MYLib.dll");
cout<<"\n\nGetLastError() "<<GetLastError()<<"\n";
if(hinstLib == NULL)
return 0;
call = (func_another)GetProcAddress(hinstLib, "Initialize");
if(call == NULL)
{
FreeLibrary(hinstLib);
return 0;
}
iReturn = (*call)();
call = (func)GetProcAddress(hinstLib, "Terminate");
if(call == NULL)
{
FreeLibrary(hinstLib);
return 0;
}
FreeLibrary(hinstLib);
return 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
DynamicLoad_Lib();
return 0;
}
This prints the last error that happened in any Windows API function:
It should be, print any error that happened in the LoadLibrary function:
LoadLibrary RTFM: