Hey guys, I recently started reading the book Programming Windows Fifth Edition by Charles Petzold and I came about a roadblock. The book mentions a _TCHAR type that I could use for either Unicode or ASCII support depending on whether or not _UNICODE is defined. It also mentions that _TCHAR comes with its own functions. The one I'm trying to use is _tcslen().
The problem is, every time I try using _tcslen() I get an error saying _tcslen was not declared in this scope.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <windows.h>
#include <string.h>
#define _UNICODE
#define UNICODE
int main(){
_TCHAR x = 'a';
int tester = 0;
tester = tcslen(x);
return 0;
}
_UNICODE and UNICODE must be defined before including any Windows header. You would normally define these in your project settings, not in any source or header file.
Thanks for the quick reply LB! So I just defined both in my project settings (I'm using CodeBlocks) It was under Project > Build Options > Define. I still get the same Error. The compiler doesn't seem to understand what _tcslen() is, even though I was able to find reference for it on countless MSDB pages. I find this strange because the compiler has no problem with _TCHAR.
I didn't realize you said you were using CodeBlocks - you're probably using GCC or MinGW which doesn't have full proper Windows support. If you want to do Windows development you should just install Visual Studio 2015 - it's free and will save you many headaches.
@JLBorges Thanks a lot mate! Including <tchar.h> made the program run. Also thanks for writing out that piece of code, it definitely helped me understand how TCHAR and _tcslen works much better.