2017-05-26 48 views
-1

背景獲取結構的UUID

我有一個IDL file限定數目的struct像這樣

typedef[uuid(68D81983-793D-43BE-AC16-C74254C90607)] struct Foo 
{ 
    // some members 
} Foo; 

在編譯時(使用Visual Studio 2013)它生成一個.h文件,其中相應的struct被翻譯爲

typedef /* [uuid] */ DECLSPEC_UUID("68D81983-793D-43BE-AC16-C74254C90607") struct Foo 
{ 
    // some members 
} Foo; 

DECLSPEC_UUID擴展到

#define DECLSPEC_UUID(x) __declspec(uuid(x)) 

問題

我怎樣才能檢索到別處struct的UUID?

包括生成的頭之後,我試圖用__uuidof

static const auto idFoo = __uuidof(Foo); 

但後來我得到一個編譯錯誤

error C2787: 'Foo' : no GUID has been associated with this object 
+1

我不知道標記這是重複的,但這個答案似乎覆蓋了這個偉大的deatil:https://stackoverflow.com/questions/23977244/how-can-i-define-an -uuid換一個級和使用的-uuidof-內式相同的方式換克 – Chad

回答

0

這個問題似乎是試圖聲明和typedefstruct與此同時。

typedef[uuid(68D81983-793D-43BE-AC16-C74254C90607)] struct Foo 
{ 
    // some members 
} Foo; 

該溶液是聲明struct,然後seperately typedef它。然後__uuidof工作沒有問題。

[uuid(68D81983-793D-43BE-AC16-C74254C90607)] struct Foo 
{ 
    // some members 
}; 
typedef struct Foo Foo;