C/C++和C#混合编程笔记-DLL调用与IPC等mixed问题记录
个人备查笔记,视情况补全
---------------------------------------------------------------
Q.C#调用C++ DLL:
C++部分
extern "C" { __declspec(dllexport) IS_RET ImageQuilting( TMatrix *Src, TMatrix *Dest, int TileSizeX, int TileSizeY, int OverlapX, int OverlapY ); __declspec(dllexport) BSTR ImageQuiltingEx(BSTR* inputpath, BSTR* outputpath, int TileSizeX, int TileSizeY, int OverlapX, int OverlapY); }
C#部分
[DllImport("ImageProcessing.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true)] private static extern IS_RET ImageQuilting(ref TMatrix Src, ref TMatrix Dest, int TileSizeX, int TileSizeY, int OverlapX, int OverlapY); [DllImport("ImageProcessing.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode, ExactSpelling = true)] static extern unsafe string ImageQuiltingEx(ref string intputpath, ref string outputpath, int TileSizeX = -1, int TileSizeY = -1, int OverlapX = -1, int OverlapY = -1);
Q.C++/C#传递中文字符串的几种方式:
1.C#: StringBuilder
2.C#: [MarshalAs(UnmanagedType.LPStr)]string
3.C++: 使用BSTR
连接一:https://stackoverflow.com/questions/1450731/equivalent-char-in-c-sharp
本文原创,不定时更新
可以随意转载到任何网站
~但是~ 转载也要按“基本法”
请注明原文出处和作者