Link to home
Start Free TrialLog in
Avatar of olagutt
olagutt

asked on

PChar or String in DLL

I want to make a library with a couple of functions and I know that I will have to convert my delphi strings to pchars, when passing information.

But what about string-handling _inside_ my DLL-functions?

It's just the interface between the EXE and the DLL that needs Pchars, right?

Regards,
Ola
ASKER CERTIFIED SOLUTION
Avatar of DaFox
DaFox

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Martyn Spencer
You could use PChars, or you could import the sharemem module as the first in your project and use Delphi strings. Note that if you are passing objects between the main app and the dll, and the classes contain strings, you should also have the sharemem unit included (see the Delphi help on dlls).
Avatar of ILE
ILE

Just the interface must be a PCHAR !
Absolytly RIGHT

All internal calculation mey be with delphi strings or what ever u wont.
Personaly i use the delphi strings for everything (bercouse i think it is a much mor "menagabile") except i must pass samo paramaetars to API or call some dll-s
   
If you are writing a delphi app, and a delphi DLL, then a Delphi string is an option. If you are looking to produce a DLL that is shareable by a different tool, then PChars are required. Certainly this is my experience, anyway.
Avatar of olagutt

ASKER

Thanks for your very fast reply!
use WideString instead of PChar, WideString is NTS (Null Terminated String) and You can use it just like string :-)
ziolko.
Ziolko, possible! But PChars are used by API functions and so it's the "broadest common denominator" (they are more universal). Furthermore widestrings are managed by the Delphi memory management (-> sharemem).

Markus
DaFox > I know PChar is used in most of Windows API, about sharemem .. I'm useing WideString with DLLs without sharemem.
ziolko.
Do you also use WideStrings in DLLs without adding sharemem?
Hm, maybe. I must confess that I did not really often do this.

Markus
DaFox > yep I use WideString In DLLs without sharemem
ziolko.
However, Widestrings are passed as their values. PChars are references and that's the way windows handles it, too. :o)

That's the last comment I'll add to this thread! ;) Both ways are possible and we seem to have different experiences. No problem!

Markus
DaFox > I'm not saying that WideStrings are better than PChars its just different way :-) I think Delphi's string type made us (at least me) a little bit lazy 'cause its so easy to use. over and out :-)
ziolko.