Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ FormatMessage中是否有明确的大小限制?_C++_C_Winapi - Fatal编程技术网

C++ FormatMessage中是否有明确的大小限制?

C++ FormatMessage中是否有明确的大小限制?,c++,c,winapi,C++,C,Winapi,当传递给FormatMessage的参数太长时,我遇到了一个问题 void testMessage(UINT id, ...) { va_list argList; va_start(argList, id); LPTSTR buff = NULL; const char* str = "The following value is invalid: %1"; DWORD success = FormatMessage(FORMAT_MESSAGE_

当传递给
FormatMessage
的参数太长时,我遇到了一个问题

void testMessage(UINT id, ...)
{
    va_list argList;
    va_start(argList, id);

    LPTSTR buff = NULL;

    const char* str = "The following value is invalid: %1";

    DWORD success = FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER,
           str, 0, 0, (LPSTR) &buff, 0, &argList);

    if(0 == success)
    {
       DWORD err = GetLastError();

       //...
    }

    va_end(argList);

    //...
 }

 int main(int argc, char** argv)
 {
    const char* arg = NULL;

    // ...
    // Initialize arg to some big string about 33,000 bytes long.
    // ...

    test(0, arg);
 }
我得到的错误是
error\u MORE\u DATA
(234)。当我将
arg
的大小减少到32000字节左右时,问题没有出现,但不清楚限制是否与传入参数的大小或生成的字符串的总大小有关。on
FormatMessage
中提到了
lpBuffer
参数,“此缓冲区不能大于64K字节。”


我可以通过执行更多的错误检查并对传入该函数的参数的大小设置一些合理的限制来轻松解决这个问题,但对于我和其他人的将来参考,最好知道真正的限制是什么。

您是在调用
FormatMessageA
还是
FormateMessageW
?如果调用
FormatMessageA
,32K ASCII消息将被编组为64K Unicode消息。今天的Windows内部使用Unicode,“A”系列函数只是“W”函数的包装。

啊,我想我是在调用FormatMessageA,因为我没有定义Unicode宏。这听起来像是一种解释。谢谢