Trying to call an ActiveX DLL from Delphi...

Hi, I have an ActiveX DLL from a software security package I purchased about 9 years ago (company now defunct), which I'd like to call from a Delphi program. The DLL is written in C or VB I think. The docs that came with it show how to call it from a VB project, but that doesn't help me much for Delphi. Here's what the docs say:


(1) From the Project menu, choose References as shown in Figure 1.1.
(2) The References dialog box is displayed, as shown in Figure 1.2. Look for CodeLockKeyGen. If you can't find it, click on the "Browse..." button and look for the Code-Lock Keygen.DLL in the directory where you installed Code-Lock. Select the check box to the left of the CodeLockKeyGen.
(3) Choose OK to close the References dialog box. After adding the reference, you can make use of the ActiveX DLL as below.

First, you will need to declare it like below:

Private KG As New CodeLockKeyGen.KeyGen

The only function in the ActiveX DLL is .Get_RegistrationCode. To make use of it, you need to supply it with the necessary variables.

The format for the function is as below:

.Get_RegistrationCode("Program Code", "User Data", "Name of User", "Filename", ProtFlag)


1) The variables must be in the specified sequence.
2) If you do not supply the Filename variable, the Registration Code will be returned from the function. If you supply a filename for the variable, a text file containing the Registration Code will be produced in the directory of the ActiveX DLL.
3) If you supply the Filename variable, the return value will always be "True". However, if there is any error during the generation of the Registration Code, the text file as specified will not be produced. An error log file named "Error.log" will be produced instead.
4) If you do not specify the Filename variable, the return value will be the Registration Code unless there is any error during the generation of the Registration Code, in which case, the return value will be "Error". An error log file named "Error.log" will also be produced.


Dim strResult As String
strResult = KG.Get_RegistrationCode("12345678", "ED3E78BDB99C15A36DB6746B9966B6ECCFF62E8202EEB9956DC83B7F15C4AF00", "ChosenBytes", "RegFile - ChosenBytes.txt", True)
While Len(strResult) = 0 ' to wait for the Registration Code generation
MsgBox strResult   ' strResult will contain the Registration Code

The above example will input the following values:

Program Code: "12345678"
User Data: "ED3E78BDB99C15A36DB6746B9966B6ECCFF62E8202EEB9956DC83B7F15C4AF00"
Name of User: "ChosenBytes"
Filename: "RegFile - ChosenBytes.txt"
ProtFlag: True

This will produce a text file with the name of "RegFile - ChosenBytes.txt" containing the Registration Code.


I tried making a barebones Delphi project to attempt to call this using what little experience I have in calling DLL's, but kept getting :

TestDLL.exe - Entry Point Not Found
The procedure entry point Get_RegistrationCode could not be located in the dynamic link library Code-Lock Keygen.DLL.

Would anyone be able to shed any light on this please? I can send you the DLL to your private mailbox if you wish - I don't want to attach it here and make it publicly available.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Did you import it as ActiveX Control?

Please send it over.
"My profile name"
shawn857Author Commented:
Hi Jimy... okay, coming your way. No I didn't import it in... wasn't really sure what to do there. It's not an ActiveX "package", it's just a dll file.

That DLL has four functions, non of them is "Get_RegistrationCode":

Either that was the wrong DLL or there are extra missing steps.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

shawn857Author Commented:
That's strange Jimy, I had ran a utility called "ActiveXplorer" on it a while back (and just did so again), and it does show that function in there. See attached screenshot please.

OK, I figured it out.

Which Delphi version you are using?
shawn857Author Commented:
Delphi 7
You need to Import a Type Library.
In Delphi XE:
From the menu -> Components -> Import Component... -> Import a Type Library and then locate that DLL, Add it if not listed, Next, select Palette Page, Next, Install to a new package, add a name and Finish.

Now start a new project, go to the Palette page where that Type Library were installed in, and drop KeyGen component and the rest, is similar to the documentation, is calling "KeyGen1.Get_RegistrationCode(...)".
Wrong assumption, sorry :)

In Delphi 7 (make sure to Run As Admin.):
From Delphi menu -> Component -> Import ActiveX Control... -> Locate the DLL or Add if not listed, Select Palette Page and Install.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shawn857Author Commented:
OK, I put the DLL in one of my Search Paths, but when I go into Import ActiveX Control, it's still not listed in the window of all the ActiveX controls and DLL's. So I clicked ADD and tried to add it in. It was looking for only .ocx files, but I changed it to "All Files", found the DLL file and added it. The window showing the list of controls and DLLs "flashed" so I thought it may have worked, but it did not add it to the list  :-(

I though when you imported an ActiveX, it was supposed to be an ocx? This is only a DLL file. I know so little about this stuff.....

shawn857Author Commented:
Is this going to be a component that can be "dropped" on a form? I assumed it was just a DLL that got called straight from my app?

> Is this going to be a component that can be "dropped" on a form?

I assumed it was just a DLL that got called straight from my app?
The DLL can be anything.

Do you have a team viewer?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.