Solved

C++ Dll

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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