I am trying to loop through a TCHAR array and for each loop iteration, convert the iteration number to a string and save it into the array.
The code below is what I have:
#undef UNICODE
#define UNICODE
#undef _UNICODE
#define _UNICODE
#include <tchar.h>
#include <string>
#include <windows.h>
#include <strsafe.h>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
LRESULT CALLBACK MyTextWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//do stuff...
#define LINES 56
static TCHAR *abc[LINES];
for(unsigned int l = 0; l<(LINES-1); l ++){
std::wstring s = std::to_wstring(l);
abc[l]=TEXT(s.c_str());
}
But it gives the following error in CodeBlocks:
error: 'Ls' was not declared in this scope
I have tried reading about TCHAR and the TEXT macro. According to here https://learn.microsoft.com/en-us/windows/win32/api/winnt/nf-winnt-text the TEXT macro expects a pointer to the string which is why I tried using .c_str()
The
TEXT(or_T) macro is used for character strings ("string"), not variables. It will place a leadingLbefore the argument if compiling withUNICODE(or is it_UNICODE? I never remember), so a string will becomeL"string".The
wstringclass will return awchar_t *pointer, which you can assign to yourTCHAR *value. However, yourwstringobject is a local, and is destroyed at the end of the loop iteration. You'll need to either dynamically allocate space for theTCHAR *values, or allocate an array ofwstringobjects to hold the constructed strings that will stick around until your done usingabc.