简体   繁体   English

0xC0000005:访问冲突执行位置0x00000000

[英]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.

相关问题 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 0xC0000005:访问冲突读取位置0x00000000 - 0xC0000005: Access violation reading location 0x00000000 在 Project0_opengl.exe 中的 0x00000000 处抛出异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in Project0_opengl.exe: 0xC0000005: Access violation executing location 0x00000000 在 CobwebDiagram.exe 中的 0x00000000 处引发异常:0xC0000005:访问冲突执行位置 0x00000000 - Exception thrown at 0x00000000 in CobwebDiagram.exe: 0xC0000005: Access violation executing location 0x00000000 为什么我在 ConsoleApplication1.exe 中的 0x00000000 处出现异常异常:0xC0000005:访问冲突执行位置 0x00000000 - Why do I get an Exception Exception thrown at 0x00000000 in ConsoleApplication1.exe: 0xC0000005: Access violation executing location 0x00000000 在0xC0000005中的0x6ececafa出现未处理的异常:访问冲突写入位置0x00000000 - Unhandled Exception as at 0x6ececafa in 0xC0000005 : Access violation writing location 0x00000000 IXAudio2-0xC0000005:访问冲突写入位置0x00000000 - IXAudio2 - 0xC0000005: Access violation writing location 0x00000000 C ++:0xC0000005:访问冲突写入位置0x00000000 - C++: 0xC0000005: Access violation writing location 0x00000000 : 0xC0000005: 访问冲突写入位置 0x00000000 C++ 与内联汇编 - : 0xC0000005: Access violation writing location 0x00000000 C++ with inline assembly Project4.exe中0x00998876处的首次机会异常:0xC0000005:访问冲突写入位置0x00000000 - First-chance exception at 0x00998876 in Project4.exe: 0xC0000005: Access violation writing location 0x00000000
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM