Which way is the correct way to handle this.
TCHAR szString[100];
1. ZeroMemory(&szString, sizeof(szString));
2. ZeroMemory(&szString, sizeof(TCHAR) * sizeof(szString));
3. Something else all together.
Which way is the correct way to handle this.
TCHAR szString[100];
1. ZeroMemory(&szString, sizeof(szString));
2. ZeroMemory(&szString, sizeof(TCHAR) * sizeof(szString));
3. Something else all together.
ZeroMemory(szString, sizeof(TCHAR) * sizeof(szString));
The size should be expressed in bytes, so to be correct you should use sizeof(), though a char only takes one byte.
szString is basically a pointer, so you don't get it's adress using &.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>ZeroMemory(szString, sizeof(TCHAR) * sizeof(szString));<
Say we had a unicode array -
TCHAR t[255];
sizeof(TCHAR) would equal 2.
sizeof(t) would equal 510.
Using the above method you'd be zero-ing 1020 bytes. This isn't what you want.
The sizeof operator will produce the number of bytes in an array. All you need is -
ZeroMemory(szString,sizeof(szString));
Joe
My favorite way...if using C++
TCHAR szString[100] = {0};