C ++: Obtain the Globally Unique ID (GUID or UUID) in the program)

Source: Internet
Author: User

Windows: Use the CoCreateGuid function (GUID) [cpp] # include <objbase. h> # include <stdio. h> # define GUID_LEN 64 int main (int argc, char * argv []) {char buffer [GUID_LEN] = {0}; GUID guid; if (CoCreateGuid (& guid )) {fprintf (stderr, "create guid error \ n"); return-1;} _ snprintf (buffer, sizeof (buffer ), "% 08X-% 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]); printf ("guid: % s \ n", buffer); return 0;} Linux: Use uuid_generate function (UUID) [cpp] // compile command: gcc atemp. c-o atemp-luuid # include <stdio. h> # include <uuid/uuid. h> int main () {uid_t uu; int I; uuid_generate (uu); for (I = 0; I <16; I ++) {printf ("% 02X-", uu [I]);} printf ("\ n"); return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.