Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to convert LPTSTR to LPCWSTR?
    text
    copied!<p>I need to convert from <code>LPTSTR</code> to <code>LPCWSTR</code>. I need this because I'm getting <code>LPTSTR</code> from <code>GetDlgItemText</code>, which I'm going to feed to <code>ExtTextOut</code>, which accepts <code>LPCWSTR</code>.</p> <p>Edit: Before passing of the value from <code>GetDlgItemText</code> I store the value in <code>std::vector</code>. After which I retrieve the value from the <code>std::vector</code> and it returns me an empty/giberish.</p> <p><strong>Dialog box:</strong></p> <pre><code>WORD lineLength = (WORD) SendDlgItemMessage(hwnd,IDC_EDIT1, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0); if(lineLength &gt; 0){ TCHAR line[16]; int number = GetDlgItemTextW(hwnd, IDC_EDIT1, line, 16); HWND parent = (HWND)GetWindowLongPtr(hwnd, GWLP_HWNDPARENT); LPCWSTR line2(line); SendMessage(parent, WM_COMMAND, MAKEWPARAM(ADD_COMBO_ITEM,0), (LPARAM)line); </code></pre> <p>It sends a message to the parent window, which adds this value to the vector (<strong><code>push_back</code></strong>). The class with the parentwindow:</p> <pre><code>std::vector&lt;LPCWSTR&gt; comboItems </code></pre> <p>this is a piece of a function that I use to output my values using <strong><code>ExtTextOut</code></strong>:</p> <pre><code>RECT temp; temp.left = listItemWidth; temp.right = width; SetBkColor(hdc, RGB(240,240,260)); LPCWSTR comboName = L""; for(std::vector&lt;item&gt;::size_type i=0; i != comboItems.size(); i++){ temp.left = listItemWidth; temp.right = width; temp.top = (currentlyClicked + 1) * listItemHeight + i * listItemHeight; temp.bottom = temp.top + listItemHeight; comboName = comboItems[i]; ExtTextOut(hdc, temp.left+2, temp.top + 1, ETO_OPAQUE, &amp;temp, comboName, lstrlen(comboName), 0); DrawEdge(hdc, &amp;temp, EDGE_RAISED, BF_RECT | BF_FLAT | BF_ADJUST); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload