开发者

Unmanaged code calling causes a WCF process to crash [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜