How to get IID of a COM interface on runtime

Davit Sargsyan 41 Reputation points
2022-12-09T05:47:14.203+00:00

I am using the following interface in my code:

// Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface\{372E1D3B-38D3-42E4-A15B-8AB2B178F513}  
DECLARE_INTERFACE_IID_(IApplicationView, IInspectable, "372E1D3B-38D3-42E4-A15B-8AB2B178F513")  
...  

then querying this interface:

    CComPtr<IServiceProvider> m_pServiceProvider;  
    CComPtr<IApplicationViewCollection> appCollection = NULL;  
  
    m_pServiceProvider.CoCreateInstance(__uuidof(IServiceProvider), NULL, CLSCTX_LOCAL_SERVER));  
    m_pServiceProvider->QueryService(__uuidof(IApplicationViewCollection), &appCollection));  
    ....  

I am also using a few other internal (non documented) interfaces, which I found on github. As I understood from github, the IID of those interfaces might change depending on windows build, because I have found different IIDs for the same interface. I wonder how can we get IID on runtime (maybe from registry?), so the code is portable and works on all windows builds. Please correct me if I am wrong or miss something, I don't know much about COM.

Windows development Windows API - Win32
{count} votes

Accepted answer
  1. RLWA32 49,536 Reputation points
    2022-12-09T12:00:58.877+00:00

    The interface information in the registry is used by the system for marshalling. However, since you are trying to work with internal/undocumented interfaces such entries may not exist. Further, it is possible to provide proxy / stub marshalling information for an interface to the system at run time through the CoRegisterPSClsid function.

    As far as I know there is no documented API function to return an IID for an arbitrary interface name.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.