有关IntPtr定义的问题有点晕
C++ 里是
EXPORT int WINAPI Match(void* Minu1, int nMinu1, void* Minu2, int nMinu2);C#里
[DllImport("brmatchCHS.dll", SetLastError=true)]
public static extern int Match(System.IntPtr Minu1, int nMinu1,System.IntPtr Minu2, int nMinu2);
Minu1实际的数据类型应该是byte[]或string 
那么我该如何用IntPtr来表示byte[]或string 呢?

解决方案 »

  1.   

    Marshal.PtrToStructure(IntPtr, Type)
    将数据从非托管内存块封送到新分配的指定类型的托管对象。
    http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfSystemRuntimeInteropServicesMarshalClassPtrToStructureTopic2.asp
      

  2.   

    System.Runtime.InteropServices.Marshal.AllocCoTaskMem();
      

  3.   

    如果说Menu1 的实际类型应该是 byte[]或string 方法应该进行重载:[DllImport("brmatchCHS.dll", SetLastError=true)]
    public static extern int Match(byte[] Minu1, int nMinu1,System.IntPtr Minu2, int nMinu2);[DllImport("brmatchCHS.dll", SetLastError=true)]
    public static extern int Match(String Minu1, int nMinu1,System.IntPtr Minu2, int nMinu2);
      

  4.   

    能否举个例子呢?
    例如:string s="a";
    我想把s传进Match函数里的Minu1用方法重载好象得不到想要的结果
      

  5.   

    [DllImport("brmatchCHS.dll", SetLastError=true)]
    public static extern int Match(ref String Minu1, int nMinu1,System.IntPtr Minu2, int nMinu2);使用:
    String s = "aaa";
    Match(ref s, ...);