Solved

C++ Dll

Posted on 1997-05-20
3
182 Views
Last Modified: 2010-04-04
I have some classes written in C++ in a DLL.
How can I use this classes in Delphi?
0
Comment
Question by:facr
[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
3 Comments
 
LVL 2

Expert Comment

by:gysbert1
ID: 1336500
Create a similar pascal function prototype and follow it by external 'MyDllName.dll';

EG:

C++:
int
MyDllFunction(int FirstParam, word SecondParam) {
  // Blaah Blaah Blaah
}

Delphi:
function MyDllFunction(FirstParam :integer; SecondParam :word) :integer; external 'MyDllName.dll';

Then just go ahead and call it in your code ...
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1336501
Ok, that was calling functions of course.

Structures have to be duplicated in much the same way, only the functions can be called directly from the .dll.

You can thus not create an instance of a class that you only declared in the .dll.

The same limitations apply in Delphi as in C++ with respect to accessing stuff in dll's
0
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336502
Create a virtual, abstract class in Delphi, where all methods map exactly (and in the same order) as those of the C++ class.

Next, export a function from the C++ DLL which creates an instance of the class, and returns it as a pointer. In delphi, cast this pointer to the abstract class you've defined, and use.


E.g.

C class:

class SomeClass ....
{
  void SomeMethod (byte * Data);
}

Delphi class

TSomeClass = class
protected
  procedure SomeMethod (Data : PBYTE); virtual; abstract;
end;

funtion DLLCreateSomeClass : POINTER; external 'DLLNAME.DLL';

procedure SomeProcedure;
var
  SomeObject : TSomeClass;
begin
  SomeObject := TSomeObject(DLLCreateSomeClass);
end;


I'm not certain of the C++ syntax, but this'll hopefully give you an idea of how to do. You'll ofcourse have to ensure that calling conventions are correct.

Regards,

Erik.

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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