0

I am trying to convert previous code to VS 2010. The code I am trying to convert is mentioned below. The function addCommand is defined like

addCommand(const ACHAR * cmdGroupName,  const ACHAR * cmdGlobalName, const ACHAR * cmdLocalName, Adesk::Int32 commandFlags, AcRxFunctionPtr FunctionAddr,AcEdUIContext *UIContext=NULL,  int fcode=-1,  HINSTANCE hResourceHandle=NULL,  AcEdCommand** cmdPtrRet=NULL)

The third required argument is of type ACHAR. The function is called in the following way.

char cmdLocRes[65];

// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {

    // Load strings from the string table and register the command.
    ::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
    acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);

My problem is that the variable cmdLocRes is of type char but the argument needs to be of type ACHAR.

How can I convert the same ?

4

1 回答 1

0
  1. ACHAR 是 wchar_t 的 typedef(由 Autodesk 在文件 AdAChar.h 中制作)。所以问题是如何将 char 转换为 wchar_t。
  2. 在更广泛的背景下,这个问题是因为 unicode 的存在。Linux 和 Windows 程序员通常在相互不了解的情况下讨论它。因为我也不懂,所以无法解释。急切的海狸有一些线程:C++ wchar_t 和 wstrings 有什么“错误”?宽字符有哪些替代方法?
  3. 以下内容可能会让您了解如何转换它。
    // Convert char to wchar_t

    字符 cmdLocRes[65];

    // 备注:确保 cmdLocRes 包含元素!

    cmdLocRes[0] = 'A';

    cmdLocRes[1] = '\0';

    // 获取一个 wstringstream

    std::wstringstream str;

    // 将 char 数组写入 wstringstream

    str << cmdLocRes;

    // 从 wstringstream 中获取一个 wstring

    std::wstring wstr = str.str();

    // 从 wstring 中获取一个 wchar_t

    常量 wchar_t *chr1 = wstr.c_str();

    常量 ACHAR *chr2 = wstr.c_str(); // 我们看到 wchar_t == ACHAR!

  4. 最好考虑使用 wchar_t cmdLocRes[65] 而不是 char cmdLocRes[65]!

  5. 对不起代码风格,但这个文本字段是另一个很好的例子,说明如何不这样做。我花了更长的时间尝试格式化代码块(请看一下!!!)而不是写答案。耶稣!!!
于 2014-05-19T10:52:59.750 回答