Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Trying to create a guid in C++ from my code

Trying to create a guid in C++ from my code

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++question
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LCI
    wrote on last edited by
    #1

    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++?

    D J 2 Replies Last reply
    0
    • L LCI

      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++?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • L LCI

        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++?

        J Offline
        J Offline
        jhwurmbach
        wrote on last edited by
        #3

        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() from stdio.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"

        K 1 Reply Last reply
        0
        • D David Crow

          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

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • J jhwurmbach

            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() from stdio.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"

            K Offline
            K Offline
            KenThompson
            wrote on last edited by
            #5

            #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

            J 1 Reply Last reply
            0
            • K KenThompson

              #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

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #6

              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"

              K 1 Reply Last reply
              0
              • J jhwurmbach

                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"

                K Offline
                K Offline
                KenThompson
                wrote on last edited by
                #7

                I pressed reply! Sorry it got pasted under you! That buffer is simply a char[16] buffer.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups