Try catch blocks in C++ dll's in MVS 2010
I have a code which imports a dll and calls its functions several times.
For certain inputs the dll function is throwing an exception, but for
others it works fine. After studying a bit about exceptions in dll here it
seems that the runtime exceptions are not handled in case of dll's in a
straightforward approach.
Here is my code
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;
}
I have used try catch blocks in the dll as well. the error is coming from
the second function which is called multiple times.
I have changed the project properties as mentioned here and here. But I am
still getting this error. (I have changed the properties of the project
that creates the dll and also the one in which I call the dll)
Assuming I have no access to the dll , how can I fix this code? If
impossible, is it possible if I can access the dll?
Any help will be greatly appreciated
No comments:
Post a Comment