![](/img/trans.png)
[英]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.