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
olaguttAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DaFoxCommented:
Hi olagutt!

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

You're right. Windows uses null-terminated strings, therefore you have to use PChars in your prototypes. It doesn't matter what kind of type you use inside your functions.
So, your assumptions are absolutely right!

Markus
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martyn SpencerConsultantCommented:
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).
0
ILECommented:
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
   
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Martyn SpencerConsultantCommented:
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.
0
olaguttAuthor Commented:
Thanks for your very fast reply!
0
ziolkoCommented:
use WideString instead of PChar, WideString is NTS (Null Terminated String) and You can use it just like string :-)
ziolko.
0
DaFoxCommented:
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
0
ziolkoCommented:
DaFox > I know PChar is used in most of Windows API, about sharemem .. I'm useing WideString with DLLs without sharemem.
ziolko.
0
DaFoxCommented:
Do you also use WideStrings in DLLs without adding sharemem?
Hm, maybe. I must confess that I did not really often do this.

Markus
0
ziolkoCommented:
DaFox > yep I use WideString In DLLs without sharemem
ziolko.
0
DaFoxCommented:
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
0
ziolkoCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.