-1

I have a method that takes in a System::String^ and internally obtains a VARIANT. I want to compare the var.bstrVal with my string and it never seems to find a match even though I know it does. Here is the code (NOTE: I have updated this with more detail):

System::String^ filterName = "MyStringThatMatches";
//pass to method and code to build up the VARIANT called var...
IPropertyBag *pPropBag;
pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
VARIANT var;
VariantInit(&var);
pPropBag->Read(L"FriendlyName", &var, 0);
pin_ptr<const wchar_t> convertedFilter = PtrToStringChars(filterName);
    if (0 == wcscmp(var2.bstrVal, convertedFilter))

So the wcscmp never finds a match. I thought I was on the right track here.. Any ideas?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
JustinC
  • 29
  • 5
  • what is wcsmp and can you provide MCVE? –  Oct 01 '15 at 19:21
  • Side note: Use utf8 to get rid of stupid unicode encodings. –  Oct 01 '15 at 19:25
  • This particular example works just as expected ('wcscmp' returns 0). Maybe there is something wrong with the way you are initializing the VARIANT? Please post some more code. – Sebacote Oct 01 '15 at 19:54
  • wcscmp() is a pretty crude way to compare Unicode strings but isn't technically wrong. Simply use the debugger, use Debug > Windows > Memory > Memory 1 and put "filterName" in the Address box. Do it again, now using Memory 2 and use "var2.bstrVal". Now you see what wcscmp() sees and it should be obvious how the strings could differ. – Hans Passant Oct 02 '15 at 09:03

1 Answers1

0

Thanks for the suggestion to use the Memory windows Hans. It turns out my code was fine but the string I was comparing to had an extra whitespace in it.

JustinC
  • 29
  • 5