< Previous PageNext Page > Hide TOC

Generating a UUID Programmatically

Listing 1 shows you how to generate a UUID programmatically using CFUUID functions. Plug-ins use UUIDs to uniquely identify types, interfaces, and factories.

Listing 1  Generating a UUID programmatically

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, strBuffer, 100, kCFStringEncodingASCII);
 
CFStringRef outputString =
    CFStringCreateWithFormat(kCFAllocatorDefault,
                             NULL,
                             CFSTR("My UUID is: %s!\n"),
                             strBuffer);
CFShow(outputString);


< Previous PageNext Page > Hide TOC


© 2003, 2005 Apple Computer, Inc. All Rights Reserved. (Last updated: 2005-03-03)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.