Solved

Classes in Dll

Posted on 1997-05-16
3
192 Views
Last Modified: 2010-04-04
I have a class build in c++ in a Dll.
Can anyone tell me how can i use it in delphi 2.0?
Thank you.

0
Comment
Question by:Nuno Alves
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336344
Create a similar virtual and abstract class in delphi 2. Get the address of a instance of the C++ class, and cast this address to the delphi class.


e.g.

type

  TClassCorrespondingToDllClass = class
    function FirstMethodInCPPClass : INTEGER; stdcall; virtual; abstract;
    procedure SecondMethodInCPPClass; stdcall; virtual; abstract;
  end;


Then

var
  TheObject : TClassCorrespondingToDllClass;

begin
  TheObject := TClassCorrespondingToDllClass ( DLLFunctionCreatingTheClassAndReturningPointer)

  TheObject.SecondMethod;
end;

If your delphi class maps *exactly* to the c++ class (calling convention and parameters), this should work. You need to have the DLL create an instance of the class though.

Regards,

Erik.
0
 
LVL 1

Author Comment

by:Nuno Alves
ID: 1336345
How can I load the dll in delphi?
I now that with the dll in C I just have to put before
the declaration of the function external 'Dll name' but
with the class i couldn't do the same.
0
 
LVL 3

Expert Comment

by:sperling
ID: 1336346
You have to declare an exported function in the C DLL. This function should create an instance of the class and return it as a pointer. I can't be of much help when it comes to C syntax...

Import it into delphi like this:

function CreateAnObject : POINTER; stdcall; external 'DLLNAME.DLL' name 'ExportedNameOfCreateAnObject';


Regards,

Erik.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…

830 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