Skip to content

Commit

Permalink
win32_utf8: Add DrawText.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlgc committed Aug 25, 2013
1 parent 1fc959f commit 78d562c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion thcrap/src/win32_patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ void win32_patch(HMODULE hMod)
"GetTextExtentPoint32A", GetTextExtentPoint32U
);

iat_patch_funcs_var(hMod, "user32.dll", 9,
iat_patch_funcs_var(hMod, "user32.dll", 10,
"CharNextA", CharNextU,
"CreateDialogParamA", CreateDialogParamU,
"CreateWindowExA", CreateWindowExU,
// Yep, both original functions use the same parameters
"DefWindowProcA", DefWindowProcW,
"DialogBoxParamA", DialogBoxParamU,
"DrawTextA", DrawTextU,
"MessageBoxA", MessageBoxU,
"RegisterClassA", RegisterClassU,
"RegisterClassExA", RegisterClassExU,
Expand Down
10 changes: 2 additions & 8 deletions win32_utf8/src/gdi32_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ BOOL APIENTRY GetTextExtentPoint32U(
)
{
BOOL ret;
size_t lpString_len = c + 1;
VLA(wchar_t, lpString_w, lpString_len);
ZeroMemory(lpString_w, lpString_len * sizeof(wchar_t));
StringToUTF16(lpString_w, lpString, c);
FixedLengthStringConvert(lpString, c);
ret = GetTextExtentPoint32W(hdc, lpString_w, wcslen(lpString_w), psizl);
VLA_FREE(lpString_w);
return ret;
Expand All @@ -63,10 +60,7 @@ BOOL WINAPI TextOutU(
)
{
BOOL ret;
size_t lpString_len = c + 1;
VLA(wchar_t, lpString_w, lpString_len);
ZeroMemory(lpString_w, lpString_len * sizeof(wchar_t));
StringToUTF16(lpString_w, lpString, c);
FixedLengthStringConvert(lpString, c);
ret = TextOutW(hdc, x, y, lpString_w, wcslen(lpString_w));
VLA_FREE(lpString_w);
return ret;
Expand Down
8 changes: 8 additions & 0 deletions win32_utf8/src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,11 @@

// Our strlen has error-checking!
#define strlen(s) (s ? strlen(s) : 0)

// Convenience macro to convert one fixed-length string to UTF-16.
// TODO: place this somewhere else?
#define FixedLengthStringConvert(str_in, str_len) \
size_t str_in##_len = (str_len != -1 ? str_len : strlen(str_in)) + 1; \
VLA(wchar_t, str_in##_w, str_in##_len); \
ZeroMemory(str_in##_w, str_in##_len * sizeof(wchar_t)); \
StringToUTF16(str_in##_w, str_in, str_len);
15 changes: 15 additions & 0 deletions win32_utf8/src/user32_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ INT_PTR WINAPI DialogBoxParamU(
return DialogBoxParamW(hInstance, lptn_w, hWndParent, lpDialogFunc, dwInitParam);
}

int WINAPI DrawTextU(
__in HDC hdc,
__inout_ecount_opt(cchText) LPCSTR lpchText,
__in int cchText,
__inout LPRECT lprc,
__in UINT format
)
{
int ret;
FixedLengthStringConvert(lpchText, cchText);
ret = DrawTextW(hdc, lpchText_w, wcslen(lpchText_w) + 1, lprc, format);
VLA_FREE(lpchText_w);
return ret;
}

int WINAPI MessageBoxU(
__in_opt HWND hWnd,
__in_opt LPCSTR lpText,
Expand Down
10 changes: 10 additions & 0 deletions win32_utf8/src/user32_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ INT_PTR WINAPI DialogBoxParamU(
#undef DialogBoxParam
#define DialogBoxParam DialogBoxParamU

int WINAPI DrawTextU(
__in HDC hdc,
__inout_ecount_opt(cchText) LPCSTR lpchText,
__in int cchText,
__inout LPRECT lprc,
__in UINT format
);
#undef DrawText
#define DrawText DrawTextU

int WINAPI MessageBoxU(
__in_opt HWND hWnd,
__in_opt LPCSTR lpText,
Expand Down
1 change: 1 addition & 0 deletions win32_utf8/win32_utf8.def
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ EXPORTS
CreateDialogParamU
CreateWindowExU
DialogBoxParamU
DrawTextU
MessageBoxU
RegisterClassU
RegisterClassExU
Expand Down

0 comments on commit 78d562c

Please sign in to comment.