[英]0xC0000005: Access violation executing location 0x00000000
I'm writing an MFC project that try to call a function in the DLL which will return some information in a string. 我正在编写一个MFC项目,尝试在DLL中调用一个函数,该函数将以字符串形式返回一些信息。 The function in the DLL is as follows:
DLL中的功能如下:
int GetInfo(char* Info)
The function will return 0 if success. 如果成功,该函数将返回0。 Information will be returned in the string parameter.
信息将在string参数中返回。 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.
执行时,将在上述位置返回“访问冲突执行位置0x00000000”错误。 Can anyone advice?
有人可以建议吗?
You tried to write to (or dereference) a NULL pointer. 您试图写入(或取消引用)NULL指针。 As you checked all possible NULLs in your calling code, the error most likely is in your called code.
当您检查调用代码中所有可能的NULL时,错误很可能是在您的调用代码中。
If you checked your called code and cannot find a reason for a null reference exception there either, consider that you may have missed to match the calling conventions correctly. 如果您检查了您的被调用代码,但在那也找不到空引用异常的原因,请考虑您可能错过了正确匹配调用约定的地方。 The type of your function pointer should be EXACTLY the same as in your library:
函数指针的类型应该与库中的类型完全相同:
For int GetInfo(char* Info)
the typedef should be typedef int (*FUNC1)(char* szInfo);
对于
int GetInfo(char* Info)
,typedef应该为typedef int (*FUNC1)(char* szInfo);
It is also possible that more than 50 characters are being written to the buffer (szInfo): 还可能有超过50个字符被写入缓冲区(szInfo):
char szInfo[50]; char szInfo [50];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.