通过EXE程序来调用另一个由DELPHI写的DLL程序。
DLL程序中有一个函数,如
function test(const aa:pchar):pchar;stdcall;
begin
...
end;
函数的参数是PCHAR类型,现在的问题是为什么我在EXE程序中
调用test时参数值会丢失,比如我在EXE程序中调用
test('test');
调度跟踪发现到了dll里test函数读取的aa参数为't',即总是传进来
参数的第一个字符,这是为什么?急~~
DLL程序中有一个函数,如
function test(const aa:pchar):pchar;stdcall;
begin
...
end;
函数的参数是PCHAR类型,现在的问题是为什么我在EXE程序中
调用test时参数值会丢失,比如我在EXE程序中调用
test('test');
调度跟踪发现到了dll里test函数读取的aa参数为't',即总是传进来
参数的第一个字符,这是为什么?急~~
我的意思是,DLL中参数是PChar,在调用单元中函数参数说明为string即可(不要用PChar)
test('test');
改为
test(pchar('test'))
2.不可以将字符串作为返回值,你看见那个WIN API有字符串返回值了。
3.一般都要传递给函数PCHAR的空间长度,避免字符串空间不足。常见写法fun xxx(ps: pchar; ilen: integer): integer
var
s: string;
begin
s := 'abc';
result := length(s);
if ilen = 0 then
exit;
if result > ilen then
result := ilen ;
CopyMemory(ps, PChar(s), result);
end;var
ss: string;
i: integer;
begin
i := xxx(PChar(ss), 0);
SetLength(ss, i);
i := xxx(pChar(ss), i);
end;http://blog.csdn.net/comerliang/archive/2006/03/16/626158.aspx