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

原文地址:https://www.cnblogs.com/linqing/p/11679268.html