Solved

C++ Dll

Posted on 1997-05-20
3
181 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

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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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