现在我要在delphi中调用C++开发的一个DLL ,DLL中有两个函数,OpenOppApi()创建一个Opp实例,CloseOppApi销毁这个实例,但是在CloseOppApi(void * objptr) 中的*objptr我不知道怎么表示出来C++中函数声明如下:
void * __stdcall OpenOppApi();// @func Closes the current instance of the OPPAPI.
void __stdcall CloseOppApi(void * objptr)   // @parm Pointer to the OPPAPI.我的delphi翻译如下:
 TCloseApi = procedure; stdcall;procedure TForm1.CloseOppApiClick(Sender: TObject);
var
  pfunc: TFarProc;
  hdl: THandle;
begin
  hdl := LoadLibrary('OppApi.dll');
  if hdl > 32 then
    begin
      pfunc := GetProcAddress(hdl,'CloseOppApi(^objstr)');
      TCloseApi(pfunc);                                  //执行到这一句时会报内存读写错误
    end;
  freeLibrary(hdl);
end;
请指点。。
   ; 

解决方案 »

  1.   

    pfunc := GetProcAddress(hdl,'CloseOppApi(^objstr)');
    ??pfunc := GetProcAddress(hdl,'CloseOppApi');
    ??
      

  2.   

    另外似乎要判断一下pfunc<>nil, =nil表示没找到这个函数
      

  3.   

    [Quote=引用 1 楼 sonicer 的回复:]
    pfunc := GetProcAddress(hdl,'CloseOppApi(^objstr)');
    ?? 
    pfunc := GetProcAddress(hdl,'CloseOppApi');
    ??——————————————试过这种写法,会报错,原函数参数不知道怎么申明
      

  4.   

    加载DLL文件
    使用DLL资源
    释放DLL文件
      

  5.   

    TCloseApi = procedure(objptr:Pointer); stdcall;
    var
      pfunc: TCloseApi;
    另外,tdump一下dll的内容看看
      

  6.   

      
    执行这一句
    pfunc := GetProcAddress(hdl,'CloseOppApi'); 
    pfunc 是有值,但是在TCloseApi(pfunc);是报错误‘Access violation at .... in 'OppApi.dll' ’
      

  7.   

    为啥还要加tcloseapi(..)呢?
    直接 pfunc(mypointer);不行?
      

  8.   

    为啥还要加tcloseapi(..)呢?// 强制转换我想用到的函数类型
    直接 pfunc(mypointer);  //myPointer是指向函数创建的实例的指针
    ----------------------------------------------------
    已经找到办法,
    C++中函数声明如下:
    void * __stdcall OpenOppApi();     //原来此函数返回的是一个指针类型的变量,这个变量就是创建的实例。