小编use*_*698的帖子

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

我正在编写一个 MFC 项目,该项目尝试调用 DLL 中的函数,该函数将以字符串形式返回一些信息。DLL中的函数如下:

int GetInfo(char* Info)
Run Code Online (Sandbox Code Playgroud)

如果成功,该函数将返回 0。信息将在字符串参数中返回。调用例程如下:

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);
} 
Run Code Online (Sandbox Code Playgroud)

此代码在编译和链接时没有错误。执行时,会在上述位置返回“访问冲突执行位置0x00000000”的错误。任何人都可以建议吗?

c++ mfc loadlibrary getprocaddress access-violation

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

access-violation ×1

c++ ×1

getprocaddress ×1

loadlibrary ×1

mfc ×1