A call to std::basic_stri ng<wchar_t>::fi nd(...) 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!st d::basic_string <wchar_t,std::c har_traits<wcha r_t>,std::alloc ator<wchar_t>
::find(_Ch=' ?' (0xE961), _Off=0x00000000 )
mscorwks.dll!79 1befaf()
MyClassLibrary. dll!MyNamespace .MyClass.bar()
MyConsoleApp.ex e!main()
MyConsoleApp.ex e!mainCRTStartu p()
// MyConsoleApp.cp p
#include "stdafx.h"
#include <string>
#using <mscorlib.dll >
#using "C:\MyClassLibr ary.dll"
int _tmain()
{
MyNamespace::My Class::Init();
MyNamespace::My Class* foo = new MyNamespace::My Class();
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_initi alize();
}
void bar()
{
std::wstring string = L"hello world";
size_t n = string.find(L'a ');
}
};
}
// MyClassLibrary compile options
/Od /AI "C:\MyClassLibr ary" /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\Mic rosoft.NET\Fram ework\v1.1.4322 \mscorlib.dll" /FU
"C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \System.dll" /FU
"C:\WINDOWS\Mic rosoft.NET\Fram ework\v1.1.4322 \System.Data.dl l"
// MyClassLibrary link options
/OUT:"C:\MyClass Library.dll" /INCREMENTAL /NOLOGO /DLL
/INCLUDE:"__DllM ainCRTStartup@1 2" /DEBUG /ASSEMBLYDEBUG
/PDB:"C:\MyClass Library.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\L ib\mscoree.lib"