0

我有一个导入 dll 并多次调用其函数的代码。对于某些输入,dll 函数会引发异常,但对于其他输入,它可以正常工作。在对 dll 中的异常进行了一些研究之后 ,似乎在 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 块。错误来自多次调用的第二个函数。

我已经改变了这里这里提到的项目属性。但我仍然收到此错误。(我已经更改了创建 dll 的项目的属性以及我调用 dll 的项目的属性)

错误

假设我无法访问 dll ,我该如何修复此代码?如果不可能,是否可以访问 dll?

任何帮助将不胜感激

4

1 回答 1

2

Try-catch 用于异常。此对话框用于断言。不同的野兽,几乎没有关系。

于 2013-09-18T14:00:13.347 回答