Solved

How to get GUID using WinAPI

Posted on 1998-05-15
7
362 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:dnavarro
Comment Utility
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 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

11 Experts available now in Live!

Get 1:1 Help Now