PDA

View Full Version : C++ Bundle path




kcjones
Sep 14, 2008, 11:18 PM
Hey Everyone,

My question is how do I get the bundle path in c++. Something similar to:

[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]

How do I get the full path of a resource in the Application bundle in char[].

Thanks for your help!



kcjones
Sep 14, 2008, 11:29 PM
Ok I've now got:


CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);

CFShow(resourcesURL); // prints full bundle path to console

CFRelease(resourcesURL);



How do I get the resourcesURL to a string and append something to it?

kcjones
Sep 14, 2008, 11:54 PM
Don't worry about it I got it:


CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle );
CFRelease(resourcesURL);
char path[PATH_MAX];

CFStringGetCString( str, path, FILENAME_MAX, kCFStringEncodingASCII );
CFRelease(str);
fprintf(stderr, path);