?
Solved

Delphi DLL for C++ program

Posted on 2003-03-28
2
Medium Priority
?
207 Views
Last Modified: 2010-04-04
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






0
Comment
Question by:JoostWJ
[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
2 Comments
 
LVL 1

Accepted Solution

by:
jbshumate earned 75 total points
ID: 8229509
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
 

Expert Comment

by:CleanupPing
ID: 9316556
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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