使用什么函数可以产生GUID?

noneone 2005-07-15 10:03:48
我想在程序中使用GUID来作某项配置的唯一标识,请问使用哪个函数来生成GUID?
...全文
519 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaojian666 2005-07-15
  • 打赏
  • 举报
回复
长见识
dabears 2005-07-15
  • 打赏
  • 举报
回复
#include "rpc.h"
#include "rpcdce.h"

GUID guid;
if(S_OK!=CoCreateGuid(&guid)) //4+2+2+8 = 16个字节
{
return;
}
else
{
BYTE * buf = new BYTE;
UuidToString((UUID*)&guid, &buf);
m_Edit = buf;
UpdateData(FALSE);
}
teli_eurydice 2005-07-15
  • 打赏
  • 举报
回复
GUID guid;
CoCreateGuid(&guid);

char strData1[9];
char strData2[5];
char strData3[5];
char strData4[8][3];

sprintf(strData1,"%08X",guid.Data1);
sprintf(strData2,"%04X",guid.Data2);
sprintf(strData3,"%04X",guid.Data3);
sprintf(strData4[0],"%02X",guid.Data4[0]);
sprintf(strData4[1],"%02X",guid.Data4[1]);
sprintf(strData4[2],"%02X",guid.Data4[2]);
sprintf(strData4[3],"%02X",guid.Data4[3]);
sprintf(strData4[4],"%02X",guid.Data4[4]);
sprintf(strData4[5],"%02X",guid.Data4[5]);
sprintf(strData4[6],"%02X",guid.Data4[6]);
sprintf(strData4[7],"%02X",guid.Data4[7]);

m_strID.Format("{%s-%s-%s-%s%s-%s%s%s%s%s%s}",strData1,strData2,strData3,
strData4[0],strData4[1],strData4[2],strData4[3],strData4[4],strData4[5],strData4[6],strData4[7]);
freebird_top 2005-07-15
  • 打赏
  • 举报
回复
上面己经回答得很好了.

CoCreateGuid
Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.

HRESULT CoCreateGuid(
GUID *pguid //Pointer to the GUID on return
);

Parameter
pguid
[out] Pointer to the requested GUID on return.
Return Value
S_OK
The GUID was successfully created.
Win32 errors are returned byUuidCreate but wrapped as an HRESULT.

Remarks
The CoCreateGuid function calls the RPC function UuidCreate, which creates a GUID, a globally unique 128-bit integer. Use the CoCreateGuid function when you need an absolutely unique number that you will use as a persistent identifier in a distributed environment.To a very high degree of certainty, this function returns a unique value – no other invocation, on the same or any other system (networked or not), should return the same value.

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.

bohut 2005-07-15
  • 打赏
  • 举报
回复
CoCreateGuid

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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