In 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:
The documentation for CFString states: "in a method where you see an
NSString * parameter, you can pass in a
CFStringRef" 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.