COM 根据CLSID获取ProgID
2022-02-17
83
0
void GetProgID()
{
CoInitialize(NULL);
//{000209FF-0000-0000-C000-000000000046} = word.application
LPOLESTR lpwProgID = NULL; //指针
CLSID clsid = { 0x209ff,0,0,{0xc0,0,0,0,0,0,0,0x46} }; //定义一个CLSIDS标识
CoInitialize(NULL); //初始化COM库
HRESULT hr = ProgIDFromCLSID(clsid, &lpwProgID); //根据CLSID取得ProgID指针
if (SUCCEEDED(hr))
{
::MessageBox(NULL, lpwProgID, L"ProgID",MB_OK); //显示ProgID
IMalloc* pMalloc = NULL; //初始化指针
hr = CoGetMalloc(1, &pMalloc); //取得IMalloc
if (SUCCEEDED(hr))
{
pMalloc->Free(lpwProgID); //释放ProgID内存
pMalloc->Release(); //释放IMalloc
}
}
CoUninitialize(); //释放COM库
}
本机中执行结果如下:
因为本机注册表中信息如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CLSID\{000209FF-0000-0000-C000-000000000046}\ProgID]
@="Word.Application.15"