?
Solved

How to get GUID using WinAPI

Posted on 1998-05-15
7
Medium Priority
?
435 Views
Last Modified: 2013-12-03
I need to get the GUID of an object at "run-time".  I realize that most GUIDs are available in the header files provided in the Win32 SDK, but I need to get a GUID at run-time for a call to CoCreateInstance().

Essentially, I am attempting to call an OLE object from a non-object oriented language through Win32 API calls. I've got it working with the GUIDs generated by the macros in the SDK header files, but I can't seem to find a way to get a GUID at run-time.
0
Comment
Question by:dnavarro
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1402078
GUID is static unique information specific to every server or interface. If you know what objects you want to call you can descover their CLSIDs or interface IDs.
0
 
LVL 1

Author Comment

by:dnavarro
ID: 1402079
Okay, so how do I get a CLSID at run-time?  For example, at run-time how do I get a CLSID for "iShellLink"?

Thanks for your help.


0
 
LVL 7

Expert Comment

by:galkin
ID: 1402080
This is global unique name. Object is identified by this number. How are you going to identify interface or object you want to create? you are saying you want to create IShellLink so you try to identify interface usig name. This is not supposed to be unique in space in time. That's why COM uses GUID instaed of names. if you are still going to do this by name you can create static map from name to GUID.
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:dnavarro
ID: 1402081
What I want to do is call an OLE object at runtime.  I do not know the name of the object or the ID of the object, that is supplied by the user.

As a test, I thought I would try iShellLink.  My 'hope' was that I could pass the object name and file name to an API call and get back a CLSID compatible with CoCreateObject.

I've successfully used the CLSID during compile time from the win32 header fiiles, so I know the code works, but I don't know how to get a CLSID at run-time.

I haven't been able to read the CLSID's from the header file and "type them in" because they are actually created by pre-processor macros.
0
 
LVL 7

Accepted Solution

by:
galkin earned 450 total points
ID: 1402082
You can get CLSID from program ID and vice versa with CLSIDFromProgID. But not all servers implement ProgID but they do implement CLSID. Anyway CLSID is the only number you can locate server and it is fundamental of COM.
0
 
LVL 1

Author Comment

by:dnavarro
ID: 1402083
I was able to use CLSIDfromProgID with an OCX I've been testing, but not with iShellLink.  Apparently the objects built-in to Windows don't have CLSID's in the registry.  But I think I could use CLSIDfromString if I new what CLSID string to pass.  Any ideas?

Thank you for your answer.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1402084
IShellLink is interface not server. when you creat object with CoCreateInstance the first parameter you supply is CLSID of the server. CLSIDFromString simply converts string representation of CLSID into 128bit number(more precisely structure that has four numbers and ocupies 128bit).
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

850 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