Solved

How to find the class id of an arbitrary object?  Example:Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Posted on 2016-08-04
10
147 Views
Last Modified: 2016-08-27
Please, do not post tangents about whether today's goal is good, bad, fast, slow, brilliant or stupid.  I already had a bunch of those tangents here.  Strangely enough, that long winded discussion never mentioned createobject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")  which I now believe might be a very useful construction.

My goal is to make vba code more portable by switching from early binding to late binding. I wanted to do this for ARBITRARY object types while keeping the object's methods and properties unchanged.  

For instance let us say I want to switch the following code to late binding.

Dim x as dataobject ' reference to ms forms 2.0 object library  which on my machine is c:\windows\syswow64\fm20.dll
set x = new dataobject

I accidentally found a webpage that showed the following alternative.
   dim x as object
  Set x = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

How can intentionally find similar classids? For instance, can I transform the following
    dim x as new SHDocVw.ShellWindows
0
Comment
Question by:rberke
  • 4
  • 3
10 Comments
 
LVL 69

Accepted Solution

by:
Qlemo earned 300 total points (awarded by participants)
ID: 41743223
You can search in the registry below HKCR\CLSID for the value containing your class name to replace.
0
 
LVL 35

Assisted Solution

by:[ fanpages ]
[ fanpages ] earned 200 total points (awarded by participants)
ID: 41743364
I added the "Microsoft Internet Controls" as the fifth Reference in my VB(A)Project.

In the "Immediate" Window:

?ThisWorkbook.VBProject.References(5).Guid
{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}
0
 
LVL 5

Author Comment

by:rberke
ID: 41743383
I'll be a son of a gun -- that was really easy !!
 
To replace MSForms.dataobject I search for "dataobject" and found just what I needed:

HKEY_CLASSES_ROOT\CLSID\{1C3B4210-F441-11CE-B9EA-00AA006B1A69}\InprocServer32
        Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.DataObjectClass

Next, I wanted to replace < set x =  New SHDocVw.ShellWindows > so I searched for "ShellWindows"

HKEY_CLASSES_ROOT\CLSID\{9BA05972-F6A8-11CF-A442-00A0C90A8F39
     (default)  REG_SZ   Shellwindows
     Appid      Reg_SZ   {9BA05972-F6A8-11CF-A442-00A0C90A8F39}

That actually worked in the following

Sub ShowIE()
Dim shellWins As Object, explorer As Object '  SHDocVw.ShellWindows & SHDocVw.InternetExplorer
    Set shellWins = CreateObject("New:{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
    For Each explorer In shellWins
        Debug.Print explorer.LocationURL
    Next
End Sub

Open in new window

But, I still have one more question.  What if I had been try to replace   MsForms.Page?  Search for "Page" gives me a dozen false positives before I finally got to
      Class   Reg_SZ   Microsoft.Vbe.Interop.Forms.PageClass

I recognized that as the correct key because I had previously seen the same structure for the DataObject.  That is cheating, I want a methodology that finds an arbitrary object (without relying on previous success searching for a similar object).

Is there some methodology that will quickly get to the correct classId having just the library.class (E.G. SHDocVw.ShellWindows )?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 69

Expert Comment

by:Qlemo
ID: 41743403
Sorry, but I don't think you will succeed in that. Some classes are translated into something more easily to use. "MsForms.Page" certainly is a VB alias for "Microsoft.Vbe.Interop.Forms.PageClass".
But in general, the classes are following the same scheme. "MsForms" translates to "Microsoft.Vbe.Interop.Forms" - always.
"Excel.Application" is a COM reference, and as such has an entry below HKCR\Excel.Application with CLSID pointing to HKCR\CLSID, and that again contains the real class name "Microsoft.Office.Interop.Excel.ApplicationClass". This shows the complexity of your request.
0
 
LVL 5

Author Comment

by:rberke
ID: 41743430
I am still making more progress than I expected.  I will leave this question open for while, just in case someone has a better idea.  Then I will award you points.  

Thanks for you help.

rberke
0
 
LVL 5

Author Comment

by:rberke
ID: 41743468
To replace  set  var = new xxxxx.yyyy
With  Set var = CreateObject("new:{3F4DACA4-160D-11D2-A8E9-00104B365C9F}")

You must first find the “magic numbers”. The following procedure seems to work pretty well.
Open Notepad to be used as workspace.

Open regedit and manuver to HKEY_CLASSES_ROOT\CLSID\
Ctrl f to find in yyyyy.  (remove the checkbox next to Keys and Values, and keep Data)

Edit > Copy Key Name > then paste into notepad.
Edit > Modify > Ctrl C > then paste into notepad. The first entry might look like this
    HKEY_CLASSES_ROOT\CLSID\{1C3B4210-F441-11CE-B9EA-00AA006B1A69}\InprocServer32
    Class REG_SZ Microsoft.Vbe.Interop.Forms.DataObjectClass

Use F3 to repeat the find and record the next occurances of yyyyy.
If the search “hangs” for over a minute, you are done.
You are also done if the key name does not start with HKEY_CLASSES_ROOT\CLSID

For instance yyyyy = “InternetExplorer” might look like this
HKEY_CLASSES_ROOT\CLSID\{0002DF01-0000-0000-C000-000000000046}\ProgID
InternetExplorer.Application.1
HKEY_CLASSES_ROOT\CLSID\{0002DF01-0000-0000-C000-000000000046}\VersionIndependentProgID
InternetExplorer.Application

Summarize all the class ids and ignore duplicates.  
Eliminate incorrect class ids using code like this.

Sub test711()
On Error Resume Next
Dim x1 As SHDocVw.InternetExplorer ' your original early binding class
Dim x2 As Object
Dim x3 As Object
Set x2 = CreateObject("new:{0002DF01-0000-0000-C000-000000000046}") ' possible replacement
Set x3 = CreateObject("new:{xxxxxxx.....xxxx}") ' another possible replacement

Debug.Print TypeName(x1) & vbCrLf & TypeName(x2) & vbCrLf & TypeName(x3)

End Sub
0
 
LVL 5

Author Comment

by:rberke
ID: 41763088
I still believe there might be a more general answer and (when I have time) I am going to open a new question to pursue a general resolution to my question.
For instance, I am very intrigued by Fanpage's code which shows the GuiId associated with a referenced library.    Perhaps there is some way of diving lower into the reference and pull out all class names and their associated clsid?

But, for right now, I agree the question should be closed.

Qlemo should get best answer

300 Points should go to Qlemo, and 200 to Fanpages.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 41765117
OP stated a different point distribution, so stopping the closing process.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

839 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