Trying to create a guid in C++ from my code
-
I used a GUID to represent a portion of a unique file name do my file looked like: myfilename_GUID.txt In C# i just do String strRandomName = System.Guid.NewGuid().ToString(); However, what do i do in C++?
LCI wrote:
However, what do i do in C++?
What's the problem? You previously stated that, "I used a GUID to represent a portion of a unique file name...", so did that work?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I used a GUID to represent a portion of a unique file name do my file looked like: myfilename_GUID.txt In C# i just do String strRandomName = System.Guid.NewGuid().ToString(); However, what do i do in C++?
LCI wrote:
However, what do i do in C++?
They hid it in the documentation. Those Bastards! The secret lies in searching the MSDN for "GUID" and "creating". ;P But maybe what you want is just
::tmpfile()
or ::tempnam()
fromstdio.h
?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
LCI wrote:
However, what do i do in C++?
What's the problem? You previously stated that, "I used a GUID to represent a portion of a unique file name...", so did that work?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
He created the GUID in C# and he wants to know how to do the same thing in C++.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
LCI wrote:
However, what do i do in C++?
They hid it in the documentation. Those Bastards! The secret lies in searching the MSDN for "GUID" and "creating". ;P But maybe what you want is just
::tmpfile()
or ::tempnam()
fromstdio.h
?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"#if (defined(__unix__) || defined(unix)) && !defined(USG) #include #endif #include #include #if defined(_WIN32) || defined(__CYGWIN__) #include #elif defined MACOSX #include #include #elif defined __FreeBSD__ # if __FreeBSD_version >= 500000 # include # else # error FreeBSD versions prior to 500000 does not support uuid(3) # endif #else #include #endif ///Above are my includes, below is the calls abstracted #if defined(_WIN32) || defined(__CYGWIN__) GUID randomGuid; // create random GUID randomGuid = GUID_NULL; ::CoCreateGuid(&randomGuid); if (randomGuid == GUID_NULL) { fprintf(stderr,"Couldn't create a random GUID\n"); return; } memcpy(m_bufuid, &randomGuid, 16); #elif defined __FreeBSD__ uuid_t uid; // uuid_t is a struct uuid_create(&uid, NULL); memcpy(m_bufuid, &uid, 16); #else uuid_t uid; // uuid_t is defined as unsigned char[16] uuid_generate(uid); memcpy(m_bufuid, uid, 16); #endif std::string tmp; char cuid[100]; // Uid::GetUid temporary sprintf(cuid,"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", m_bufuid[0],m_bufuid[1],m_bufuid[2],m_bufuid[3], m_bufuid[4],m_bufuid[5],m_bufuid[6],m_bufuid[7], m_bufuid[8],m_bufuid[9],m_bufuid[10],m_bufuid[11], m_bufuid[12],m_bufuid[13],m_bufuid[14],m_bufuid[15]); tmp = cuid; Done. -- modified at 8:48 Wednesday 31st October, 2007
-
#if (defined(__unix__) || defined(unix)) && !defined(USG) #include #endif #include #include #if defined(_WIN32) || defined(__CYGWIN__) #include #elif defined MACOSX #include #include #elif defined __FreeBSD__ # if __FreeBSD_version >= 500000 # include # else # error FreeBSD versions prior to 500000 does not support uuid(3) # endif #else #include #endif ///Above are my includes, below is the calls abstracted #if defined(_WIN32) || defined(__CYGWIN__) GUID randomGuid; // create random GUID randomGuid = GUID_NULL; ::CoCreateGuid(&randomGuid); if (randomGuid == GUID_NULL) { fprintf(stderr,"Couldn't create a random GUID\n"); return; } memcpy(m_bufuid, &randomGuid, 16); #elif defined __FreeBSD__ uuid_t uid; // uuid_t is a struct uuid_create(&uid, NULL); memcpy(m_bufuid, &uid, 16); #else uuid_t uid; // uuid_t is defined as unsigned char[16] uuid_generate(uid); memcpy(m_bufuid, uid, 16); #endif std::string tmp; char cuid[100]; // Uid::GetUid temporary sprintf(cuid,"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", m_bufuid[0],m_bufuid[1],m_bufuid[2],m_bufuid[3], m_bufuid[4],m_bufuid[5],m_bufuid[6],m_bufuid[7], m_bufuid[8],m_bufuid[9],m_bufuid[10],m_bufuid[11], m_bufuid[12],m_bufuid[13],m_bufuid[14],m_bufuid[15]); tmp = cuid; Done. -- modified at 8:48 Wednesday 31st October, 2007
Hey! I did not ask! Anyway, your code is missing the m_bufuid declaration.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
Hey! I did not ask! Anyway, your code is missing the m_bufuid declaration.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"I pressed reply! Sorry it got pasted under you! That buffer is simply a char[16] buffer.