Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PChar or String in DLL

Posted on 2003-03-10
12
Medium Priority
?
2,250 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:olagutt
  • 4
  • 4
  • 2
  • +2
12 Comments
 
LVL 6

Accepted Solution

by:
DaFox earned 315 total points
ID: 8106702
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
 
LVL 2

Expert Comment

by:Martyn Spencer
ID: 8106718
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
 
LVL 3

Expert Comment

by:ILE
ID: 8106925
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Martyn Spencer
ID: 8107505
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
 

Author Comment

by:olagutt
ID: 8108319
Thanks for your very fast reply!
0
 
LVL 21

Expert Comment

by:ziolko
ID: 8111623
use WideString instead of PChar, WideString is NTS (Null Terminated String) and You can use it just like string :-)
ziolko.
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8111809
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
 
LVL 21

Expert Comment

by:ziolko
ID: 8112836
DaFox > I know PChar is used in most of Windows API, about sharemem .. I'm useing WideString with DLLs without sharemem.
ziolko.
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8114835
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
 
LVL 21

Expert Comment

by:ziolko
ID: 8115219
DaFox > yep I use WideString In DLLs without sharemem
ziolko.
0
 
LVL 6

Expert Comment

by:DaFox
ID: 8115300
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
 
LVL 21

Expert Comment

by:ziolko
ID: 8115372
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question