本文整理汇总了C++中UuidCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ UuidCreate函数的具体用法?C++ UuidCreate怎么用?C++ UuidCreate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UuidCreate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UuidCreate
std::wstring Directory::CreateDirectoryWithUniqueName (const std::wstring & strFolderPathRoot)
{
UUID uuid;
RPC_WSTR str_uuid;
UuidCreate (&uuid);
UuidToString (&uuid, &str_uuid);
std::wstring pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
pcTemplate += (TCHAR *) str_uuid;
RpcStringFree (&str_uuid);
int attemps = 10;
while (!CreateDirectory(pcTemplate))
{
UuidCreate (&uuid);
UuidToString (&uuid, &str_uuid);
pcTemplate = strFolderPathRoot + FILE_SEPARATOR_STR;
pcTemplate += (TCHAR *) str_uuid;
RpcStringFree (&str_uuid);
attemps--;
if (0 == attemps)
{
pcTemplate = _T("");
}
}
return pcTemplate;
}
示例2: test_UuidCreate
static void test_UuidCreate(void)
{
UUID guid;
BYTE version;
UuidCreate(&guid);
version = (guid.Data3 & 0xf000) >> 12;
ok(version == 4 || broken(version == 1), "unexpected version %d\n",
version);
if (version == 4)
{
static UUID v4and = { 0, 0, 0x4000, { 0x80,0,0,0,0,0,0,0 } };
static UUID v4or = { 0xffffffff, 0xffff, 0x4fff,
{ 0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff } };
UUID and, or;
RPC_STATUS rslt;
int i;
char buf[39];
and = guid;
or = guid;
/* Generate a bunch of UUIDs and mask them. By the end, we expect
* every randomly generated bit to have been zero at least once,
* resulting in no bits set in the and mask except those which are not
* randomly generated: the version number and the topmost bits of the
* Data4 field (treated as big-endian.) Similarly, we expect only
* the bits which are not randomly set to be cleared in the or mask.
*/
for (i = 0; i < 1000; i++)
{
LPBYTE src, dst;
UuidCreate(&guid);
for (src = (LPBYTE)&guid, dst = (LPBYTE)∧
src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
*dst &= *src;
for (src = (LPBYTE)&guid, dst = (LPBYTE)∨
src - (LPBYTE)&guid < sizeof(guid); src++, dst++)
*dst |= *src;
}
ok(UuidEqual(&and, &v4and, &rslt),
"unexpected bits set in V4 UUID: %s\n", printGuid(buf, sizeof(buf), &and));
ok(UuidEqual(&or, &v4or, &rslt),
"unexpected bits set in V4 UUID: %s\n", printGuid(buf, sizeof(buf), &or));
}
else
{
/* Older versions of Windows generate V1 UUIDs. For these, there are
* many stable bits, including at least the MAC address if one is
* present. Just check that Data4[0]'s most significant bits are
* set as expected.
*/
ok((guid.Data4[0] & 0xc0) == 0x80,
"unexpected value in Data4[0]: %02x\n", guid.Data4[0] & 0xc0);
}
}
示例3: srand
void
random_c::generate_bytes(void *destination,
size_t num_bytes) {
UUID uuid;
if (!m_seeded) {
srand(GetTickCount());
m_seeded = true;
}
if (!m_tried_uuidcreate) {
// Find out whether UuidCreate returns different
// data in Data4 on each call by comparing up to five
// results. If not use srand() and rand().
UUID first_uuid;
int i;
m_use_uuidcreate = true;
RPC_STATUS status = UuidCreate(&first_uuid);
if ((RPC_S_OK == status) || (RPC_S_UUID_LOCAL_ONLY == status)) {
for (i = 0; i < 5; ++i) {
status = UuidCreate(&uuid);
if (((RPC_S_OK != status) && (RPC_S_UUID_LOCAL_ONLY != status)) ||
!memcmp(first_uuid.Data4, uuid.Data4, sizeof(uuid.Data4))) {
m_use_uuidcreate = false;
break;
}
}
} else
m_use_uuidcreate = false;
m_tried_uuidcreate = true;
}
size_t num_written = 0;
while (num_written < num_bytes) {
if (m_use_uuidcreate) {
RPC_STATUS status = UuidCreate(&uuid);
if ((RPC_S_OK != status) && (RPC_S_UUID_LOCAL_ONLY != status)) {
m_use_uuidcreate = false;
continue;
}
int num_left = num_bytes - num_written;
if (num_left > 8)
num_left = 8;
memcpy((unsigned char *)destination + num_written, &uuid.Data4, num_left);
num_written += num_left;
} else
for (; num_written < num_bytes; ++num_written)
((unsigned char *)destination)[num_written] = (unsigned char)(256.0 * rand() / (RAND_MAX + 1.0));
}
}
示例4: TEST
TEST(Guid2StrTest, RandomGUID) {
GUID guid = { 0 };
UuidCreate(&guid);
Guid2Str *o = new Guid2Str(guid);
EXPECT_TRUE(o->Str() != NULL);
delete o;
}
示例5: _uuuid_create
static void _uuuid_create(struct uuuid_t** uuuid, int* status, int nil)
{
struct uuuid_t* u;
RPC_STATUS st;
u = uuuid_new();
if (!u) {
*status = UUUID_ERR;
return;
}
if (nil)
st = UuidCreateNil(&u->uuid);
else
st = UuidCreate(&u->uuid);
if (st != RPC_S_OK) {
uuuid_free(u);
*status = UUUID_ERR;
return;
}
*uuuid = u;
*status = UUUID_OK;
}
示例6: UuidCreate
void MSVC8_Filter::write_filter_name_vs100(OutputWriter &output, int indent, const std::string &parent) const
{
std::string new_filter;
if (parent.length())
{
new_filter = parent + "\\" + name;
}
else
{
new_filter = name;
}
output.write_line(indent, " <Filter Include=\"" + new_filter + "\">");
// Create a new GUID:
unsigned char *projectGUID = 0;
GUID guid;
UuidCreate(&guid);
UuidToStringA(&guid, &projectGUID);
_strupr((char *) projectGUID);
std::string returnGUID = std::string("{") + ((char *) projectGUID) + std::string("}");
RpcStringFreeA(&projectGUID);
output.write_line(indent, " <UniqueIdentifier>" + returnGUID + "</UniqueIdentifier>");
output.write_line(indent, " </Filter>");
std::vector<MSVC8_FileItem *>::size_type index;
for (index = 0; index < files.size(); index++)
{
files[index]->write_filter_name_vs100(output, indent, new_filter);
}
}
示例7: put_uuid_string
static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
{
UUID uuid;
RPC_STATUS status = UuidCreate(&uuid);
HRESULT result;
if (RPC_S_OK != status &&
RPC_S_UUID_LOCAL_ONLY != status &&
RPC_S_UUID_NO_ADDRESS != status) {
giterr_set(GITERR_NET, "Unable to generate name for temp file");
return -1;
}
if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
giterr_set(GITERR_NET, "Buffer too small for name of temp file");
return -1;
}
result = StringCbPrintfW(
buffer, buffer_len_cch,
L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x",
uuid.Data1, uuid.Data2, uuid.Data3,
uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3],
uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]);
if (FAILED(result)) {
giterr_set(GITERR_OS, "Unable to generate name for temp file");
return -1;
}
return 0;
}
示例8: zuuid_new
zuuid_t *
zuuid_new (void)
{
zuuid_t *self = (zuuid_t *) zmalloc (sizeof (zuuid_t));
if (self) {
#if defined (HAVE_LIBUUID)
# if defined (__WINDOWS__)
UUID uuid;
assert (sizeof (uuid) == ZUUID_LEN);
UuidCreate (&uuid);
zuuid_set (self, (byte *) &uuid);
# else
uuid_t uuid;
assert (sizeof (uuid) == ZUUID_LEN);
uuid_generate (uuid);
zuuid_set (self, (byte *) uuid);
# endif
#else
// No UUID system calls, so generate a random string
byte uuid [ZUUID_LEN];
int fd = open ("/dev/urandom", O_RDONLY);
if (fd != -1) {
ssize_t bytes_read = read (fd, uuid, ZUUID_LEN);
assert (bytes_read == ZUUID_LEN);
close (fd);
}
zuuid_set (self, uuid);
#endif
}
return self;
}
示例9: V2vConnectorProcessInternalTx
static ULONG
V2vConnectorProcessInternalTx(V2V_CONNECTOR_STATE *vcs)
{
unsigned available;
volatile UCHAR *msg;
ULONG error;
V2V_FRAME_HEADER *header;
V2V_POST_INTERNAL *vpi;
RPC_STATUS rpcstat;
size_t msize;
printf("V2VAPP-CONNECTOR sending internal message #%d\n", vcs->txCounter + 1);
available = v2v_nc2_producer_bytes_available(vcs->channel);
printf("V2VAPP-CONNECTOR channel indicates minimum bytes available: 0x%x\n", available);
if (vcs->vac->xferSize == 0) {
printf("V2VAPP-CONNECTOR transer size 0, send nothing\n");
return ERROR_SUCCESS;
}
if (vcs->vac->fastrx && v2v_nc2_remote_requested_fast_wakeup(vcs->channel))
msize = MIN(vcs->vac->xferSize, vcs->vac->xferMaxFastRx);
else
msize = vcs->vac->xferSize;
if (!v2v_nc2_prep_message(vcs->channel, msize, V2V_MESSAGE_TYPE_INTERNAL, 0, &msg)) {
error = GetLastError();
if (error == ERROR_RETRY) {
/* No room right now, return and try again later */
printf("V2VAPP-CONNECTOR not enough buffer space to send message #%d; retry\n", vcs->txCounter + 1);
return ERROR_RETRY;
}
printf("V2VAPP-CONNECTOR transmit internal data failure; abort processing - error: 0x%x\n", error);
return error; /* failure */
}
vcs->txCounter++; /* next message */
header = (V2V_FRAME_HEADER*)msg;
header->id = (USHORT)vcs->txCounter;
header->type = V2V_MESSAGE_TYPE_INTERNAL;
header->cs = 0;
header->length = vcs->vac->xferSize;
vpi = (V2V_POST_INTERNAL*)msg;
rpcstat = UuidCreate(&vpi->guid);
if (rpcstat != RPC_S_OK) {
printf("V2VAPP-CONNECTOR UuidCreate() failed - error: 0x%x; using NULL GUID\n", rpcstat);
memset((void*)(msg + sizeof(V2V_FRAME_HEADER)), 0, sizeof(GUID));
}
/* Fill it up with some data and send it */
memset((void*)(msg + sizeof(V2V_POST_INTERNAL)),
'X',
(vcs->vac->xferSize - sizeof(V2V_POST_INTERNAL)));
header->cs = V2vChecksum((const UCHAR*)msg, vcs->vac->xferSize);
v2v_nc2_send_messages(vcs->channel);
/* Keep the send loop going by setting the event. If there is no more room, the prep message call
will return ERROR_RETRY and just land us back in the wait. */
SetEvent(v2v_get_send_event(vcs->channel));
return ERROR_SUCCESS;
}
示例10: initialize_display_settings
static void initialize_display_settings( HWND desktop )
{
static const WCHAR display_device_guid_propW[] = {
'_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
'd','e','v','i','c','e','_','g','u','i','d',0 };
GUID guid;
RPC_CSTR guid_str;
ATOM guid_atom;
DEVMODEW dmW;
UuidCreate( &guid );
UuidToStringA( &guid, &guid_str );
WINE_TRACE( "display guid %s\n", guid_str );
guid_atom = GlobalAddAtomA( (LPCSTR)guid_str );
SetPropW( desktop, display_device_guid_propW, ULongToHandle(guid_atom) );
RpcStringFreeA( &guid_str );
/* Store current display mode in the registry */
if (EnumDisplaySettingsExW( NULL, ENUM_CURRENT_SETTINGS, &dmW, 0 ))
{
WINE_TRACE( "Current display mode %ux%u %u bpp %u Hz\n", dmW.dmPelsWidth,
dmW.dmPelsHeight, dmW.dmBitsPerPel, dmW.dmDisplayFrequency );
ChangeDisplaySettingsExW( NULL, &dmW, 0,
CDS_GLOBAL | CDS_NORESET | CDS_UPDATEREGISTRY,
NULL );
}
}
示例11: get_uuid
static void get_uuid(char *str)
{
#ifdef HAVE_WINDOWS_H
UUID guid;
UuidCreate(&guid);
sprintf(str, "%08lX-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.Data1, guid.Data2, guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
#elif defined(HAVE_CFUUIDCREATE)
CFUUIDRef myUUID;
CFStringRef myUUIDString;
char strBuffer[100];
myUUID = CFUUIDCreate(kCFAllocatorDefault);
myUUIDString = CFUUIDCreateString(kCFAllocatorDefault, myUUID);/* This is the safest way to obtain a C string from a CFString.*/
CFStringGetCString(myUUIDString, str, SMPD_MAX_DBS_NAME_LEN, kCFStringEncodingASCII);
CFRelease(myUUIDString);
#elif defined(HAVE_UUID_GENERATE)
uuid_t guid;
uuid_generate(guid);
uuid_unparse(guid, str);
#else
sprintf(str, "%X%X%X%X", rand(), rand(), rand(), rand());
#endif
}
示例12: OpcUa_P_Guid_Create
/**
* CreateGuid generates a global unique identifier. It calls the
* Win32 API function for doing this.
*/
OpcUa_Guid* OPCUA_DLLCALL OpcUa_P_Guid_Create(OpcUa_Guid* Guid)
{
#ifndef _GUID_CREATE_NOT_AVAILABLE
if(UuidCreate((UUID*)Guid) != RPC_S_OK)
{
/* Error */
Guid = OpcUa_Null;
return OpcUa_Null;
}
/* Good */
return Guid;
#else
unsigned int *data = (unsigned int*)Guid;
int chunks = 16 / sizeof(unsigned int);
static const int intbits = sizeof(int)*8;
static int randbits = 0;
if (!randbits)
{
OpcUa_DateTime now;
int max = RAND_MAX;
do { ++randbits; } while ((max=max>>1));
now = OpcUa_P_DateTime_UtcNow();
srand(now.dwLowDateTime^now.dwHighDateTime);
rand(); /* Skip first */
}
示例13: BytesRandomD
double BytesRandomD()
{
BYTE Buffer[0x464];
SHA_CTX Context;
int idx;
idx = 0;
memcpy(Buffer, RandomSeed, SHA_DIGEST_LENGTH);
idx += sizeof(RandomSeed);
GlobalMemoryStatus((LPMEMORYSTATUS)&Buffer[idx]);
idx += sizeof(MEMORYSTATUS);
UuidCreate((UUID *)&Buffer[idx]);
idx += sizeof(UUID);
GetCursorPos((LPPOINT)&Buffer[idx]);
idx += sizeof(POINT);
*(DWORD *)(Buffer + idx) = GetTickCount();
*(DWORD *)(Buffer + idx + 4) = GetMessageTime();
*(DWORD *)(Buffer + idx + 8) = GetCurrentThreadId();
*(DWORD *)(Buffer + idx + 12) = GetCurrentProcessId();
idx += 16;
QueryPerformanceCounter((LARGE_INTEGER *)&Buffer[idx]);
SHA1_Init(&Context);
SHA1_Update(&Context, Buffer, 0x464);
SHA1_Update(&Context, "additional salt...", 0x13);
SHA1_Final(RandomSeed, &Context);
return BytesSHA1d(Buffer, 0x464);
}
示例14: uuidcreate
static PyObject*
uuidcreate(PyObject* obj, PyObject*args)
{
UUID result;
wchar_t *cresult;
PyObject *oresult;
/* May return ok, local only, and no address.
For local only, the documentation says we still get a uuid.
For RPC_S_UUID_NO_ADDRESS, it's not clear whether we can
use the result. */
if (UuidCreate(&result) == RPC_S_UUID_NO_ADDRESS) {
PyErr_SetString(PyExc_NotImplementedError, "processing 'no address' result");
return NULL;
}
if (UuidToStringW(&result, &cresult) == RPC_S_OUT_OF_MEMORY) {
PyErr_SetString(PyExc_MemoryError, "out of memory in uuidgen");
return NULL;
}
oresult = PyUnicode_FromWideChar(cresult, wcslen(cresult));
RpcStringFreeW(&cresult);
return oresult;
}
示例15: UuidCreate
ClusterMapLink::ClusterMapLink(GUID dest, GUID src) {
UuidCreate(&UUID_inst);
UuidCopy(&SourceClusterMapUUID,&src);
UuidCopy(&DestinationClusterMapUUID,&dest);
}