Solved

C++ Dll

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

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 104
Downloading email attachments 2 83
Reconfigure Delphi Install? 2 64
Delphi Firemonkey : user drawing in window 3 17
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 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