Tips for using a C library from C#

前端 未结 6 2198
你的背包
你的背包 2020-12-28 21:57

I\'ve got a library in C which I\'d like to use from C#.

From what I\'ve gleaned off the internet, one idea is to wrap it in a C++ dll, and DllImport that.

6条回答
  •  無奈伤痛
    2020-12-28 22:44

    This is how I typically interact with C DLLs from C#:

      public static unsafe class WrapCDll {
        private const string DllName = "c_functions.dll";
    
        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        public static extern void do_stuff_in_c(byte* arg);
      }
    

    No need to wrap in C++ and you get the needed calling convention.

提交回复
热议问题