Hello,
A call to std::basic_string<wchar_t>::find(...) from within a class library
is not working as expected. The value passed to find is 0x61, but the value
it receives is 0xE961. What's happening? How do I fix this?
Thanks
// stack trace
msvcp71d.dll!std::basic_string<wchar_t,std::char_t raits<wchar_t>,std::allocator
// the arg passed in the next line is L'a' = 0x0061, but the value received
by the called string.find() routine is 0xE961.
<wchar_t> >::find(_Ch='?' [is 0xE961, should be 0x0061], _Off=0x00000000)
mscorwks.dll!791befaf()
MyClassLibrary.dll!MyNamespace.MyClass.bar()
MyConsoleApp.exe!main()
MyConsoleApp.exe!mainCRTStartup()
// MyConsoleApp.cpp
#include "stdafx.h"
#include <string>
#using <mscorlib.dll>
#using "C:\MyClassLibrary.dll"
int _tmain()
{
MyNamespace::MyClass::Init();
MyNamespace::MyClass* foo = new MyNamespace::MyClass();
foo->bar();
return 0;
}
// MyClassLibrary.cpp
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "_vcclrit.h"
#include <string>
using namespace System;
namespace MyNamespace
{
public __gc class MyClass
{
public:
static void Init()
{
__crt_dll_initialize();
}
void bar()
{
std::wstring string = L"hello world";
// L'a' = 0x0061, but the value received by string.find() is 0xE961
size_t n = string.find(L'a');
}
};
}
// MyClassLibrary compile options
/Od /AI "C:\MyClassLibrary" /D "WIN32" /D "_DEBUG" /D "_WINDLL" /D "_MBCS"
/FD /EHsc /MDd /GS /Zc:wchar_t /GR /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3
/nologo /c /Zi /clr /TP /FU
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\msco rlib.dll" /FU
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Syst em.dll" /FU
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Syst em.Data.dll"
// MyClassLibrary link options
/OUT:"C:\MyClassLibrary.dll" /INCREMENTAL /NOLOGO /DLL
/INCLUDE:"__DllMainCRTStartup@12" /DEBUG /ASSEMBLYDEBUG
/PDB:"C:\MyClassLibrary.pdb" /NOENTRY /FIXED:No mscoree.lib msvcrt.lib
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
"\Program Files\Microsoft Visual Studio .NET 2003\Sdk\v1.1\Lib\mscoree.lib"