Here’s what I did (almost all plain Carbon code) in an old AU plugin (still working today) that I developed when I still was using my own cross platform framework: CPL.
I’m sure you’ll be able to get the sense and maybe to add that to your great toolkit.
(cpl::MString objects were my string classes, cpl::MApplicationImpl was the class doing the implementation for a bridged Application class abstracted from the OSs).
cpl::MString MApplicationImpl::GetAppOSFullPath()
{
cpl::MString strPath;
CFStringRef cfstrBundleIdentifier = CFStringCreateWithCString(NULL,m_pAbstraction->GetBundleIdentifier().c_str(),kCFStringEncodingUTF8);
if (!cfstrBundleIdentifier)
{
// We have to define a bundle identifier into the Info.plist file, or the system is not able to reach the path of this bundle
return strPath;
}
CFBundleRef cfbThisBundle = CFBundleGetBundleWithIdentifier(cfstrBundleIdentifier);
CFRelease(cfstrBundleIdentifier);
if (!cfbThisBundle)
{
// The identifier typed-in in the source code (at application initialization, presumably) does not
// correspond to the Info.plist bundle identifier
return strPath;
}
CFURLRef cfuExecutable = CFBundleCopyExecutableURL(cfbThisBundle);
if (!cfuExecutable)
{
// Cannot get executable's URL (we have to define the executable name into the Info.plist file)
return strPath;
}
CFStringRef cfstrFullPath = CFURLCopyFileSystemPath(cfuExecutable, kCFURLPOSIXPathStyle);
if (!cfstrFullPath)
{
// Something wrong while allocating CFString? ...
return strPath;
}
CFIndex nSize = CFStringGetLength(cfstrFullPath) + 1;
char* szPath = new char[nSize];
CFStringGetCString(cfstrFullPath, szPath, nSize, CFStringGetSystemEncoding());
CFRelease(cfstrFullPath);
strPath = cpl::MString(szPath);
delete [] szPath;
return strPath;
}