Compile problems with problems with the win32 api TEXT macro

I can compile and run this without a problem

dosomething(BLABLA, TEXT("some text"));


TEXT is the macro from win32 api

but when i try to put a char string like this

char str[100];
scan_f("%s" , str);

dosomething(BLABLA, TEXT(str));


i get errors like error C2065: 'Lstr' : undeclared identifier

the function prototype of the dosomething function is
dosomething(int BLABLA , LPTSTR str_var);


anyone willing to help is welcomed.
I am not very familiar with the win32 api ,but unfortunately i can't post the actual code.
That's because you have _UNICODE defined.

The TEXT and _T macros convert your string literal to the correct type depending on whether _UNICODE is defined.

The use:
1
2
char str[100];
dosomething(TEXT(str));
is wrong.

It should be:
1
2
TCHAR str[100];
dosomething(str);
Thanks for replying first of all.

I tried with TCHAR and also with WCHAR and i still get the compiler error.

I have to say that i the UNICODE is defined in my program so i need the TEXT macro in order to convert the string to UNICODE format.

So any other ideas.
Last edited on
I've just spent about five minutes searching for scan_f. What is that? I can find no references to it. Or do you mean scanf?
I tried with TCHAR and also with WCHAR and i still get the compiler error.
Can you post your attempt?
just replace the char with WCHAR or

WCHAR str[100];
dosomething(TEXT(str));

TCHAR str[100];
dosomething(TEXT(str));

as for the scan_f it's a typing error ,i wanted to type scanf()
This works for me...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//console program - main.cpp
#include <tchar.h>
#include <stdio.h>

void DoSomething(TCHAR* szBuffer)
{
 _tprintf(_T("%s"),szBuffer);
}

int main()
{
 TCHAR szText[]=_T("Hello, World!\n");

 DoSomething(szText);
 getchar();

 return 0;
}

/*  --Output--

Hello, World!

*/


...which is exactly what kbw said to do in his 1st reply.
Last edited on
yes that might works but how can i get a string from the user, not just printing a predefined string on the screen.
That is what i can't figure out.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//console program - main.cpp
#include <tchar.h>
#include <stdio.h>

void DoSomething(TCHAR* szBuffer)
{
 _tprintf(_T("%s"),szBuffer);
}

int main()
{
 TCHAR szText[128];

 _tscanf(_T("%s"),szText);  //I entered freddie [ENTER]
 DoSomething(szText);
 getchar();

 return 0;
}

/*  --Output--

Compiling: main.cpp
Linking console executable: Uni2.exe
Output size is 6.00 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings

Run:

freddie
freddie
Process returned 0 (0x0)   execution time : 4.595 s
Press any key to continue.
*/
Last edited on
Yes indeed that works but i have another problem.

In the function
void DoSomething(TCHAR* szBuffer)
{
_tprintf(_T("%s"),szBuffer);
}


i have this instead:

void DoSomething(LPTSTR szBuffer)
{
_tprintf(_T("%s"),szBuffer);
}

int main()
{
TCHAR szText[128];

_tscanf(_T("%s"),szText); //I entered freddie [ENTER]
DoSomething(_T(szText));
getchar();

return 0;
}



so i still have the problem with the
error C2065: 'Lsztext' : undeclared identifier

I have to pass sztext as a long pointer to string.
i am using visual studio by the way.
I repeat, the TEXT and _T macros convert your string literal ...

In DoSomething(_T(szText)); szText is not a literal, it's a variable.

It should be DoSomething(szText);

It may be helpful if you look up the definition of _T
Last edited on
All the _T or TEXT macros do is prepend a L to whatever symbol they enclose if UNICODE is defined. If it isn't defined they don't do anything. That is why if you put your str variable with the macro it gets converted to Lstr by the preprocessor, and you get a variable not declared error message. You seem determined to put string variables within these macros and it won't work as kbw says.
Topic archived. No new replies allowed.