getting component information (by name) at run time

Posted on 2004-11-15
Last Modified: 2010-05-02
I have a dll called "X".  In this library is a class, called "Y".  When I am troubleshooting, I often need to observe run time behavior and then search the registry for information such as the path of the library "X".  It would be nice if I could put the path of the library in the window bar at run time.  Something like the following:

Me.caption = "You are using " & getPathByName("X") & _
                    " Version: " getVersionByName("X") & _
                    " with GUID of " & getGUIDByName("X")
Question by:dbyrne03
    LVL 32

    Accepted Solution

    Here is one of the functions so far...

    getGUIDByName returns the CLSID of the ProgID passed in.

    Option Explicit

    'from the MS sample:

    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type

    Private Declare Function CLSIDFromProgID _
       Lib "ole32.dll" (ByVal lpszProgID As Long, _
       pCLSID As GUID) As Long

    Function getGUIDByName(ByVal ProgID As String) As String
        Dim cid As GUID
        Dim lngRet As Long
        Dim i As Integer
        Dim sCLSID As String
        'Get CLSID.
        lngRet = CLSIDFromProgID(StrPtr(ProgID), cid)
        'Build CLSID
        sCLSID = Right("00000000" & Hex(cid.Data1), 8) & "-"
        sCLSID = sCLSID & Right("0000" & Hex(cid.Data2), 4) & "-"
        sCLSID = sCLSID & Right("0000" & Hex(cid.Data3), 4) & "-"
        sCLSID = sCLSID & Right("00" & Hex(cid.Data4(0)), 2) & Right("00" & Hex(cid.Data4(1)), 2) & "-"
        For i = 2 To 7
              sCLSID = sCLSID & Right("00" & Hex(cid.Data4(i)), 2)
        getGUIDByName = sCLSID
    End Function

    'example useage
    Private Sub Command1_Click()
        Caption = getGUIDByName("excel.application")
    End Sub
    LVL 2

    Expert Comment

    If you require to read and write to the registry view.

    HOWTO: Use the Registry API to Save and Retrieve Setting
    Last reviewed: October 7, 1997
    Article ID: Q145679  

    in the VB help file this will also give you code samples in VB source.

    Author Comment

    Thanks Erick37.  I will use your function in combination with the one I found @;en-us;240794

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now