Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Path to Shared Library?



Oh, I know the answer to this one. You can make it return the URL or bundle instead. All I cared about was the executable name.

static CFStringRef CopyForestName(void)
{
CFStringRef forestName=NULL;
Dl_info info;
if (dladdr(CopyForestName, &info))
{
const char * libraryName = info.dli_fname;
if (libraryName)
{
CFURLRef url=CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)libraryName, strlen(libraryName), false);
if (url)
{
CFURLRef macOSFolder=CFURLCreateCopyDeletingLastPathComponent(NULL,url);
if (macOSFolder)
{
CFURLRef contents=CFURLCreateCopyDeletingLastPathComponent(NULL, macOSFolder);
if (contents)
{
CFURLRef bundleURL=CFURLCreateCopyDeletingLastPathComponent(NULL, contents);
if (bundleURL)
{
CFBundleRef bundle=CFBundleCreate(NULL, bundleURL);
if (bundle)
{


forestName=CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleNameKey);
if (forestName)
CFRetain(forestName);
CFRelease(bundle);
}
}
CFRelease(contents);
}
CFRelease(macOSFolder);
}
CFRelease(url);
}
}
}
return forestName;
}




Ack, at 5/30/06, Ben Weiss said:

How can my shared library discover its own location on disk at runtime?

I can get the path to the host application (using GetProcessBundleLocation()), but the relative path from the application to the library may not be constant. (The shared may be used by several applications, for which the relative paths may be different.) Any ideas how I can this?

--


Sincerely, Rosyna Keller Technical Support/Holy Knight/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People

It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Path to Shared Library? (From: Ben Weiss <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.