6262
6363// / Detour chains
6464// / -------------
65+
6566W32U8_DETOUR_CHAIN_DEF (CreateDialogParam);
6667W32U8_DETOUR_CHAIN_DEF (DialogBoxParam);
68+
69+ typedef HWND WINAPI CreateDialogParamW_type (
70+ HINSTANCE hInstance,
71+ LPCWSTR lpTemplateName,
72+ HWND hWndParent,
73+ DLGPROC lpDialogFunc,
74+ LPARAM dwInitParam
75+ );
76+
77+ typedef INT_PTR WINAPI DialogBoxParamW_type (
78+ HINSTANCE hInstance,
79+ LPCWSTR lpTemplateName,
80+ HWND hWndParent,
81+ DLGPROC lpDialogFunc,
82+ LPARAM dwInitParam
83+ );
84+
85+ DETOUR_CHAIN_DEF (CreateDialogParamW);
86+ DETOUR_CHAIN_DEF (DialogBoxParamW);
87+
6788// / -------------
6889
6990// / Structures
@@ -439,32 +460,19 @@ size_t dialog_item_template_ex_build(BYTE *dst, const BYTE **src, dialog_adjust_
439460}
440461// / -----------------
441462
442- DLGTEMPLATE* dialog_translate (HINSTANCE hInstance, LPCSTR lpTemplateName )
463+ DLGTEMPLATE* dialog_translate_internal (LPCSTR lpTemplateName, HGLOBAL hDlg, size_t hDlg_len )
443464{
444465 void *dlg_out = NULL ;
445466 json_t *trans = NULL ;
446467 size_t dlg_name_len;
447468 const char *dlg_format = NULL ;
448- HRSRC hrsrc;
449- HGLOBAL hDlg;
450469 HGLOBAL hDlg_rep = NULL ;
451- size_t hDlg_len;
452-
453- if (!lpTemplateName) {
454- return NULL ;
455- }
456470
457- // MAKEINTRESOURCE(5) == RT_DIALOG. (The regular
458- // RT_DIALOG macro is subject to UNICODE.)
459- hrsrc = FindResourceA (hInstance, lpTemplateName, MAKEINTRESOURCEA (5 ));
460- hDlg = LoadResource (hInstance, hrsrc);
461- hDlg_len = SizeofResource (hInstance, hrsrc);
462-
463- if (!hDlg) {
471+ if (!lpTemplateName || !hDlg) {
464472 return NULL ;
465473 }
466474
467- if (HIWORD (lpTemplateName) != 0 ) {
475+ if (! IS_INTRESOURCE (lpTemplateName)) {
468476 dlg_name_len = strlen (lpTemplateName) + 1 ;
469477 dlg_format = " %s%s%s" ;
470478 } else {
@@ -528,6 +536,62 @@ DLGTEMPLATE* dialog_translate(HINSTANCE hInstance, LPCSTR lpTemplateName)
528536 return (DLGTEMPLATE *)dlg_out;
529537}
530538
539+ DLGTEMPLATE* dialog_translate (HINSTANCE hInstance, LPCSTR lpTemplateName)
540+ {
541+ HRSRC hrsrc = NULL ;
542+ HGLOBAL hDlg = NULL ;
543+ size_t hDlg_len;
544+
545+ if (!lpTemplateName) {
546+ return NULL ;
547+ }
548+
549+ // MAKEINTRESOURCE(5) == RT_DIALOG.
550+ hrsrc = FindResourceA (hInstance, lpTemplateName, MAKEINTRESOURCEA (5 ));
551+ hDlg = LoadResource (hInstance, hrsrc);
552+ hDlg_len = SizeofResource (hInstance, hrsrc);
553+
554+ if (!hDlg) {
555+ return NULL ;
556+ }
557+
558+ return dialog_translate_internal (lpTemplateName, hDlg, hDlg_len);
559+ }
560+
561+ DLGTEMPLATE* dialog_translatew (HINSTANCE hInstance, LPCWSTR lpTemplateName)
562+ {
563+ HRSRC hrsrc = NULL ;
564+ HGLOBAL hDlg = NULL ;
565+ size_t hDlg_len;
566+ DLGTEMPLATE *dlg_out = NULL ;
567+
568+ if (!lpTemplateName) {
569+ return NULL ;
570+ }
571+
572+ // MAKEINTRESOURCE(5) == RT_DIALOG.
573+ hrsrc = FindResourceW (hInstance, lpTemplateName, MAKEINTRESOURCEW (5 ));
574+ hDlg = LoadResource (hInstance, hrsrc);
575+ hDlg_len = SizeofResource (hInstance, hrsrc);
576+
577+ if (!hDlg) {
578+ return NULL ;
579+ }
580+
581+ if (!IS_INTRESOURCE (lpTemplateName)) {
582+ UTF8_DEC (lpTemplateName);
583+ UTF8_CONV (lpTemplateName);
584+ dlg_out = dialog_translate_internal (lpTemplateName_utf8, hDlg, hDlg_len);
585+ UTF8_FREE (lpTemplateName);
586+ }
587+ else {
588+ // Pass the integer as-is
589+ dlg_out = dialog_translate_internal ((LPCSTR)lpTemplateName, hDlg, hDlg_len);
590+ }
591+
592+ return dlg_out;
593+ }
594+
531595HWND WINAPI dialog_CreateDialogParamA (
532596 HINSTANCE hInstance,
533597 LPCSTR lpTemplateName,
@@ -551,6 +615,29 @@ HWND WINAPI dialog_CreateDialogParamA(
551615 return ret;
552616}
553617
618+ HWND WINAPI dialog_CreateDialogParamW (
619+ HINSTANCE hInstance,
620+ LPCWSTR lpTemplateName,
621+ HWND hWndParent,
622+ DLGPROC lpDialogFunc,
623+ LPARAM dwInitParam
624+ )
625+ {
626+ HWND ret;
627+ DLGTEMPLATE *dlg_trans = dialog_translatew (hInstance, lpTemplateName);
628+ if (dlg_trans) {
629+ ret = CreateDialogIndirectParamW (
630+ hInstance, dlg_trans, hWndParent, lpDialogFunc, dwInitParam
631+ );
632+ SAFE_FREE (dlg_trans);
633+ } else {
634+ ret = chain_CreateDialogParamW (
635+ hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam
636+ );
637+ }
638+ return ret;
639+ }
640+
554641INT_PTR WINAPI dialog_DialogBoxParamA (
555642 HINSTANCE hInstance,
556643 LPCSTR lpTemplateName,
@@ -574,13 +661,38 @@ INT_PTR WINAPI dialog_DialogBoxParamA(
574661 return ret;
575662}
576663
664+ INT_PTR WINAPI dialog_DialogBoxParamW (
665+ HINSTANCE hInstance,
666+ LPCWSTR lpTemplateName,
667+ HWND hWndParent,
668+ DLGPROC lpDialogFunc,
669+ LPARAM dwInitParam
670+ )
671+ {
672+ INT_PTR ret;
673+ DLGTEMPLATE *dlg_trans = dialog_translatew (hInstance, lpTemplateName);
674+ if (dlg_trans) {
675+ ret = DialogBoxIndirectParamW (
676+ hInstance, dlg_trans, hWndParent, lpDialogFunc, dwInitParam
677+ );
678+ SAFE_FREE (dlg_trans);
679+ } else {
680+ ret = chain_DialogBoxParamW (
681+ hInstance, lpTemplateName, hWndParent, lpDialogFunc, dwInitParam
682+ );
683+ }
684+ return ret;
685+ }
686+
577687extern " C" {
578688
579689TH_EXPORT void dialog_mod_detour (void )
580690{
581691 detour_chain (" user32.dll" , 1 ,
582692 " CreateDialogParamA" , dialog_CreateDialogParamA, &chain_CreateDialogParamU,
583693 " DialogBoxParamA" , dialog_DialogBoxParamA, &chain_DialogBoxParamU,
694+ " CreateDialogParamW" , dialog_CreateDialogParamW, &chain_CreateDialogParamW,
695+ " DialogBoxParamW" , dialog_DialogBoxParamW, &chain_DialogBoxParamW,
584696 NULL
585697 );
586698}
0 commit comments