Delphi .NET (2) Database (71) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
Using a C++ DLL in Delphi (ActiveX control)
7 comments. Current rating: (4 votes). Leave comments and/ or rate it.
Question:
I have this DLL TblAnalysis.DLL that is written in C++, how can I use it in Delphi? I have a list of exported functions as a .h header file, but when I try to define them in Delphi as 'external', I get runtime errors. The documentation speaks about an object that publishes those functions as methods.
Answer:
Very likely this TblAnalysis.DLL could be an Active-X control - which technically is a DLL with a well-defined interface. To verify this, you can either
- Try to register it from the commandline with
regsvr32 TblAnalysis.DLL
If this works, then you are looking at an ActiveX control.
or - better:
- Get a list of all functions with ordinals exported from the DLL. From the commandline, use Borland's TDump tool to get such a list.
tdump -ee tblanalysis.dll
The output:
c:\temp> tdump -ee tblanalysis.dll
Turbo Dump Version 5.0.16.12 Copyright (c) 1988, 2000 Inprise Corporation
Display of File TBLANALYIS.DLL
Export ord:0001 = 'DLLConUnloadNow'
Export ord:0002 = 'DLLGetClassObject'
Export ord:0003 = 'DLLRegisterServer'
Export ord:0004 = 'DLLUnregisterServer'
Again, if the output looks like this, then the you are looking at an ActiveX control.
So now you hopefully verified that you're looking at an ActiveX control, not at a regular DLL. How do you deal with it then?
Instead of importing and calling functions, you will have to create an instance of that ActiveX control and then you can call its methods.
- Make sure to register it on your machine. This also has to be done on any computer where the application will run - so make this part of your install program:
regsvr32.exe TBLANALYSIS.DLL
A messagebox should appear saying that the registration succeeded. Unregistering an ActiveX control goes with the /U option:
regsvr32.exe /u TBLANALYSIS.DLL
- Convert the type library that should be included in the DLL to a Delphi stub. In Delphi, close your project, start a new project and select Import Type Library from the project menu. A dialog will show up containing a list of all registered ActiveX libraries on your system.
Locate the one that belongs the the DLL (the name should be in your
documents) and select it. You can then click install (make sure
generate component wrapper is checked) and a new component will be
installed on your component palette. You use this component in your application and use its methods as described in the DLL's documentation.
Comments:
|
|
|
|
This topic is very useful for someone that use C++ DLL in Delphi . More over, we can apply the same stratégie for the reverse action.
|
|
|
|
|
Finally I have succesfully installed activelock component in delphi ...
|
|
|
|
|
How would the process be different in case of a regular DLL?
S. Odgaard
|
|
|
|
|
This topic is very useful if the dll is an ActiveX, but how if the dll isn't an ActiveX ?
|
|
|
|
|
Hi, I can't call a fortran dll in delphi. How can I do?
|
|
|
|
|
hii..i want to know to use fortran sub routines like LAPACK,ARPACK on delphi.I mean how to implement fortran dll's in Delphi..
|
|
|
|
|
it was me who posted the last question
|
|