创建动态库test.dll
其中有函数定义如下:
function AddStr(instr:string):string;
begin
result:='接收到了'+instr;
end;在客户端调用时为何总是提示“Invalid pointer operation”
其中有函数定义如下:
function AddStr(instr:string):string;
begin
result:='接收到了'+instr;
end;在客户端调用时为何总是提示“Invalid pointer operation”
str:string;
fun:function (str: String): integer;
begin
Libs:=LoadLibrary(pchar('test.dll'));
fun:=GetProcAddress(Libs,'AddStr');
str:=fun(edit1.Text);
edit2.Text:=inttostr(str);
...
TProc = function (str: String): integer; stdcall;var Libs:THandle;
str:string;
modalPro: TProc;
FPointer: TFarProc;
begin
Libs:=LoadLibrary(pchar('test.dll'));
FPointer:=GetProcAddress(Libs,PChar('AddStr'));
modalPro := TProc(FPointer);
modalPro(str);
FreeLibrary(Libs);
...
这是解释:
Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters.
都放上以后怎么客户端提示非法操作:(