本文来自http://blogs.msdn.com/asiatech/default.aspx 上我写的一篇文章:
.NET application may crash when calling function from native C++ dll
Symptom
===========
Customer built an ASP.NET web application using Visual Studio 2008 on Windows 2008. In the source code, it called a function which was imported from native c++ dll:
[The source code looks like below]
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Runtime.InteropServices.DllImport("PinvokeLib.dll", EntryPoint = " TestStringAsResult", CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
public static extern string TestStringAsResult();
……
protected void Button_Click(object sender, EventArgs e)
{
string str = TestStringAsResult();
}
}
Above code seems working fine during debugging when "Use Visual Studio Development Server" in Web properties. However, when choose the web properties to “Use IIS Web Server”, the web page seems hang and returns server internal error message. This issue will not occur on Windows 2003.
Troubleshoot
===========
We got the source code of native c++ dll and the related method was written like below:
extern "C" PINVOKELIB_API char * TestStringAsResult()