Solved

Classes in Dll

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

Technology Partners: 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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