Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to call c# from c++ - meetup app osaka@10

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

How to call c# from c++ - meetup app osaka@10

2026/2/21 meetup app osaka@10
「C++からC#を呼ぶ方法の一覧」遥佐保

Avatar for Akiko Kawai

Akiko Kawai

February 21, 2026
Tweet

More Decks by Akiko Kawai

Other Decks in Programming

Transcript

  1. Type C# → C++(序章) C++ → C#(本丸) COM系 COM Interop(RCW)

    COM Interop(CCW) CLI系 C++/CRIラッパー /clr, C++/CLIブリッジDLL Export系 P/Invoke (DLLImport,LibraryImport) DllExport, NativeAOT+[UnmanagedCallersOnly] Hosting系 なし (C++は既にNativeなので Runtime不要) CLR Hosting, hostfxr+[UnmanagedCallersOnly]
  2. Type C# → C++(序章) COM系 COM Interop(RCW) CLI系 C++/CLIラッパー Export系

    P/Invoke (DLLImport,LibraryImport) https://learn.microsoft.com/ja-jp/dotnet/standard/native-interop/runtime-callable-wrapper RCW C# Client COM Object C++/CLI 自作Wrapper (/clr) C# Client Native Class/DLL C# Client Marshal (auto- generated) Native DLL CRLに組み込まれている DllImport 実行時 LibraryImportビルド時
  3. Type C++ → C#(本丸) COM系 COM Interop(CCW) CLI系 /clr 化

    C++/CLIブリッジDLL CCW C# Object COM Client Native Class/DLLのCLR化 (/clr) IJW(It Just Works) Thunk using VTableFixup C++/CLI 自作ブリッジ DLL C# Object Native Class/DLL C# Object
  4. Type C++ → C#(本丸) Export系 DllExport (~.NET Framework) NativeAOT (.NET

    7+) +[UnmanagedCallersOnly] Build後にToolでC# DLLのILを書き換え パッチDLL(純粋なIL) C# Object using VTableFixup Native Class/DLL AOTコンパイラが C#コードをNativeDLLへ Native Class/DLL C# Native
  5. Type C++ → C#(本丸) Hosting系 CLR Hosting hostfxr (.NET Core

    3.0+) +[UnmanagedCallersOnly] C++ Process CLR Runtime C# Managed Heap Native Class/DLL C++ Process Core CLR Runtime C# Managed Heap Native Class/DLL
  6. Type C# → C++(序章) C++ → C#(本丸) COM系 COM Interop(RCW)

    COM Interop(CCW) CLI系 C++/CRIラッパー /clr, C++/CLIブリッジDLL Export系 P/Invoke (DLLImport,LibraryImport) DllExport, NativeAOT+[UnmanagedCallersOnly] Hosting系 なし (C++は既にNativeなので Runtime不要) CLR Hosting, hostfxr+[UnmanagedCallersOnly]