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.
TaskDialogIndirect displays chinese text on expanded form
![](https://techprofile.blob.core.windows.net/images/SIU9LlAzpEep5CQxUaYhZw.png?8DB221)
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)
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:
Expanded state (the problem):
How do I solve this?
Accepted answer
2 additional answers
Sort by: Most helpful
-
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.
-
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