【问题标题】:How to convert CFString to HFSUniStr255?如何将 CFString 转换为 HFSUniStr255?
【发布时间】:2014-09-14 14:33:06
【问题描述】:

首先,这与古代技术有关。我正在开发的程序端口在 Metrowerks Codewarrior 9 中维护,目标是 PPC。

用于 MSL C 的 FSRefParentAndFilename_fopen 函数

FILE * FSRefParentAndFilename_fopen(
const FSRefPtr theParentRef,
ConstHFSUniStr255Param theName,
const char *open_mode);

我需要一个 ConstHFSUniStr255Param,它是一个指向 HFSUniStr255 的指针。 我有一个包含我的文件名的 CFString,我的问题是如何转换为 HFSUniStr255?

struct HFSUniStr255 {
UInt16 length;
UniChar unicode[255];
};

到目前为止我有:

HFSUniStr255 HFSString;
FSGetDataForkName(&HFSString);
HFSString.length=(uint16)CFStringGetLength(fileName);
HFSString.unicode=?

【问题讨论】:

    标签: c++ c macos macos-carbon codewarrior


    【解决方案1】:

    你可以使用下面的sn-p:

    HFSString.length=(uint16)CFStringGetLength(fileName);
    CFStringGetCharacters(filename, CFRangeMake(0, CFStringGetLength(filename)), HFSString.unicode);
    

    但请确保您的文件名有效,尤其是其长度小于 255 个 Unicode 字符。否则你将不得不面对缓冲区溢出的后果。

    【讨论】:

      猜你喜欢
      • 2015-10-28
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多