PDA

View Full Version : pChar passing to DLL



25-03-2002, 09:11 PM
I have a DLL called by MAIN as listed below. When I put the code in the main program it works fine. When calling the DLL it doesn't show the text 'Test 123' but 'A@A' or similar rubbish.
This must be a pointer issue I suppose. Any ideas?
TIA
John.
--------------------
MAIN PROGRAM:

procedure TForm1.Button1Click(Sender: TObject);
var
p : pChar;
begin
p := strAlloc(1000 * sizeOf(char));
strPCopy(p, 'Testing 123');
ShowStr(p, true);
strDispose(p);
end;


--------------------
IN THE DLL:

procedure ShowStr(pSQL : pChar; boAll : boolean); StdCall;
var
s : string;
begin
s := string(pSQL);
showMessage(s); // the dll shows rubbish text like 'A@A'
end;

25-03-2002, 11:50 PM
A character string of any length is compatible with the PChar type when the extended syntax is enabled {$X+}.