'How to get GUIDs of COM classes from the interface names used in the Windows API documentation?
What is the correct way to find the GUID (for instance {1C158861-B533-4B30-B1CF-E853E51C59B8}
) for a given COM class named in the Windows SDK documentation (for instance IChannelAudioVolume
)?
I'm working on a Python script that sets Windows audio mixer settings for individual applications that are playing audio (audio sessions). I want to set the channel volumes, to pan the audio, which is built-in Windows functionality exposed by the IChannelAudioVolume API.
I see that pycaw
uses many COM-based Windows APIs through comtypes
, starting with declarations that provide the GUID, parent interface, and method details to comtypes
:
from ctypes import HRESULT, POINTER, c_uint32, c_float
from comtypes import IUnknown, GUID, COMMETHOD
class ISimpleAudioVolume(IUnknown):
_iid_ = GUID('{87CE5498-68D6-44E5-9215-6DA47EF883D8}')
_methods_ = (
# HRESULT SetMasterVolume(
# [in] float fLevel,
# [in] LPCGUID EventContext);
COMMETHOD([], HRESULT, 'SetMasterVolume',
(['in'], c_float, 'fLevel'),
(['in'], POINTER(GUID), 'EventContext')), # ...
Where does someone writing this kind of code find out these GUIDs (e.g. '{87CE5498-68D6-44E5-9215-6DA47EF883D8}'
) that correspond to particular interface names? They are not in the main documentation for the individual interfaces. Are they documented officially somewhere? Alternately, is there something that I can run to look them up from the interface name (e.g. ISimpleAudioVolume
) in Windows?
In the meantime, I'm just Googling the name of the interface I'm looking for, along with GUID values of thematically-similar interfaces without the {}
, and hoping to come across other code samples that have them. This works well enough for my immediate purposes, but is hit or miss, and it's unclear whether the GUIDs I find this way are intended as public APIs.
Solution 1:[1]
This online tool MagnumDb as "Magic Number Database" (disclaimer: I wrote it) is a totally free seach engine that contains 99% of Windows SDK constants with more than 70K guids (IID, CLSID, etc.).
You can query it by name or by value, using wildcards, etc., for example: http://www.magnumdb.com/search?q=IChannelAudioVolume
will get you this (name, type, value, SDK header file location):
IID_IChannelAudioVolume Guid 1c158861-b533-4b30-b1cf-e853e51c59b8 %ProgramFiles(x86)%\Windows Kits\10\Include\10.0.17134.0\um\Audioclient.h(1942,0)
Solution 2:[2]
The Windows SDK contains interface definition (IDL) files alongside the C/C++ header files in the Include directories, and these contain the GUIDs.
The MSDN API documentation for an interface, for instance IChannelAudioVolume
, provides the C/C++ header file name in the Requirements box near the bottom of the page. For IChannelAudioVolume
, it is Audioclient.h
. Search the SDK directory for that filename, to find the subdirectory where that header file is found, in this case
C:\Program Files (x86)\Windows Kits\8.0\Include\um
There you will find an associated IDL file Audioclient.idl
.
This has a section for each interface, where you can find the GUIDs, e.g.:
//-----------------------------------------------------------------------------
// Description: IChannelAudioVolume interface
//
[
object,
uuid(1C158861-B533-4B30-B1CF-E853E51C59B8),
// ...
Solution 3:[3]
I wrote a project which analyzes the Windows SDK and parses all header files to extract this information: https://github.com/Elmue/WindowsRT-GUID-Analyzer
It auto-generates INI, XML, HTML, C# and C++ files for getting an interface name from a given GUID.
You don't need to install Windows SDK. I uploaded the auto-generated files.
Here you see your interface in the auto-generate C# code:
Dictionary<String,String> mi_Interfaces = new Dictionary<String,String>();
....
mi_Interfaces["96236A83-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarity";
mi_Interfaces["96236A7F-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityFileIdTable";
mi_Interfaces["96236A7A-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityReportProgress";
mi_Interfaces["96236A7B-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityTableDumpState";
mi_Interfaces["96236A7C-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityTraitsMappedView";
mi_Interfaces["96236A7D-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityTraitsMapping";
mi_Interfaces["96236A7E-9DBC-11DA-9E3F-0011114AE311"] = "ISimilarityTraitsTable";
mi_Interfaces["87CE5498-68D6-44E5-9215-6DA47EF883D8"] = "ISimpleAudioVolume";
mi_Interfaces["5E341AB7-02D0-11D1-900C-00A0C9063796"] = "ISimpleCommandCreator";
mi_Interfaces["51973C3E-CB0C-11D0-B5C9-00A0244A0E7A"] = "ISimpleConnectionPoint";
mi_Interfaces["742B0E01-14E6-101B-914E-00AA00300CAB"] = "ISimpleFrameSite";
mi_Interfaces["9A189741-DED1-4535-B116-B6D287BF70D2"] = "ISimpleModemCompletion";
mi_Interfaces["892FB9B0-7C55-4A18-9316-FDF449569B64"] = "ISingleItemException";
mi_Interfaces["624B5CA7-FE40-4957-A019-20C4CF11920F"] = "IsItemContainerPatternAvailable_Property_GUID";
mi_Interfaces["B4563688-98EB-4646-B279-44DA14D45748"] = "ISketchInk";
....
The file containing 25600 interfaces can be downloaded here: All Windows 11 Interfaces - C# Windows GUID Database
There is also a *.XML, *.HTM, *.CS and *.H file.
You can simply modify the project to output the data in reverse order: Input=Interface Name --> Output=GUID and you can modify the CSharp template to generate Python code instead.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Simon Mourier |
Solution 2 | |
Solution 3 |