Created
January 19, 2023 00:53
-
-
Save uemuraj/ba8346d3a4fe1a5cc43435bde15e79cd to your computer and use it in GitHub Desktop.
wsprintf の最大文字数。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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