C++ 如何将CFString转换为HFSUniStr255?
首先,这与古代技术有关。我正在使用的程序端口在Metrowerks Codewarrior 9中维护,目标是PPC 用于MSL C的FSRefParentAndFilename\u fopen函数C++ 如何将CFString转换为HFSUniStr255?,c++,c,macos,macos-carbon,codewarrior,C++,C,Macos,Macos Carbon,Codewarrior,首先,这与古代技术有关。我正在使用的程序端口在Metrowerks Codewarrior 9中维护,目标是PPC 用于MSL C的FSRefParentAndFilename\u fopen函数 FILE * FSRefParentAndFilename_fopen( const FSRefPtr theParentRef, ConstHFSUniStr255Param theName, const char *open_mode); 我需要一个consthfsunistr255参数,它是指
FILE * FSRefParentAndFilename_fopen(
const FSRefPtr theParentRef,
ConstHFSUniStr255Param theName,
const char *open_mode);
我需要一个consthfsunistr255参数,它是指向HFSUniStr255的指针。
我有一个包含文件名的CFString,我的问题是如何转换为HFSUniStr255
struct HFSUniStr255 {
UInt16 length;
UniChar unicode[255];
};
到目前为止,我已经:
HFSUniStr255 HFSString;
FSGetDataForkName(&HFSString);
HFSString.length=(uint16)CFStringGetLength(fileName);
HFSString.unicode=?
您可以使用以下代码段:
HFSString.length=(uint16)CFStringGetLength(fileName);
CFStringGetCharacters(filename, CFRangeMake(0, CFStringGetLength(filename)), HFSString.unicode);
但是,请确保文件名有效,尤其是其长度小于255个Unicode字符。否则,您将不得不面对缓冲区溢出的后果