Discussion Locked

How to Declare DLL in VB6?

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

my ActiveX DLL is called "TestDLL.dll"
inside the DLL, there is one class called "clsTestDLL". in this class there is a sub called "PopMessageBox", something like this:

Public Sub PopMessageBox()
Call MsgBox("Hello World")
End Sub

How do iwrite my Declare statement in order to call this DLL? i've tried the following, it didn't work.

'==========================================
Declare Sub PopMessageBox Lib "C:\PRG\Test DLL\TestDLL.dll" ()

Sub main()
PopMessageBox
End Sub
'===========================================

The error message said something abt couldn't find the DLL entry point.

10 replies

by rock tremblay

1- Compile your ActivX DLL Project.

2- Start a new EXE project and add a reference to TestDLL (if your project name was TestDll. If not then probably your project name was Project1)

3- Declare a variable like this MyTest as TestDLL.clsTestdLL
4- Anjoy! ;) MyTest.PopMessageBox()

Rock.

by rock tremblay

oupss ! Dont forget the "New" keyword
ex:
Public MyTest as new TestDLL.clsTestDLL
or
Public MyTest as TestDLL.clsTestDLL
... Set MyTest = New TestDLL.clsTestDLL

by ohjani

Due to some reason, i can't add the DLL the from the Reference or Dim it thru the way u told me. i have to use a different way, which is from the Declare statement, ie:
Declare Sub TestDLL Lib "\\SERVER\DLL\TestDLL.dll"

by remus.borca

Because you are using a DLL created from VB - which is an ActiveX DLL and not a true DLL - you CANNOT use it in a declarative instruction.

Alt. solution: register your DLL with regsrv32.exe and use CreateObject([prog_id]) function in VB to create an instance of your class and call after that your function PopMessageBox()

by ohjani

For some reason, the DLL is not placed in the local pc. it is placed at the server and connected to the pc thru LAN. how can i use regsrv32 to register those DLLs? and furthermore, those DLLs will be modified frequently, therefore this regsrv32 will have to be executed every time my application starts.

by madestroitsolutions

Since you are working from a computer attached to the network, It really depends on how you connect to this resource. In any event, what you need to do is the following (I tried it myself, and I can assure you it works):

- On the project in whichyou are trying to instantiate the component, goto Menu Project > References...

- Click the browse button, and manually browse to the place where the actual DLL is located on the server drive.

- Select the component and click [ open ]

- You will now see an extra checkbox checked with your components name. Note that this name is not necesarily what you named your dll. It might be project1 or something. REMEMBER THIS NAME. For purpose of explanation, I will call it RefComp

- Click [ ok]

- Now this is how you instantiate it:

Dim MYDLL As New RefComp.clsTestDLL

MYDLL.PopMessageBox

And that will display the box. It is very important that you understand that the name of your component is not necesarily the name of your project, so when you try to reference it manually using the menu, you might be doing so, but dont realize it, because it appears as a check with a different name.

Hope that helps, feel free to drop a line if you need extra help. bye!

by ohjani

This solution only works during development stage, it didn't work after the project is deployed to user pc. the EXE doesn't carry the DLL reference path with it, therefore when the user run the EXE, error says, "ActiveX component not found.", i think the pc is trying to look for the DLL locally since the EXE doesn't store the physical DLL location.

by madestroitsolutions

If you use the EXE that I told you, from the "support" folder that is created with the setup package, it will work, because that particular EXE does not need to look for the file. The reference to the DLL is included upon compilation, but it points to the same folder as the EXE is. Besides, you must understand how DLLs work. A DLL is 1 or more classes that provide methods. When you install an application in your computer for example, it will register its DLLs, and depending on how you compile it, it might even be used by anyone, just by instantiating its classes. Once a DLL is registered, you dont need to know its physical location. On the other hand, the packager always creates the "support" folder, because this folder contains an application capable of running on its own, without any installation needed, just in case you experience problems installing it. So thats why it will work. Regarding what you mentioned about this only working during developement, the whole project itself is a "forever developement", you said you will be updating it on a weekly basis, which is why you need to put it in the server, and have everyone run it from there. I have done it myself several times at my company. By the way, the machine in which you develop the DLL is capable of running it because VB registers the DLL for you when you make it, in order to be able to "RUN" and "STOP" the DLL during developement. Good luck.

by shanghai sam

ur suggestion seems to work for some DLLs. i've installed a few 3rd party components for the project (of course installed in my developement pc), and i've tried it in a fresh new pc. some of the components didn't work eventhough i ran the EXE directly from the remote Support folder

This discussion is closed to new replies.