I have decided to begin working with Unicode compatible programs and have started the process of easing my mind into the correct way of thinking for this task. Quite quickly I encountered a couple of issues that I couldn't seem to understand the cause of, so I am hoping that someone here can provide an insight. Thanks in advance for any help with these problems.
The first problem seems to relate to a simple concatenation of wchar_ts. Firstly, I have come to understand that (correct me if I'm wrong) TCHAR is infact a wchar_t if UNICODE is defined and so I have been using TCHAR extensively. All I am trying to do in this snippet is obtain the value of the %systemdrive% variable and pre-pend it to a file path.
Here is my first attempt:
CODE
TCHAR* sysdrive = new TCHAR[2];
ExpandEnvironmentStrings(L"%systemdrive%", sysdrive, 2);
log = _tcscat(sysdrive, L"\\Folder\\log.txt"); //this line causes program to crash, could be result of above line though?
ExpandEnvironmentStrings(L"%systemdrive%", sysdrive, 2);
log = _tcscat(sysdrive, L"\\Folder\\log.txt"); //this line causes program to crash, could be result of above line though?
Pretty much directly converted from the working char* version I have been using.
Having no idea what could be wrong on where the problem lies, I decided that the sysdrive is probably not going to be a Unicode character so I would see if it worked with a char* casted to a TCHAR*:
CODE
char* sysdrive = new char[2];
ExpandEnvironmentStringsA("%systemdrive%", sysdrive, 2);
log = _tcscat((TCHAR*)sysdrive, L"\\Folder\\log.txt"); //this line causes program to crash, could be result of above line though?
ExpandEnvironmentStringsA("%systemdrive%", sysdrive, 2);
log = _tcscat((TCHAR*)sysdrive, L"\\Folder\\log.txt"); //this line causes program to crash, could be result of above line though?
Still no luck. Since I am still in the first stages of non char characters and general Unicode API use there is probably something fundamental that I have missed, or it could be the (badly)self-taught C catching up to me.
Plugging on to the second identifiable issue with my program, I can't seem to work out how to compare my TCHAR*s correctly. Here is a comparison that just wont go:
CODE
if(_tcscmp(argv[1], L"/?")==0) //argv being the command parameters from main()
Simple stuff, just checking to see if someone used the /? command-line switch with my program. No joy with this one either (no crashes, just no joy).
If anyone can offer any help or advice with either of these issues, or point me in the direction of a good Unicode handling tutorial (or even both!) then I would greatly appreciative.
Thanks
======
EDIT: Ok, I have spotted the huge buffer overflow magnet, and that is now sorted. The /? comparison still doesn't work though...