|
-
Aug 24th, 2009, 02:51 PM
#1
Thread Starter
Junior Member
Call a dll from inside another dll
Rather than consolodating our current DLL's I would like to be able to execute other dll's from a "master" dll if you will. Is this possible if so could someone post the snippet?
Thanks!!
-
Aug 24th, 2009, 03:14 PM
#2
Re: Call a dll from inside another dll
Hm...
If they'are ActiveX DLLs (created in VB) and they have been registered then you could probably use late-binding (CreateObject()) and then call a function.
Here's an example...
Create a new VB project for an ActiveX DLL. Name the project `TestDLL`, and name the class module `VBDLL`.
Put this code in there:
vb Code:
Option Explicit
Public Sub Test()
MsgBox "Hello, world!", vbInformation
End Sub
Then, compile and close.
Then, start a new VB project (standard EXE), and put this code in it:
vb Code:
Option Explicit
Private Sub Form_Load()
Dim objMyDLL As Object
Set objMyDLL = CreateObject("TestDLL.VBDLL")
objMyDLL.test
Set objMyDLL = Nothing
End Sub
It should show the message box.
-
Aug 24th, 2009, 03:56 PM
#3
Re: Call a dll from inside another dll
 Originally Posted by m3fs
Rather than consolodating our current DLL's I would like to be able to execute other dll's from a "master" dll if you will. Is this possible if so could someone post the snippet?
Thanks!!
If using late binding, I am not sure how your apps can instantiate a class belonging to the other DLLs, from your new main dll, especially if Intellisense is desired.
If however you add your other DLLs as references to your new main DLL, then you can expose those other dll's classes via a new public property in your new main dll.
Example. Let's say you had a DLL named Drawing.DLL with a class called Surface and another DLL named Subclasser.DLL with a class called Client.
Assuming your Drawing & Subclasser DLLs are referenced in the main DLL:
Code:
' main DLL, let's say the public class is called Core
Dim mySurface As Drawing.Surface
Dim myClient As Subclasser.Client
Public Property Get DrawingSurface() As Drawing.Surface
If mySurface Is Nothing Then Set mySurface = New Drawing.Surface
Set DrawingSurface = mySurface
End Property
Public Property Get SubclasserClient() As Subclasser.Client
If myClient Is Nothing Then Set myClient = New Subclasser.Client
Set SubclasserClient = myClient
End Property
' in your app, you will have the Main dll referenced and Core class is public, then...
Dim theCore As New MainDLL.Core
Call theCore.DrawingSurface.SomeSub()
Call theCore.SubclasserClient.SomeSub()
....
Just thinking off top of my head
Edited. The downside you will have trying to wrap all your other DLLs with a new DLL is that all the other DLLs will become dependencies of the new DLL. So you'd still have all your other DLLs plus the new main DLL. If you actually combined all your DLLs into a new DLL, then you'd just have one large DLL vs the many smaller ones. "Six of one, half-dozen of the other."
Last edited by LaVolpe; Aug 24th, 2009 at 04:03 PM.
-
Aug 24th, 2009, 04:05 PM
#4
Thread Starter
Junior Member
Re: Call a dll from inside another dll
It says "Active X object can't create object" - do I need to add references besides active x data objects 2.8?
*will check the way you suggest LaVolpe!
thanks guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|