> Don't worry, got it sorted, I think.
> LPTSTR buffer = NULL;
> LPTSTR buffertest = "ACPI Fixed Feature Button";
> //buffer gets populated...
> if (*buffertest == *buffer)
> Who would think you could assign a string to a pointers contents directly
> referencing the point. Maybe I just don't understand the LPTSTR type
> properly yet.
Um... are you newbie to C++ ? :)
I guess you *should* read some good book about that language and
especially all chapters about pointers, arrays, references, and
structures or you will get those "another stupid little one" in million
First, your solution for comparing strings is totally wrong. Don't
worry, it just wont work in some cases. :)
The fact it managed to compile says nothing. :))
C++ likes those kind of ambiguosity, it just "thinks" that you must get
exactly what you've asked for. In that case - you compare NOT
the strings, but just ONE first character of each string!
LPTSTR is just another name to "char *", so it is very simple type and
"Who would think you could assign a string to a pointers contents
directly referencing the point." - is wrong. (Alas, this could be right
for some *really* complicated type, because most operations, even
dereference and comparation, could be overloaded in C++. You'll like
that language... :) )
The fact that
LPTSTR buffertest = "ACPI...";
compiles, also says nothing.
It is just such special syntax to initialize pointers to char ("char
*"). It should be thinked of like this "allocate storage in data segment
for constant string during compilation time, copy characters supplied
to that storage, remember address of the first character to given
variable". during execution time - NO string is allocated, your
buffertest just gets pointed to that pre-allocated single-use storage,
and NO copying of characters occures. If you change that string (meaning
the characters in string, NOT the pointers :) ) - all pointers to that
string would "show" changed value.
While dereferencing LPTSTR, which is "char *", you get "char", of
course... and the string is "char ", say "char " or "char",
you got it? string is the sequence of characters, i.e. array of chars.
Thus, if you want to compare whole strings, you must use something like:
Second, the sample was written for "C", not the C++. C is much more
friendly, it does not allow classes, operator overloading, templates,
and thus all errors you could met with this. It also check types more
lazily, that's why LPTSTR type is equal to HANDLE type in the sample and
not in your project.
If you want allocate memory - in most cases you should forget about
Windows API like LocalAlloc, etc... use "new" operator, it comes with
C++ and support type conversion by default. Look here:
char *pStr = new char ;
got it? the syntax is 'new "type"'. in that case type is char ,
which means allocate 200 characters for storage. you could treat
"char" like "char *", meaning that when you need to work with the
array you could just have pointer to the forst element of the array.
after you work with pStr (be sure NOT to change pStr, only use it as
"readonly", change values it points to, i.e. pStr) you can free the
memory by calling
that's the syntax: you get the pointer allocated with "new" and pass it
to delete. Understood the fact why pointer itself should not change?
Third, Windows lives for more over 10 years with lots of different
versions been introduced. The SetupDi API is from Win32, the LocalAlloc
is from Windows3.0, as far as I remember... ;-)
To support different versions, using "sizeof" member of structures is
just common practice (and not only in Windows). Guess what happens, if
you run "old" program which thinks sizeof(SP_DEVICE_DATA) is 100 with
new, revised version of the system which thinks sizeof(SP_DEVICE_DATA)
is 98? system would overwrite some piece of memory, and it will GPF.
Hope I helped you, follow the advise: study C++, it worth effors...