C++函数里有个参数是指针类型,可以指向结构体A或者结构体B,
C#调用时,怎么申明它?
[DllImport("test.dll", EntryPoint="SetValue")] 
    public static extern int SetValue(ref int hHandle,ref A pt);
其中pt是指针,如果他只指向结构体A的话,我可以象上面那样申明,可是他若是指向另一个结构体B时,我就没办法用了;
高手指点,谢谢。

解决方案 »

  1.   

    如果哪个指针是不定型的话, 你可以做成重载:[DllImport("test.dll", EntryPoint="SetValue")] 
    public static extern int SetValue(ref int hHandle,ref A pt);[DllImport("test.dll", EntryPoint="SetValue")] 
    public static extern int SetValue(ref int hHandle,ref B pt);
      

  2.   

    或者你甚至都可以做成unsafe的,其实只要方便怎么做都可以[DllImport("test.dll", EntryPoint="SetValue")] 
    public static extern unsafe int SetValue(ref int hHandle,A* pt);甚至[DllImport("test.dll", EntryPoint="SetValue")] 
    public static extern unsafe int SetValue(ref int hHandle, void* pt);
      

  3.   

    Have a try[DllImport("test.dll", EntryPoint="SetValue")]
    public static extern int SetValue(ref int hHandle,[MarshalAs( UnmanagedType.LPStruct)]object pt);
      

  4.   

    谢谢2位指点。
    结贴前再想问一下,我觉得.net的msdn总是查询不出实质的帮助,比如我选中Marshal.SizeOf,再按F1,总是没有命中帮助,这方面大家有何指教?
      

  5.   

    to 比如我选中Marshal.SizeOf,再按F1,总是没有命中帮助,这方面大家有何指教?你是否安装的msdn是全的,不过我现在很少按F1来寻求帮助,基本上是直接输入进行查看。
      

  6.   

    应该是装全了msdn,我看了d:\msdn目录里的文件大小是1.67G.
    会不会帮助文档定位不对呢?我没找到msdn目录设置。