Click here to Skip to main content
15,912,493 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Memory leak problem. Pin
sirtimid4-Sep-11 10:19
sirtimid4-Sep-11 10:19 
QuestionGetting AppData Directory Path Pin
jwalker3432-Sep-11 17:02
jwalker3432-Sep-11 17:02 
AnswerRe: Getting AppData Directory Path Pin
Richard Andrew x643-Sep-11 10:19
professionalRichard Andrew x643-Sep-11 10:19 
GeneralRe: Getting AppData Directory Path Pin
jwalker3435-Sep-11 9:52
jwalker3435-Sep-11 9:52 
GeneralRe: Getting AppData Directory Path Pin
Richard Andrew x645-Sep-11 10:13
professionalRichard Andrew x645-Sep-11 10:13 
AnswerRe: Getting AppData Directory Path Pin
MicroVirus6-Sep-11 1:28
MicroVirus6-Sep-11 1:28 
GeneralRe: Getting AppData Directory Path Pin
jwalker3436-Sep-11 5:44
jwalker3436-Sep-11 5:44 
GeneralRe: Getting AppData Directory Path Pin
MicroVirus6-Sep-11 15:31
MicroVirus6-Sep-11 15:31 
jwalker343 wrote:

I'm still a bit confused about the TCHAR and WCHAR definitions... they seem to convert themselves... i guess these are one of those "C++ Macros" that i've been reading about?


These are indeed macro's. The definition of TCHAR sort of goes like:
C++
#ifdef _UNICODE
#define TCHAR WCHAR // Unicode is on -> Wide character type
#else
#define TCHAR CHAR // Unicode is off -> Normal character type
#endif



jwalker343 wrote:
i figured i could just strcat() the strings in the same line, but i'm still trying to figure out C++


The thing with TCHARs is that they work very nicely in allowing your code to compile and work both when compiling for Ansi and for Unicode (Wide) character sets. But, there is a catch. You need to make sure all your string function follow the t-pattern. That's why, in tchar.h there are a lot of macro's that switch definition based on whether _UNICODE is true or not. These are the _txyz macro's, such as _tcscat for strcat/wcscat, or _tcslen for strlen or wcslen.
If you define all your strings as TCHAR and use the associated _txyz routines, then your code will compile for all character sets without having to change. This does require a slight awareness though. Code like sizeof() can work differently. sizeof always gives the size in 'char', and that's equal to strlen for ansi, but equal to twice the wcslen for unicode (as wcslen gives the amount of wide characters, and each character is 2 bytes (chars) in size).

There is a lot of intricacies to C++, certainly when targeting a specific platform, such as Windows. One of those intricacies is tchar.h and all its facets Wink | ;)

At any rate, you were right in your assumption: you can just use strcat the way you wanted to.

jwalker343 wrote:
i've made the changes stated above, but i am now getting a "Debug Assertion Error" on my line:

Now, to the problem at hand: I think you are mixing two bits of code. The one I gave and the one given by the other poster. You posted a piece of code in the beginning. If you replace exactly that code with the code I posted (and add/remove nothing) then it should work.
I think you added a delete[] strPath to the snippet I gave, as per the other posters code. delete[] is necessary when you allocate memory using new[]. However, in this snippet the strPath is a fixed size array (MAX_PATH + 50, in my example) allocated on the stack, so it is automatically cleaned up as it goes out of scope (at function return). delete is for (manually) heap-allocated memory, and thus gives an error when used on stack-memory.
So, guideline is: are you using new to allocate memory? -> Then use delete after you are done with it.
Are you using new[..] to allocate memory? -> Then use delete[] after you are done with it.
Else, the memory is stack allocated and you don't need to manually free it.
GeneralRe: Getting AppData Directory Path Pin
jwalker3437-Sep-11 16:03
jwalker3437-Sep-11 16:03 
Questionhelp me!!! Pin
zz526335731-Aug-11 5:30
zz526335731-Aug-11 5:30 
QuestionHow to use forms / dialog boxes with an ATL Project / BHO? Pin
abetterword23-Aug-11 4:22
abetterword23-Aug-11 4:22 
AnswerRe: How to use forms / dialog boxes with an ATL Project / BHO? Pin
MicroVirus6-Sep-11 2:06
MicroVirus6-Sep-11 2:06 
QuestionFailure to Recognise Base Class [modified] Pin
Bram van Kampen19-Aug-11 13:47
Bram van Kampen19-Aug-11 13:47 
AnswerRe: Failure to Recognise Base Class Pin
Richard MacCutchan20-Aug-11 0:23
mveRichard MacCutchan20-Aug-11 0:23 
GeneralRe: Failure to Recognise Base Class Pin
Bram van Kampen20-Aug-11 15:47
Bram van Kampen20-Aug-11 15:47 
GeneralRe: Failure to Recognise Base Class Pin
Richard MacCutchan20-Aug-11 23:32
mveRichard MacCutchan20-Aug-11 23:32 
AnswerRe: Failure to Recognise Base Class Pin
«_Superman_»22-Aug-11 13:14
professional«_Superman_»22-Aug-11 13:14 
QuestionCommon Controls Issue Pin
Tracy Software16-Aug-11 2:55
Tracy Software16-Aug-11 2:55 
Questioniterator default value [modified] Pin
liquid_5-Aug-11 1:34
liquid_5-Aug-11 1:34 
AnswerRe: iterator default value Pin
Stephen Hewitt6-Aug-11 20:40
Stephen Hewitt6-Aug-11 20:40 
GeneralRe: iterator default value Pin
liquid_7-Aug-11 9:18
liquid_7-Aug-11 9:18 
QuestionSOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ Pin
VeganFanatic24-Jul-11 8:44
VeganFanatic24-Jul-11 8:44 
QuestionRe: SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ Pin
Richard MacCutchan24-Jul-11 21:09
mveRichard MacCutchan24-Jul-11 21:09 
AnswerRe: SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ Pin
VeganFanatic25-Jul-11 2:25
VeganFanatic25-Jul-11 2:25 
GeneralRe: SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\ Pin
Richard MacCutchan25-Jul-11 3:33
mveRichard MacCutchan25-Jul-11 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.