Results 1 to 4 of 4

Thread: Call a dll from inside another dll

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    26

    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!!

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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:
    1. Option Explicit
    2.  
    3. Public Sub Test()
    4.     MsgBox "Hello, world!", vbInformation
    5. End Sub

    Then, compile and close.

    Then, start a new VB project (standard EXE), and put this code in it:

    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.    
    5.     Dim objMyDLL As Object
    6.    
    7.     Set objMyDLL = CreateObject("TestDLL.VBDLL")
    8.    
    9.     objMyDLL.test
    10.    
    11.     Set objMyDLL = Nothing
    12.    
    13. End Sub

    It should show the message box.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Call a dll from inside another dll

    Quote Originally Posted by m3fs View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2008
    Posts
    26

    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
  •  



Click Here to Expand Forum to Full Width