【发布时间】:2013-09-23 07:29:14
【问题描述】:
我有一个代码可以导入一个 dll 并多次调用它的函数。对于某些输入,dll 函数会引发异常,但对于其他输入,它可以正常工作。在对 dll here 中的异常进行了一些研究之后,似乎在 dll 的情况下运行时异常没有以一种简单的方法处理。
这是我的代码
int main( void )
{
WORD_DATABASE wd=parse_data();
const char* WorkingDirPath="C:\\Users\\Koustav\\Dropbox\\Project\\July07_PT
int UserID=1;
DEVICE_INFO_T test= TOP_LEFT;
HINSTANCE hinstLib;
// MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module.
hinstLib = LoadLibrary(TEXT("Recog_Malayalam.dll"));
// If the handle is valid, try to get the function address.pppppp
if (hinstLib != NULL)
{
f_funci init = (f_funci)GetProcAddress(hinstLib,"abc");
f_funci1 reco = (f_funci1)GetProcAddress(hinstLib,"xyz");
// If the function address is valid, call the function.
int a = init(WorkingDirPath,1,(DEVICE_INFO_T)1);
for (int c3=0;c3<120;c3++)
{
try{
"<<wd.annotation_detail[c3].uni_val<<endl;
for (int c4=0;c4<wd.annotation_detail[c3].stroke_count;c4++)
{
log_cl<<wd.annotation_detail[c3].stroke_labels[c4]-1<<" ";
}
log_cl<<"Actual Values"<<endl;
cout<<endl;
//cout<<"Supplied stroke label"<<wd.annotation_detail[c3].stroke_labels[0]<<endl;
int b=0;
try{
b = reco(wd.word_db[c3],wd.annotation_detail[c3].stroke_count,PLAIN,0,'\0',1);
}
catch(exception e){
b=0;
cout<<"try_catch_success"<<endl;
}
//cout<<"Supplied stroke label"<<wd.annotation_detail[c3].stroke_labels[0]<<endl;
cout<<endl;
}
catch(exception e){
cout<<"There is an exception"<<endl;
}
}
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
getch();
return 0;
}
我也在 dll 中使用了 try catch 块。错误来自多次调用的第二个函数。
我已经更改了here 和here 中提到的项目属性。但我仍然收到此错误。 (我已经更改了创建 dll 的项目的属性以及我调用 dll 的项目的属性)
假设我无法访问 dll ,我该如何修复此代码?如果不可能,如果我可以访问dll,是否有可能?
任何帮助将不胜感激
【问题讨论】:
-
您确定问题不在您的代码中吗?我的意思是 wd.word_db, annotation_detail ... 向量?您是否会超出其中之一的范围?
-
我已经检查了很多次。看起来不错。说我的断言失败是因为你提到的。有什么方法可以跟踪错误吗?
-
如果您在点击此对话框时按重试,调试器会将您带到导致问题的行。如果您然后退回调用堆栈,应该很容易确定问题是在您的代码中还是在 dll 中。
标签: c++ visual-studio-2010 exception dll