?
Solved

Classes in Dll

Posted on 1997-05-16
3
Medium Priority
?
201 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
[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 3

Accepted Solution

by:
sperling earned 100 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

718 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