Link to home
Start Free TrialLog in
Avatar of dnavarro
dnavarro

asked on

How to get GUID using WinAPI

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.
Avatar of galkin
galkin

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.
Avatar of dnavarro

ASKER

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.


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.
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.
ASKER CERTIFIED SOLUTION
Avatar of galkin
galkin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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).