[英]DLLs loaded from wrong AppplicationBase when trying to load mixed C# and C++/CLI dlls in a new AppDomain
[英]Calling C# from C++, Reverse P/Invoke, Mixed Mode DLLs and C++/CLI
据我所知,我可以使用反向P / Invoke从C ++调用C#。 反向P / Invoke只是一个例子:
问题:
提前致谢
以下是我所知的答案:
注意,您还可以执行IL往返C#dll和导出静态方法,这些方法与C ++ / CLI中的导出基本相同。 但是,这总是一个后编译步骤,它确实有一些警告 (你的C ++ / CLI导出也是如此,顺便说一句。)。
您可以ILDASM C#和C ++ / CLI DLL来查看导出的方式; 它是这样的(来自网上的样本 ):
// unmexports.il
// Compile with : ilasm unmexports.il /dll
assembly extern mscorlib {}
..assembly UnmExports {}
..module UnmExports.dll
// This flag is important
..corflags 0x00000002
// This instructs the CLR to create a marshaling thunk for the unmanaged caller
..vtfixup [1] int32 fromunmanaged at VT_01
..data VT_01 = int32(0)
..method public static void foo()
{
..vtentry 1:1
..export [1] as foo
ldstr "Hello from managed world"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
使用ilasm 2.0,您需要更少的代码,因为它可以自己生成大部分的垃圾。 现在真的只需要.export指令。
// unmexports.il
// Compile with : ilasm unmexports.il /dll
.assembly extern mscorlib { auto }
.assembly UnmExports {}
.module UnmExports.dll
.method public static void foo()
{
.export [1] as foo
ldstr "Hello from managed world"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.