CFBundleCopyExecutableURL関数は、絶対URLを返す場合と、返さない場合があります。CFBundleCopyExecutableURLの前にCFBundleCopyExecutableArchitecturesを呼び出すと、URLは絶対になります(なぜですか?)。この関数を強制して常に絶対URLを返すにはどうすればよいですか?ありがとう。
text getBundleExeutableUrl(text bundlePath)
{
CFURLRef url = CFURLCreateFromFileSystemRepresentation(0,
(char*)bundlePath.c_str(), bundlePath.length(), false);
CFBundleRef bundle = CFBundleCreate(0, url);
CFBundleCopyExecutableArchitectures(bundle); // this is necessary to get absolute path
CFURLRef exeUrl = CFBundleCopyExecutableURL(bundle);
CFStringRef srExe = CFURLCopyFileSystemPath(exeUrl, 0);
text bundleExe = srExe;
CFRelease(srExe);
CFRelease(exeUrl);
CFRelease(url);
CFRelease(bundle);
return bundleExe;
}