在调用动态库是碰到如下问题:
   动态库:test.dll,函数:int DoCase(int i,int j);
   调用:
       HINSTASNCE hins;
       hins = LoadLibrary("test.dll");
       int (*DOCASE)(int,int);//声明一个指针函数. 不用Typedef来做
       DOCASE = GetProcAddress(hins, "DoCase");
       int k = DOCASE(1,1); //编译时,本句报错为什么呢?是调用方法的问题吗?

解决方案 »

  1.   

    DOCASE dcfn= (DOCASE)GetProcAddress(hins, "DoCase");
           int k = dcfn(1,1);
      

  2.   

    DoCase是否为空?
    如果是空的话,那就是
    int DoCase(int i,int j);
    该函数在dll里的导出名字不叫“DoCase”了。
    解决方法:
    1. 察看dll的导出函数表,看看DoCase的真实名称,比如"?DoCase@@YAXH@Z"之类
    2. 修改dll的源代码,把函数声明为extern "C"
      

  3.   

    應該是
    DOCASE = GetProcAddress(hins, "DoCase");這行出錯,GetProcAddress返回void*要用強制類型轉換
    DOCASE = (int(*)(int,int))GetProcAddress(hins, "DoCase");
      

  4.   

    非常感谢,特别感谢:an_bachelor(一個單身漢)