现在我要在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;
请指点。。
;
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;
请指点。。
;
??pfunc := GetProcAddress(hdl,'CloseOppApi');
??
pfunc := GetProcAddress(hdl,'CloseOppApi(^objstr)');
??
pfunc := GetProcAddress(hdl,'CloseOppApi');
??——————————————试过这种写法,会报错,原函数参数不知道怎么申明
使用DLL资源
释放DLL文件
var
pfunc: TCloseApi;
另外,tdump一下dll的内容看看
执行这一句
pfunc := GetProcAddress(hdl,'CloseOppApi');
pfunc 是有值,但是在TCloseApi(pfunc);是报错误‘Access violation at .... in 'OppApi.dll' ’
直接 pfunc(mypointer);不行?
直接 pfunc(mypointer); //myPointer是指向函数创建的实例的指针
----------------------------------------------------
已经找到办法,
C++中函数声明如下:
void * __stdcall OpenOppApi(); //原来此函数返回的是一个指针类型的变量,这个变量就是创建的实例。