?
Solved

PChar or String in DLL

Posted on 2003-03-10
12
Medium Priority
?
2,244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:mdspencer
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:mdspencer
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

Independent Software Vendors: 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!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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