我在C++builder中写了个dll
在C++builder中的代码:
extern "C" void  __declspec(dllexport)  __stdcall Printbmp(char bmpfile[]);void    Printbmp(char bmpfile[])

 //函数体
}下面的代码是在VC中调用该dll:
  UpdateData(TRUE);
 
   HINSTANCE handle; //DLL 模块的句柄
   FARPROC lpFarProc; //
   void(__stdcall *print)(char*);  
  handle = LoadLibrary("qaz.dll"); //
  int code =GetLastError(); //code=2
  
  
   lpFarProc = GetProcAddress(handle,"Printbmp"); 
    code =GetLastError(); //code=2  
   print = (void(__stdcall*)(char*))lpFarProc; //指针类型转换   char ch[500]="f:\\facebmp\\2100.bmp";
   
  
   print(ch);//调用函数
   code =GetLastError();     //code=0
   FreeLibrary(handle); 
   code =GetLastError();    //code=0在vc中 当 FreeLibrary(handle); 后退出时出错 报告内存不能为读程序退出。
但是在print(ch)调用函数没有报错什么原因 ??怎样解决???各位帮忙!

解决方案 »

  1.   

    extern "C" void  __declspec(dllexport) Printbmp(char bmpfile[]);去掉__stdcall
      

  2.   

    如果在调用时去掉FreeLibrary(handle); 则不报错
    to zfive5(醉马不肖) 按照你的办法做了 报同样的错
      

  3.   

    typedef void Printbmp(char bmpfile[]) Func;
    Func lpFarProc;
    lpFarProc = (Func *)GetProcAddress(handle,"Printbmp"); 
    print = (void(__stdcall*)(char*))lpFarProc; //指针类型转换_stdcall也不对
    注意:_stdcall与extern “c"的函数返回处理不同
      

  4.   

    将print(ch)改为(*print)(ch)即可,print为一函数指针。