I have a class which includes managed code calling to unmanaged code via C++\CLI wrapper. Where running the class in a console application produces no errors.
But when I wrapped it up with a WCF service the application crashes when the code reaches the point of calling unmanaged code.The problem is when passing a const wchar_t* 开发者_如何学Pythonvariable as input to the unmanaged code:
String^ text = … // Unicode Encoded text;
const wchar_t* chars = reinterpret_cast<const wchar_t*> ((Marshal::StringToHGlobalUni(string)).ToPointer());
unmanaged_class::Process(chars);
Also tried this with no luck:
pin_ptr<const wchar_t> chars = ...
The application just shutdown without any exception.
I am working on Windows Server 2008 64 bit machine with .NET 4.0.
The application is configured to run on 64bit platform.Any ideas?
Cheers, Doron.
You invoked undefined behavior somewhere in your unmanaged code.
It seems that the problem was buried in the unmanaged code which is 3rd party code who had a bug and crashed in this scenario.
This is a completely wild guess, but shouldn't the chars
pointer be pinned?
pin_ptr<const wchar_t> chars = ...
Another wild guess: does it need to be kept alive using GC::KeepAlive( chars );
after the unmanaged call?
精彩评论