TaskDialogIndirect displays chinese text on expanded form

Ahmed Osama 120 Reputation points
2023-03-02T14:29:54.71+00:00

Hi, I'm having a problem with TaskDialogIndirect displaying chinese text on the footer when expanding the control (i use TDF_EXPAND_FOOTER_AREA)

Code:

#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")

#if defined _M_IX86
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else

char buf[9];
                sprintf(&buf[0], "%08x", (int)GetLastError());
                std::string res(&buf[0]);
                DWORD le = GetLastError();
                std::string message = (std::string)"APC Administrative Application Execution Utility encountured an error of code 0x" + res + ": " + "\"" + std::system_category().message(GetLastError()); +"\"";
                int lastError = GetLastError();
                std::wstring hexerror = L"0x" + WCHAR(DecToHex(GetLastError()));
                const char* HEs = message.c_str();
                _TASKDIALOGCONFIG tdc = { sizeof(_TASKDIALOGCONFIG) };
                TASKDIALOG_BUTTON buttons[] = {
                    { 1000, L"&Accept" },
                    { 1001, L"&Close" }
                };
                LPCWSTR szTitle = L"APC Administrative Application Execution Utility";
                LPCWSTR szHeader = L"An error has occured";
                LPCWSTR szBodyText = L"APC Administrative Application Execution Utility encountured an error, verify input to make sure it's correct";;
                int btc;
                tdc.pszExpandedInformation = (LPCWSTR)message.c_str();
                tdc.pszMainIcon = IDI_ERROR;
                tdc.hwndParent = hWnd;
                tdc.dwFlags = TDF_CAN_BE_MINIMIZED | TDF_ALLOW_DIALOG_CANCELLATION | TDF_EXPAND_FOOTER_AREA;
                tdc.cButtons = _countof(buttons);
                tdc.pButtons = buttons;
                tdc.pszWindowTitle = szTitle;
                tdc.pszMainInstruction = szHeader;
                tdc.pszContent = szBodyText;

                TaskDialogIndirect(&tdc, &btc, NULL, NULL);

Which results in the following (that code is in this block:

if (GetLastError() != 0) {
// the code
}

Images:

User's image

Expanded state (the problem):

User's image

How do I solve this?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,412 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,520 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,271 Reputation points
    2023-03-02T14:50:59.6966667+00:00

    You cannot cast narrow strings to LPCWSTR. Instead of using std::string use std::wstring for your message variable. And use a UNICODE string literal when initializing it.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. David Lowndes 4,711 Reputation points
    2023-03-02T14:57:02.4766667+00:00

    You've got a cast here that's a red-herring:
    tdc.pszExpandedInformation = (LPCWSTR)message.c_str();

    Remove the cast (remove them all ideally), change message to be std::wstring and alter code appropriately.


  2. Ahmed Osama 120 Reputation points
    2023-03-02T15:17:26.26+00:00

    You can cast narrow types to LPCWSTR (wide) you can put a narroiw thing in a wide thing