 |
Borland的产品好象没有专门的函数。在Windows编程时,可以调用CoCreateGuid函数获得唯一的不重复的数。
Baby提供了下面的例子:
#include <rpc.h>
BOOL WINAPI GenerateGUID(unsigned char* pGUID, WORD nBufferLength = 36)
{
if (NULL == pGUID) return(FALSE);
UUID GUID;
RPC_STATUS theRPC_STATUS = UuidCreate(&GUID);
// In Windows NT, versions 4.0 and later, Windows 95, DCOM release,
// and Windows 98, UuidCreate returns RPC_S_UUID_LOCAL_ONLY when the
// originating machine does not have an ethernet/token ring (IEEE 802.x) address.
if ((RPC_S_OK == theRPC_STATUS) || (RPC_S_UUID_LOCAL_ONLY == theRPC_STATUS))
{
switch (nBufferLength)
{
case 16:
memcpy(pGUID, &GUID, sizeof(UUID));
return(TRUE);
case 36:
unsigned char* psGUID;
if (UuidToString(&GUID, &psGUID) == RPC_S_OK)
{
memcpy(pGUID, psGUID, 36);
RpcStringFree(&psGUID);
return(TRUE);
}
}
}
return(FALSE);
}
Phil的意见:
CreateGUID 或 CreateClassID sample :
var
AGuid:TGuid;
begin
OLECheck(CreateGUID(AGuid));
ShowMessage(GUIDToString(AGuid))
ShowMessage(CreateClassID);
end;
相关问题:
QA003702 "Guid的值定义的的含义"
此问题由李海回答。
附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, Delphi, VCL, Borland, 其他方面, 。
|