At 9:51 PM +0100 2/5/09, Jonas Maebe apparently wrote: >On 05 Feb 2009, at 21:29, Ken G. Brown wrote: > >>So far I have the following external definitions: > >All external definitions you need are already in the MacOSAll unit shipped >with FPC. > >>Function CFStringGetFileSystemRepresentation(myPathString : CFStringRef; >>buffer : ppchar; maxBufLen : CFIndex) : Boolean; cdecl; External; >>Function _CFStringGetFileSystemRepresentation(myPathString : CFStringRef; >>buffer : ppchar; maxBufLen : CFIndex) : Boolean; C; External; >> >>Function CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : >>CFStringRef) : CFIndex; cdecl; External; >>Function _CFStringGetMaximumSizeOfFileSystemRepresentation(myPathStr2 : >>CFStringRef) : CFIndex; C; External; >> >>Function CFBundleGetMainBundle() : CFBundleRef; cdecl; External; >>Function _CFBundleGetMainBundle() : CFBundleRef; C; External; > >The ones with the extra underscore don't exist. > >>and the following snippet >> >>var >> success : boolean = false; >> mainBundle : CFBundleRef; >> bundlePath : CFURLRef; >> bundlePathStr : CFStringRef; >> myBundlePathStr : ppchar; > >myBundlePathStr has to be a pchar; > >>begin >> >> >>// Get the main bundle for the app >> mainBundle := CFBundleGetMainBundle(); >> bundlePath := CFBundleCopyBundleURL(mainBundle); >> >> bundlePathStr := CFURLCopyFileSystemPath (bundlePath, >> kCFURLPOSIXPathStyle); >> >> >>success := CFStringGetFileSystemRepresentation (bundlePathStr, >>myBundlePathStr, >>CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); >> >>I'm not quite sure if I am doing the 2nd arg correctly, it's supposed to be >>char *buffer. >> >>Does this look alright? If not, what should I be using for the >>myBundlePathString type? > >You have to allocate memory for it. Something like > >myBundlePathStr:=getmem(CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr)); >success := CFStringGetFileSystemRepresentation (bundlePathStr, >myBundlePathStr, >CFStringGetMaximumSizeOfFileSystemRepresentation(bundlePathStr));
Ah! Sweet! I'm getting the path! Now all that's left is to get the path without the app name and add my filename! :) Thank you Sir! Ken >When interfacing with C routines, you have to do the same things as if you >were using C. > >>And I notice that CFStringGetFileSystemRepresentation is only available for >>10.4 and newer. What do i need to do instead if wanting to deploy to 10.3.9? > >Call CFStringGetCStringPtr and/or CFStringGetCStringPtr and tell it to convert >to utf-8 (kCFStringEncodingUTF8). > > >Jonas >_______________________________________________ >fpc-pascal maillist - fpc-pascal@lists.freepascal.org >http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal