Calling C# from C++, Reverse P/Invoke, Mixed Mode DLLs and C++/CLI

前端 未结 3 437
故里飘歌
故里飘歌 2020-12-08 08:22

As I understand it I can use reverse P/Invoke to call C# from C++. Reverse P/Invoke is simply a case of:

  1. Create you managed (c#) class.
  2. Create a c++/
3条回答
  •  情歌与酒
    2020-12-08 08:43

    With ilasm 2.0 you need less code because it can generate most of the gunk by itself. Only the .export directive is really needed now.

    // 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
    }
    

提交回复
热议问题