Skip to content

Instantly share code, notes, and snippets.

@uemuraj
Created January 19, 2023 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uemuraj/ba8346d3a4fe1a5cc43435bde15e79cd to your computer and use it in GitHub Desktop.
Save uemuraj/ba8346d3a4fe1a5cc43435bde15e79cd to your computer and use it in GitHub Desktop.
wsprintf の最大文字数。
#include "pch.h"
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#include <algorithm>
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-wsprintfw
//
// * 1,024 bytes と記載されているが文字数の誤りと思われる
// * バッファサイズの指定は無いが 1,025 文字まで使用し、終端文字を書き込む
//
TEST(TestCaseName, TestName)
{
wchar_t buf[1024 + 1];
std::fill(std::begin(buf), std::end(buf), L'a');
wchar_t wcs[1024 + 1];
std::fill(std::begin(wcs), std::end(wcs), L'b');
EXPECT_EQ(buf[1023], L'a');
EXPECT_EQ(buf[1024], L'a');
::wsprintfW(buf, L"%s", wcs);
EXPECT_EQ(buf[1023], L'b');
EXPECT_EQ(buf[1024], L'\0');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment