Results 1 to 4 of 4

Thread: VB - Differentiate between ActiveX and standard DLLs...

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    VB - Differentiate between ActiveX and standard DLLs...

    I've never found a need, but some of you may want to know whether or not a DLL is an ActiveX type DLL, or a standard API driven one. Possibly useful if you are writing your own setup/installation apps...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    4. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, _
    5.                                                         ByVal lpProcName As String) _
    6.                                                         As Long
    7. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    8.  
    9. Private Sub Command1_Click()
    10.  
    11.     MsgBox IsAXDLL("C:\Users\Project1.dll") 'A DLL written in VB (Active X), returns True
    12.     MsgBox IsAXDLL("C:\WINNT\SYSTEM32\testdll.dll") 'A DLL written in C (standard), returns False
    13.  
    14. End Sub
    15.  
    16. Private Function IsAXDLL(ByVal sFileName As String) As Boolean
    17. Dim hModule As Long
    18.  
    19.     If Not FileExists(sFileName) Then Exit Function
    20.  
    21.     hModule = LoadLibrary(sFileName)
    22.    
    23.     If hModule Then
    24.         IsAXDLL = (GetProcAddress(hModule, "DllRegisterServer") <> 0&)
    25.         Call FreeLibrary(hModule)
    26.     End If
    27.  
    28. End Function
    29.  
    30. Private Function FileExists(ByVal s As String) As Boolean
    31.     FileExists = ((Len(s) > 0) And (Len(Dir$(s)) > 0))
    32. End Function


    The code could still use some work. As you can see, it will return False if something goes wrong while calling LoadLibrary. But that doesn't always mean that the DLL isn't an ActiveX one.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    There is an addition I'd like to make. Although a really complete AX DLL must export DllRegisterServer and any known to me does it, a better function to check for would be DllGetClassObject as without this the DLL is truly useless (lacking DllRegisterServer you could still register it by hand).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by CornedBee
    There is an addition I'd like to make. Although a really complete AX DLL must export DllRegisterServer and any known to me does it, a better function to check for would be DllGetClassObject as without this the DLL is truly useless (lacking DllRegisterServer you could still register it by hand).
    Ah, good to know. Thanks.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The typelib might be external.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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