Solved

How to get GUID using WinAPI

Posted on 1998-05-15
7
369 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 150 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Program using VBScript 3 65
Windows Installer 4 72
Visual Studio: built-in keystroke automation 2 65
Need an intro to -- .Net SQL Authorization Manager 7 87
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

772 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