在vc ++代码中调用vc ++ dll时出现未处理的异常 [英] Unhandled exception when call vc++ dll in vc++ code
问题描述
我想用我的vc ++代码调用我的vc ++ dll.
但是发生错误,原因是 .exe中0x00000000处未处理的异常:0xC0000005:访问冲突读取位置0x00000000.
最后一行之后.我已按序号调用vc ++ dll.
在.h文件中
I want to call my vc++ dll in my vc++ code.
but the error occur that Unhandled exception at 0x00000000 in .exe: 0xC0000005: Access violation reading location 0x00000000.
after last line.I have call vc++ dll by ordinal no.
In .h file
typedef int (*LPVAR)(char * ptr_f, char *CC);
在.cpp文件中
In .cpp file
HINSTANCE hDLL;
hDLL = NULL;
LPVAR var;
hDLL = LoadLibrary("Prod.dll");
if( hDLL == NULL )
AfxMessageBox("Could not load the DLL");
/*int ordinal = 2;
HMODULE dll = LoadLibrary("Prod.dll");
FARPROC fn = GetProcAddress(dll, MAKEINTRESOURCE(ordinal));*/ //how to proceed after this.
else
{
var = (LPVAR)GetProcAddress(hDLL, "Ver_C");
char *ch,a;
ch = (char*)malloc(100*sizeof(char));
a = 'z';
int ans = var(ch,&a); //Unhandle exception after that.
}
推荐答案
^ ]说,如果失败则返回NULL
您返回了NULL(我从异常中得出了结论),并且那里的错误处理为零
The docs for GetProcAddress[^] say it returns NULL if if fails
You''re getting a NULL back (i worked that out from the exception) and you''ve got zero error handling in there
var =(LPVAR)GetProcAddress(hDLL,"Ver_C");
var = (LPVAR)GetProcAddress(hDLL, "Ver_C");
"Ver_C"
应该与您导出函数的名称完全匹配.确保您有一个名为的函数,如果没有,那就是您的问题.如果您确实有一个名为that的函数,请确保它是C样式的导出,否则该名称可能包含名称修改".
The "Ver_C"
should match the name of your exported function exactly. Make sure you have a function named that, if you don''t, that''s your problem. If you do have a function named that, make sure it was a C-style export or else the name probably contains "name mangling".
这篇关于在vc ++代码中调用vc ++ dll时出现未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!