Article View: comp.lang.pascal.delphi.misc
Article #598Re: Passing a string to a DLL procedure with PChar
From: Le Doute
Date: Thu, 04 Mar 1999 00:00
Date: Thu, 04 Mar 1999 00:00
67 lines
3015 bytes
3015 bytes
Emmanuel Derriey a �crit dans le message <7blh68$646$1@ai.alienor.fr>... >Hi ! >I think that your procedure is : >procedure ProcedureInsideTheDLL (Input:String; var Output:String); >and not >procedure ProcedureInsideTheDLL (Input:String; Output:String); In fact... d'oh! >Nevertheless, you should use PChar arguments ; you must consider that the >PChar are allocated by the caller. >Example : >procedure ProcedureInsideTheDLL (PcharInput:PChar; PCharOutput:PChar); // >Don't need the 'var' keyword because it's a allocated pointer >var > Input : string; > Output : string >begin > Input := string(PCharInput); // string and PChar are compatible >// Do something > PCharOutput := PChar(Output); >end; >It should work if enought char are allocated in PCharOutput !!! Else : BOOM >! >Hope it will help you... It does! But one more question: When I'm calling this procedure, what will I use? Something like: ProcedureInsideTheDLL (PChar(Input); PChar(Output)); where Input, Output: String; But it is possible that I will pass very long strings that way (like more than 1MB)... so I'm concern about memory here: PChar is a pointer? Right? So the DLL procedure will manipulate a shared copy from the calling app. But when using PChar(MyString), am I making actually a copy of my string? And of course, inside the DLL, when using: > Input := string(PCharInput); ...I'm making yet another copy... If my original string is 10MB long, I don't want, if possible, to use 20 or 30MB of RAM... The main question here is: does PChar(String) gives a pointer to String, or does it makes a C string copy of the original Pascal string (long string). >-- >Emmanuel Derriey. >Windows Software Developer. > >e-mail : ederriey@at-iris.com Thanks again, Louis Pelletier, Qu�bec.
Technical Details
Message-ID:
<x_AD2.1299$_n2.28222@carnaval.risq.qc.ca>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<2niD2.930$_n2.20928@carnaval.risq.qc.ca> <7blh68$646$1@ai.alienor.fr>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10baee,37896915cd1a101c X-Google-Attributes: gid10baee,public X-Google-Thread: fd817,37896915cd1a101c X-Google-Attributes: gidfd817,public X-Google-Thread: 108b0b,37896915cd1a101c X-Google-Attributes: gid108b0b,public X-Google-Thread: 105ac8,37896915cd1a101c X-Google-Attributes: gid105ac8,public X-Google-Thread: f973d,37896915cd1a101c X-Google-Attributes: gidf973d,public X-Google-Thread: 1043cf,37896915cd1a101c X-Google-Attributes: gid1043cf,public From: "Le Doute" <ledoute@sceptiques.qc.ca> Subject: Re: Passing a string to a DLL procedure with PChar Date: 1999/03/04 Message-ID: <x_AD2.1299$_n2.28222@carnaval.risq.qc.ca> X-Deja-AN: 451257830 References: <2niD2.930$_n2.20928@carnaval.risq.qc.ca> <7blh68$646$1@ai.alienor.fr> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3155.0 X-Trace: carnaval.risq.qc.ca 920575005 132.203.194.30 (Thu, 04 Mar 1999 14:16:45 EDT) NNTP-Posting-Date: Thu, 04 Mar 1999 14:16:45 EDT Newsgroups: comp.lang.pascal.delphi.misc,alt.comp.borland-delphi,alt.comp.lang.borland-delphi,alt.lang.delphi,borland.public.delphi.objectpascal,cern.delphi.general