Delphi DLL for C++ program

Hi,
I'm new at writing a DLL in Delphi. I have no experience with C++. I want to write one for a program in C++. This program requires me to implement some functions in the DLL to return info to the program.

The author of the program has given an example to do this in C++, it looks like

const char* doYourThing() {
     return "1.00";
}

But what must I write in my Delphi DLL to return "1.00" to the C++ program???

I've tried

library checkmail;

uses
  ShareMem,SysUtils,Classes;

{$R *.res}

function doYourThing(): string; cdecl;
begin
  Result := PChar('1.00');
end;

exports
  doYourThing;

begin
end.

but then i get a memory error.

Hope someone can help....

Greetinx,

Joost






JoostWJAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jbshumateConnect With a Mentor Commented:
Your code is returning a string rather than a pchar.  The C++ code is expecting a pChar.  Change your function to doYourThing():pChar; cdecl;.  Also the const string in your function is probably going to be freed as the function exits.  You will need to allocate some memory or use a global string var so that the string stays valid as long as the calling code is using it.
0
 
CleanupPingCommented:
JoostWJ:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
All Courses

From novice to tech pro — start learning today.