DWORD-》UInt32
WORD-》ushort
函数原型 C++中
//函数功能:测试
//参数: char* testIn1[IN] -- 测试传入参数1
// char* testIn2[IN] -- 测试传入参数2
// char* testOut[OUT] -- 测试传出参数
//返回值: int -- 函数执行成功,则返回0;否则返回错误码
int vxTestFun1(char* testIn1, char* testIn2, char* testOut);
C#中交互对应
[DllImport("Test.dll", EntryPoint = "vxTestFun1", CallingConvention = CallingConvention.Cdecl)]
public static extern int vxTestFun1(string testIn1, string testIn2, IntPtr testOut);
C#中调用
int MaxPath = 260;
byte[] chararray = new byte[MaxPath];
IntPtr x = Marshal.AllocHGlobal(MaxPath * sizeof(byte));//申请与chararray相同大小的内存
Marshal.Copy(chararray, 0, x, MaxPath);//内存拷贝
VxInvoker.vxTestFun1("testin1","testin2", x);
Marshal.Copy(x, chararray, 0, MaxPath);
Marshal.FreeHGlobal(x);//释放内存
string path = Encoding.Default.GetString(chararray).Trim("\0".ToCharArray()) ;//去除掉字符串中多余的终结符"\0"