I'm writing an MFC project that try to call a function in the DLL which will return some information in a string. The function in the DLL is as follows:
int GetInfo(char* Info)
The function will return 0 if success. Information will be returned in the string parameter. The calling routine is as follows:
typedef int (WINAPI *FUNC1)(char* szInfo);
HINSTANCE hinstLib;
FUNC1 GetInfo;
char szInfo[50];
hinstLib = LoadLibrary(TEXT("DevInfo.dll"));
// If the handle is valid, try to get the function address.
if (hinstLib != NULL)
{
GetInfo = (FUNC1) GetProcAddress(hinstLib, "GetInfo");
// If the function address is valid, call the function.
if (NULL != GetInfo)
{
if((GetInfo) (szInfo)) // Error here!!
{
AfxMessageBox(_T("Error Reading"));
}
}
FreeLibrary(hinstLib);
}
This code does not have error in compiling and linking. When executing, it will return the error of "Access violation executing location 0x00000000" at the location stated above. Can anyone advice?
EDIT: The OP reports (in a comment to one of the answers below) that in this case:
"The error was due to the called function in the DLL which needs other dlls to be present."
int WINAPI(char*)
andint(char*)
are not the same thing. Your function shold be at least prototyped asint WINAPI GetInfo(char*)
– MinuetGetInfo
function? – Raimes