从非托管代码进入CLR的线程中的未处理异常不会触发"正常"未处理异常CLR处理.
在下面的代码CSSimpleObject.GetstringLength()
中用C++ 调用
在"1"的情况下
在"2"(预期行为)的情况下
要做出"正常"行为需要做些什么?
下面的代码基于" 所有互操作和融合样本 "中的Visual Studio 2010" CppHostCLR "代码示例.
RuntimeHost(C++):
PCWSTR pszStaticMethodName = L"GetStringLength";
PCWSTR pszStringArg = L"1";
//PCWSTR pszStringArg = L"2";
hr = pClrRuntimeHost->ExecuteInDefaultAppDomain(pszAssemblyPath,
pszClassName, pszStaticMethodName, pszStringArg, &dwLengthRet);
if (FAILED(hr))
{
wprintf(L"Failed to call GetStringLength w/hr 0x%08lx\n", hr);
goto Cleanup;
}
Run Code Online (Sandbox Code Playgroud)
托管代码(C#):
public class CSSimpleObject
{
public CSSimpleObject()
{
}
//------8<----------
public static int GetStringLength(string str)
{
AppDomain.CurrentDomain.UnhandledException += new …
Run Code Online (Sandbox Code Playgroud)