getting component information (by name) at run time

Posted on 2004-11-15
Medium Priority
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

Erick37 earned 375 total points
ID: 12590581
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

Expert Comment

ID: 12590614
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

ID: 12590939
Thanks Erick37.  I will use your function in combination with the one I found @

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

830 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