2008-11-13 68 views
1

我正在從C++訪問.NET COM對象。我想知道關於這個COM對象的版本信息。當我在OLEVIEW.exe中打開TLB時,我可以看到與coclass關聯的版本信息。我如何從C++訪問這些信息?這是我得到的信息:獲取COM對象的版本

[ 
    uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX), 
    version(1.0), 
    custom(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX, XXXX) 
] 
coclass XXXXXXXX{ 
    [default] interface XXXXXXXX; 
    interface _Object; 
    interface XXXXXXXX; 
}; 

回答

1

基本上最後我發現我需要使用ITypeLib接口獲取信息。所以這裏是解決方案:

BSTR bstrTLBNameWithPath = ""; //set this to whatever you want 

    if(bstrTLBNameWithPath) 
    { 
    ITypeLib * pTlib = 0; 
    HRESULT hr = LoadTypeLib(bstrTLBNameWithPath,&pTlib); 
    if(SUCCEEDED(hr) && pTlib) 
    { 
     TLIBATTR * pTlibattr = 0; 
     hr = pTlib->GetLibAttr(&pTlibattr); 
     if(SUCCEEDED(hr) && pTlibattr) 
     { 
     //do something with the info 

     //release the information 
     pTlib->ReleaseTLibAttr(pTlibattr); 
     pTlib->Release(); 
     } 
    } 
    } 
1

code project有一個類,將在運行時做到這一點。