DelphiFAQ Home Search:

Using a C++ DLL in Delphi (ActiveX control)

 

comments9 comments. Current rating: 4 stars (5 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


  1. Try to register it from the commandline with
    regsvr32 TblAnalysis.DLL

    If this works, then you are looking at an ActiveX control.

    or - better:

  2. 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.

  1. 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

  2. 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:

2005-12-06, 09:28:37
Abdelkader YEDDES from France  
rating
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.
2006-02-03, 08:32:30
[hidden]  
rating
Finally I have succesfully installed activelock component in delphi ...
2006-04-08, 04:43:19
[hidden] from Denmark  
rating
How would the process be different in case of a regular DLL?

S. Odgaard
2006-08-09, 07:24:43
anonymous from Indonesia  
rating
This topic is very useful if the dll is an ActiveX, but how if the dll isn't an ActiveX ?
2007-12-04, 03:22:48
babaei_zahed@yahoo.com from Iran  
Hi, I can't call a fortran dll in delphi. How can I do?
2008-06-16, 08:37:40
anonymous from Italy  
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..
2008-06-16, 08:38:54
ashvinchander@gmail.com from Italy  
it was me who posted the last question
2009-04-16, 01:28:28
anonymous from Belgium  
I get a list of functions with tdump, but I can not register the dll: dllRegisterServer entry point not found, anyone know how to solve this? thx
2010-03-09, 14:56:25
anonymous from United Kingdom  
rating
If tdump -ee some.dll reports a list as explained it does not mean that some.dll is an ActiveX control.
Tdump reports the functions in 'standard' dlls which are not ActiveX dlls.

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: