TaskDialogIndirect displays chinese text on expanded form

Ahmed Osama 120 Reputation points

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


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

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

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.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


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
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

    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

    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

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