C + +: Get a Globally unique identification number (GUID or UUID) in your program

Source: Internet
Author: User
Tags 04x

Windows: Using the CoCreateGuid function (GUID)
#include <stdio.h>#defineGuid_len 64intMainintargcChar*argv[]) {      CharBuffer[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: Using the Uuid_generate function (UUID)

Compile command: gcc atemp.c-o atemp-luuid

#include <uuid/uuid.h>    int  main ()  {      uuid_t uu;       int i;      Uuid_generate (UU);          for (i=0;i<; i++)      {          printf ("%02x-", Uu[i]);      }      printf ("\ n")      ; return 0 ;  }

C + +: Get a Globally unique identification number (GUID or UUID) in your program

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.