- _vsnwprintf(Buffer, 256, Format, Parameters);
+
+#ifndef WIN2K_COMPLIANT
+ /*
+ * Retrieve the message length and if it is too long, allocate
+ * an auxiliary buffer; otherwise use the static buffer.
+ */
+ MsgLen = _vscwprintf(Format, Parameters) + 1; // NULL-terminated
+ if (MsgLen > sizeof(StaticBuffer)/sizeof(StaticBuffer[0]))
+ {
+ Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MsgLen * sizeof(WCHAR));
+ if (Buffer == NULL)
+ {
+ /* Allocation failed, use the static buffer and display a suitable error message */
+ Buffer = StaticBuffer;
+ Format = L"DisplayMessage()\nOriginal message is too long and allocating an auxiliary buffer failed.";
+ MsgLen = wcslen(Format);
+ }
+ }
+#else
+ MsgLen = sizeof(Buffer)/sizeof(Buffer[0]);
+#endif
+
+ /* Display the message */
+ _vsnwprintf(Buffer, MsgLen, Format, Parameters);