GUID的格式转换

pengys 2013-11-08 03:01:14
已知ID是{FE249502-6292-4232-8151-89A555023E25}
如何转换成static const struct GUID格式
static const IID IID_IKeyValue =
{ 0xFE249502, 0x6292, 0x4232, { 0x81, 0x51, 0x89, 0xA5, 0x55, 0x2, 0x3E, 0x25 } };
...全文
451 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengys 2013-11-08
  • 打赏
  • 举报
回复
我以为有现成的工具可以转换。谢谢大家
pengys 2013-11-08
  • 打赏
  • 举报
回复
按照那个格式前面都加“0x”就可以了,是吗?
赵4老师 2013-11-08
  • 打赏
  • 举报
回复
IIDFromString Converts a string generated by the StringFromIID function back into the original interface identifier (IID). WINOLEAPI IIDFromString( LPOLESTR lpsz, //Pointer to the string representation of the IID LPIID lpiid //Pointer to the requested IID on return ); Parameters lpsz [in] Pointer to the string representation of the IID. lpiid [out] Pointer to the requested IID on return. Return Values This function supports the standard return values E_INVALIDARG and E_OUTOFMEMORY, as well as the following: S_OK The string was successfully converted. Remarks The function converts the interface identifier in a way that guarantees different interface identifiers will always be converted to different strings. QuickInfo Windows NT: Use version 3.1 or later. Windows: Use Windows 95 or later. Windows CE: Unsupported. Header: Declared in objbase.h. Import Library: Included as a resource in ole32.dll. See Also StringFromIID StringFromIID Converts an interface identifier into a string of printable characters. WINOLEAPI StringFromIID( REFIID rclsid, //Interface identifier to be converted LPOLESTR * lplpsz //Address of output variable that receives a // pointer to the resulting string ); Parameters rclsid [in] Interface identifier to be converted. lplpsz [out] Address of LPOLESTR pointer variable that receives a pointer to the resulting string. Return Values This function supports the standard return value E_OUTOFMEMORY; as well as the following: S_OK The character string was successfully returned. Remarks The string returned by the function is freed in the standard way, using the task allocator (refer to the CoGetMallocfunction). Windows CE: Passing into this function any invalid and, under some circumstances, NULL pointers will result in unexpected termination of the application. For more information about handling exceptions, see Programming Considerations. QuickInfo Windows NT: Use version 3.1 or later. Windows: Use Windows 95 or later. Windows CE: Use version 2.0 or later. Header: Declared in objbase.h. Import Library: Included as a resource in ole32.dll. See Also IIDFromString, CoGetMalloc
赵4老师 2013-11-08
  • 打赏
  • 举报
回复
IID The IID structure is a GUID structure used to describe an identifier for a MAPI interface. Remarks An IID structure is used to uniquely identify a MAPI interface and to associate a particular interface with an object. For example, when a client calls IMAPISession::OpenEntry to open a folder, the client sets the lpInterface parameter to point to an IID representing the IMAPIFolder interface. MAPI defines the IMAPIFolder IID to be IID_IMAPIFolder. IID structures are also used to uniquely identify OLE interfaces. All of the specific IID structures for the MAPI interfaces are defined in the MAPIGUID.H header file. See Also ID Structures GUID The GUID structure describes a globally unique identifier. Quick Info Header file: MAPIGUID.H typedef struct _GUID { unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8]; } GUID; Members Data1 An unsigned long integer data value. Data2 An unsigned short integer data value. Data3 An unsigned short integer data value. Data4 An array of unsigned characters. Remarks GUID structures are used in MAPI as follows: In the MAPIUID structures that uniquely identify service providers. For interface identifiers. In the property set names of named properties. Message store and address book providers call the Microsoft utility UUIDGEN.EXE to generate a GUID structure to use in their MAPIUID structure. By passing the resulting MAPIUID to IMAPISupport::SetProviderUID, these service providers inform MAPI of their unique identifier. Also, they are used in the implementation of Microsoft Remote Procedure Call (RPC) and the Object Description Language (ODL). For more information about these uses, see the Microsoft RPC Programmer's Guide and Reference, OLE Programmer's Reference, and Inside OLE, Second Edition. The GUID structure is defined in the Win32 Programmer's Reference. Specific values for GUID structures that are used within MAPI are defined in the MAPI header file MAPIGUID.H. See Also ID Structures, MAPIUID
#include <stdio.h>
#include <windows.h>
char ID[]="{FE249502-6292-4232-8151-89A555023E25}";
static IID IID_IKeyValue;
int i,b[8];
int main() {
    sscanf(ID,"{%8X-%4hX-%4hX-%2X%2X-%2X%2X%2X%2X%2X%2X}",&IID_IKeyValue.Data1,&IID_IKeyValue.Data2,&IID_IKeyValue.Data3,&b[0],&b[1],&b[2],&b[3],&b[4],&b[5],&b[6],&b[7]);
    for (i=0;i<8;i++) IID_IKeyValue.Data4[i]=(unsigned char)b[i];
    printf("{ 0x%08X, 0x%04hX, 0x%04hX, { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X } }\n",
        IID_IKeyValue.Data1,
        IID_IKeyValue.Data2,
        IID_IKeyValue.Data3,
        IID_IKeyValue.Data4[0],
        IID_IKeyValue.Data4[1],
        IID_IKeyValue.Data4[2],
        IID_IKeyValue.Data4[3],
        IID_IKeyValue.Data4[4],
        IID_IKeyValue.Data4[5],
        IID_IKeyValue.Data4[6],
        IID_IKeyValue.Data4[7]);
    return 0;
}
//{ 0xFE249502, 0x6292, 0x4232, { 0x81, 0x51, 0x89, 0xA5, 0x55, 0x02, 0x3E, 0x25 } }
//
pengys 2013-11-08
  • 打赏
  • 举报
回复
事情是这样的,原来com工程代码丢了,需要重新写,重新生成的static const IID需要替换掉,注册表中我找到原来的IID,格式是{FE249502-6292-4232-8151-89A555023E25}的,我想知道如何转换成这样的: static const IID IID_IKeyValue = { 0xFE249502, 0x6292, 0x4232, { 0x81, 0x51, 0x89, 0xA5, 0x55, 0x2, 0x3E, 0x25 } };
worldy 2013-11-08
  • 打赏
  • 举报
回复
引用 2 楼 worldy 的回复:
iid只是一个16字节的内存而已,表达格式你自己对内存进行解释就行了,如果你最前面的说的字符串,那应该可以使用__uuidof转
记错了,字串可以使用下面方式转: IID id; IIDFromString(_bstr_t("{00020400-0000-0000-c000-000000000046}"),&id);
pengys 2013-11-08
  • 打赏
  • 举报
回复
// {FE249502-6292-4232-8151-89A555023E25} static const IID IID_IKeyValue = { 0xFE249502, 0x6292, 0x4232, { 0x81, 0x51, 0x89, 0xA5, 0x55, 0x2, 0x3E, 0x25 } };
worldy 2013-11-08
  • 打赏
  • 举报
回复
iid只是一个16字节的内存而已,表达格式你自己对内存进行解释就行了,如果你最前面的说的字符串,那应该可以使用__uuidof转
秃头披风侠 2013-11-08
  • 打赏
  • 举报
回复
引用 楼主 pengys 的回复:
已知ID是{FE249502-6292-4232-8151-89A555023E25}
是字符串吗?字符串似乎不能直接转GUID

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧