I have two strings I want to compare. I was following the named piper server/client example of this page: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365592%28v=vs.85%29.aspx
Anyhow, in my "GetAnswerToRequest" I define a string like so
LPTSTR option = TEXT("THIS IS A TEST");
and then I try to compare it to the pchRequest parameter, which is the same string, that the client has sent. I can't find a working comparison that resolves true.
When I put both values in the debugger, I see some differences. For option, I believe it is using single byte characters:
- option,15
[0x00000000] 0x0054 unsigned short
[0x00000001] 0x0048 unsigned short
[0x00000002] 0x0049 unsigned short
[0x00000003] 0x0053 unsigned short
[0x00000004] 0x0020 unsigned short
[0x00000005] 0x0049 unsigned short
[0x00000006] 0x0053 unsigned short
[0x00000007] 0x0020 unsigned short
[0x00000008] 0x0041 unsigned short
[0x00000009] 0x0020 unsigned short
[0x0000000a] 0x0054 unsigned short
[0x0000000b] 0x0045 unsigned short
[0x0000000c] 0x0053 unsigned short
[0x0000000d] 0x0054 unsigned short
[0x0000000e] 0x0000 unsigned short
and for the pchRequest value, it looks like it using double byte characters:
- pchRequest,15
[0x00000000] 0x4854 unsigned short
[0x00000001] 0x5349 unsigned short
[0x00000002] 0x4920 unsigned short
[0x00000003] 0x2053 unsigned short
[0x00000004] 0x2041 unsigned short
[0x00000005] 0x4554 unsigned short
[0x00000006] 0x5453 unsigned short
[0x00000007] 0x5a00 unsigned short
[0x00000008] 0x48c0 unsigned short
[0x00000009] 0x18cf unsigned short
[0x0000000a] 0x0000 unsigned short
So..most of the hex values here match, but there are two per character in pchRequest, and one in my option variable. I think this is what makes lstrcmp()
fail.
Also, it does seem like the pchRequest might have some extra characters in it, but I can't tell where they are coming from. Any ideas on how to compare these two strings, that as far as I know should be identical?
THanks!
You presumably have a Unicode build, which means LPTSTR
is defining a wide string. However you need to compare against an ANSI string.
To do this, just drop the TEXT()
macro, and use char*
instead. For example,
char* option = "THIS IS A TEST";
Then use lstrcmpA()
to invoke the ANSI version of lstrcmp
explicitly.
User contributions licensed under CC BY-SA 3.0