C++里面带位域的怎么P/Invoke啊?? C#里面没有位域的概念吧?比如我有struct bs{ int a:8; int b:2; int c:6;}; void test(bs* pbs); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/t/20030531/22/1860471.html这里有个类似的帖子,可以参考我比较懒,直接工具伺候:[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] public struct bs { /// a : 8 ///b : 2 ///c : 6 public uint bitvector1; public uint a { get { return ((uint)((this.bitvector1 & 255u))); } set { this.bitvector1 = ((uint)((value | this.bitvector1))); } } public uint b { get { return ((uint)(((this.bitvector1 & 768u) / 256))); } set { this.bitvector1 = ((uint)(((value * 256) | this.bitvector1))); } } public uint c { get { return ((uint)(((this.bitvector1 & 64512u) / 1024))); } set { this.bitvector1 = ((uint)(((value * 1024) | this.bitvector1))); } } } public partial class NativeMethods { /// Return Type: void ///pbs: bs* [System.Runtime.InteropServices.DllImportAttribute("yourdll.dll", EntryPoint = "test")] public static extern void test(ref bs pbs); }去Google一下: PInvoke Signature Toolkit 你的问题主要就是平台调用过程中的数据封送问题。楼上的cppfaq已经给出了正确的答案。但是如果只获得答案,不知道原理,以后遇到了此类问题还是不知道如何下手。如果你想系统学习如何进行数据封送,我推荐你阅读刚刚出版的新书:《精通.NET互操作P/Invoke,C++Interop和COM Interop》,这本书的第2章“数据封送”详细介绍了平台调用中的数据封送过程,非常详细,我就是读完后才搞清楚平台调用中的封送处理。 该书的官方网站: www.interop123.com 豆瓣网信息: http://www.douban.com/subject/3671497/ 我发现个问题,多任务环境下,不能把异常写在函数里! c#图像处理问题 C#中怎么在当前界面关闭另外一个界面 c# webform 父子表如何显示 C#可以支持GPS地图吗? Winform只能打开一个相同的子窗体 请高手帮忙改,数组转为图像 C#中怎样才能截到视频的图像? DataTable汇出为xml文件的问题 用C#创建Windows(NT)服务问题 解决后马上给分 哥哥姐姐 关于注册表新建字符串值
这里有个类似的帖子,可以参考我比较懒,直接工具伺候:
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct bs
{ /// a : 8
///b : 2
///c : 6
public uint bitvector1; public uint a
{
get
{
return ((uint)((this.bitvector1 & 255u)));
}
set
{
this.bitvector1 = ((uint)((value | this.bitvector1)));
}
} public uint b
{
get
{
return ((uint)(((this.bitvector1 & 768u)
/ 256)));
}
set
{
this.bitvector1 = ((uint)(((value * 256)
| this.bitvector1)));
}
} public uint c
{
get
{
return ((uint)(((this.bitvector1 & 64512u)
/ 1024)));
}
set
{
this.bitvector1 = ((uint)(((value * 1024)
| this.bitvector1)));
}
}
} public partial class NativeMethods
{ /// Return Type: void
///pbs: bs*
[System.Runtime.InteropServices.DllImportAttribute("yourdll.dll", EntryPoint = "test")]
public static extern void test(ref bs pbs); }去Google一下: PInvoke Signature Toolkit
该书的官方网站:
www.interop123.com 豆瓣网信息:
http://www.douban.com/subject/3671497/