How to Get Program Creator?

How do I get my program's creator ID programmatically?

Use this function:

 

            UInt32 GetCreatorID(void)
{
static UInt32 nCreatorID = 0;

if (nCreatorID == 0) {
UInt16 nCard;
LocalID LocalDB;
Err err;

err = SysCurAppDatabase(&nCard, &LocalDB);
ErrFatalDisplayIf(err, "Could not get current app database.");
err = DmDatabaseInfo(nCard, LocalDB, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, &nCreatorID);
ErrFatalDisplayIf(err, "Could not get app database info, looking for creator ID");
}

return nCreatorID;
}
You can use this function to make your code more failsafe: you can change the creator ID in one place, within your build environment, without having to change it throughout your code. Your code will need to know the creator ID for any of several purposes, such as when accessing a database or its saved preferences block.

18 Feb 2003

Original code wasn't safe as ErrFatalDisplayIf? is compiled out completely when not building a debug target. This would mean the function would compile down to an empty block! Corrected by assigning results of functions to a temporary.

It's also worth noting that this uses a global, so it isn't safe in notifications. To get a version that's safe with notifications, take out the static keyword. Of Down side is that'll cause GetCreatorID? to have to do the work every time it is called instead of just once.

Today: Sep 10, 2010