I have a little annoying problem and I really need help.

I need to convert a char* to TCHAR* and I can't... I have tried everything and nothing seems to help...

TCHAR text1[ ] = "";
char *key;

key[0] = 'a';
key[1] = '\0';

text1 = _T(key); //Does not work

can anyone help me here? I'm stuck

I have a little annoying problem and I really need help.

I need to convert a char* to TCHAR* and I can't... I have tried everything and nothing seems to help...

TCHAR text1[ ] = "";
char *key;

key[0] = 'a';
key[1] = '\0';

text1 = _T(key); //Does not work

can anyone help me here? I'm stuck

char *key;

key[0] = 'a';
key[1] = '\0';

This should give you a segmentation fault.

Do this.

char key[ 2 ]; // or char* key = new char[ 2 ];
 
 key[0] = 'a';
 key[1] = '\0';

As for the _T macro, maybe you haven't defined the _UNICODE macro.

Put

#ifndef _UNICODE

#define _UNICODE 
#endif

at the beginning of the code.

Oh and from what I know, doing TCHAR text1[ ] = ""; , and then assigning key to it should also give you problems.

char *key;

key[0] = 'a';
key[1] = '\0';

This should give you a segmentation fault.

Or even worse, it won't give you a SEGV in debug and when you release it does.. !

Thank You very much, it was giving me the segmentation fault. I fixed it removing key[1] = '\0';

Now it looks like this:
text1[0] = 'a';
TextOut(hdc, posx, height, text1, ARRAYSIZE(text1));

and it's working... am I doing it right?

Point is to allocate memory for the array that's done like this:

char key[ 2 ];

and NOT like this:

char* key;

If you've done this it's fine else not.

I have a little annoying problem and I really need help.

I need to convert a char* to TCHAR* and I can't... I have tried everything and nothing seems to help...

TCHAR text1[ ] = "";
char *key;

key[0] = 'a';
key[1] = '\0';

text1 = _T(key); //Does not work

can anyone help me here? I'm stuck

text1 = _T(key); //Does not work cant work
TEXT macro or _T macro operates on constant multibyte strings.
Example TCHAR text1[ ] = TEXT("Hello") ; u can use conversion routines lie MultibytetoWidechar or mbtowc both will work in your case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.