The DLL is not written by you, correct?
The DLL function will be expecting a pointer to a buffer where it can copy the string to. That is essentially what you are doing by passing a Shortstring as a var parameter, however Shortstring was not meant to be used in this way. Shortstring has some other information attached to it such as the length of the string which the DLL does not know about.
Here is a wrapper for your DLL function that will return a string type.
WD_CopyPSToString: function (Id: Hwnd; Position: Word; Buffer: PChar; L: Word): Word; stdcall;
function CopyPSToString(Id: Hwnd; Position: Word): String;
var
Buffer: array [0..1024] of Char;
begin
{ I am assuming that L is the length of the buffer, since
this is fairly common in the case of passing a buffer. }
WD_CopyPSToString(Id, Position, Buffer, SizeOf(Buffer));
Result := PChar(Buffer);
end;Sly
In my application I am using a function in an external DLL It copies data from a mainframe application screen to the string buffer
WD_CopyPSToString : function (Id : Hwnd; Position : word; var Buffer : shortstring; L: WORD):word; stdcall;
It works ok when I use shorstring as type for the buffer variable. When I use string as type for the buffer variable I get an acces violation error.
I need to copy more then 255 characters so I cannot use shortstring. pchar does not work either when I create a new type : packed array[1..5000] of char it works ok
Any other suggestions or explanations ?
Thanks Wim
This message and its attachments may contain legally privileged or confidential information. This message is intended for the use of the individual or entity to which it is addressed. If you are not the addressee indicated in this message, or the employee or agent responsible for delivering the message to the intended recipient, you may not copy or deliver this message or its attachments to anyone. Rather, you should permanently delete this message and its attachments and kindly notify the sender by reply e-mail. Any content of this message and its attachments, which does not relate to the official business of the sending company must be taken not to have been sent or endorsed by the sending company or any of its related entities. No warranty is made that the e-mail or attachment(s) are free from computer virus or other defect.
_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

