Solved

Classes in Dll

Posted on 1997-05-16
3
177 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now