0

I am trying to to create a Task Dialog, using the TASKDIALOGCONFIG strucutre. My application uses Unicode. This is my code:

string error_text = get_error_text();
string error_code = get_error_code();

TASKDIALOGCONFIG tdc = { sizeof(TASKDIALOGCONFIG) };
tdc.dwCommonButtons = TDCBF_OK_BUTTON;
tdc.pszMainIcon = TD_ERROR_ICON;
tdc.pszWindowTitle = _T("Error");
tdc.pszContent = error_text.c_str(); /* of course this will give a 
                                        const char* instead of a wchar_t* */
tdc.pszExpandedInformation = error_code.c_str(); // here is the same thing
tdc.hwndParent = m_wndParent;

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

I have researched the problem a bit, but I haven't found a solution yet. Could anybody help me?

lost_in_the_source
  • 10,998
  • 9
  • 46
  • 75
Victor
  • 13,914
  • 19
  • 78
  • 147

1 Answers1

3

You have two options:

  1. Use ANSI text. Do so by using TASKDIALOGCONFIGA and TaskDialogIndirectA.
  2. Use Unicode text. Switch your strings from std::string to std::wstring.

I personally would recommend the latter option.

I would also recommend that you do not use tchar.h, and stop using _T(...). Since you are only targeting Unicode, you should write L"Error" rather than _T("Error"). It only makes sense to use tchar.h if you are writing code that must compile for both MBCS and Unicode targets. That was a necessary evil in the days when we needed to compile for Win 95/98 and Win NT/2000. But those days are long gone.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Which one of those two methods recommend for my general programming? I mean, which one would be more efficient for my unicode application? – Victor Jan 22 '14 at 20:29
  • Hard to say from here. Personally, I tend to do Windows programming all UTF-16. So I use `std::wstring` and target `UNICODE` builds. – David Heffernan Jan 22 '14 at 20:31
  • Ok then. I will replace the `string`s with `wstring`s. Thank you! – Victor Jan 22 '14 at 20:33