-
Working with Pascal Strings in Cocoa
Posted on August 23rd, 2007 2 commentsIn trying to access information from a quicktime file I came across my first pascal string (pstring). Trying to copy this string using strncpy or NSString:stringWithCString did not work so I looked at the memory and saw a number as the first byte. I recognized this as a pascal string so I searched on conversion from pstring to NSString and found this:
http://www.omnigroup.com/mailman/archive/macosx-dev/2001-August/030492.html
http://developer.apple.com/documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html#//apple_ref/c/func/CFStringCreateWithPascalStringThe documentation for CFString states: "in a method where you see an
NSString *parameter, you can pass in aCFStringRef" but the compiler complained so as in the example code linked above, I resorted to using the NSString:stringWithFormat. My first thought was to simply use NSString:stringWithString.Here is the wrapper function I came up with:
-(NSString*)NSStringFromPString:(unsigned char*) pstring
{
CFStringRef strRef = CFStringCreateWithPascalString (NULL, pstring, kCFStringEncodingMacRoman);
return [NSString stringWithFormat:@"%@",strRef];
}Update 8/24/07: It seems the error when using stringWithString has something to do with what source is being compiled. If it is in an .mm file (enables C++ compatibility?) I get the error:
error: cannot convert ‘const __CFString*’ to ‘NSString*’ in argument passing
but if compiled in an .m file it works fine. It appears that in the former case, the compiler is being stricter, though a forced cast will eliminate the error message.
-
Mac Documentation, not so good
Posted on August 23rd, 2007 No commentsI’ve given the Development Documentation for XCode a few weeks, but yesterday, after spending half a day searching how to retrieve the Codec information from a quicktime file, I finally concluded that the best source of documentation is source code on the web. With the lack of examples the documentation is only of minimal help when you are new and trying to discover HOW to do things, not just reference information.
Two sites helpful in searching code are Krugle and Koder. Krugle has a nicer UI. I haven’t used Koder much.


