从 C# 传递位值
我有一个 C++ 接口,它有一个公共属性“P”,它接受 5、6,7 等位值。 它的文档说:“设置组类型的位掩码。第 5 位用于“a”,第 6 位用于“b”等。”
我在我的 C# 类中使用这个接口,元数据中显示的属性“P”的类型在 VS.Net 中是“char”。
如何将 6 和 7 的位值从我的 C# 代码传递到此属性? 请注意,如上所述,应将“char”类型的值从 C# 传递到此 C++ 接口,因为这是 VS.net 元数据中显示的类型,
请建议。 代码:
从 VS.Net IDE 中看到的 C++ 接口定义 -
[SuppressUnmanagedCodeSecurity]
[Guid("f274179c-6d8a-11d2-90fc-00806fa6792c")]
[InterfaceType(1)]
public interface IAccount
{
char GroupType { get; set; }
}
C#:
IAccount objAccount= new AccountClass();
((IAccount)objAccount).GroupType = ??//I need to pass char value here
谢谢。
I've a C++ interface having a public property "P" which accepts bit value like 5, 6,7 etc.
Its documentation says:"Set bit mask of group type. Bit 5 is for 'a', Bit 6 is for 'b',etc."
Am using this interface in my C# class and the type of this property "P" shown in the metadata is "char" in VS.Net.
How do I pass the bit value of 6 and 7, to this property from my C# code?
Please note that, as mentioned above, a value of type "char" should be passed from C# to this C++ interface, as this is the type which is shown in the metadata in VS.net
Please suggest.
Code:
C++ interface definition as seen from VS.Net IDE--
[SuppressUnmanagedCodeSecurity]
[Guid("f274179c-6d8a-11d2-90fc-00806fa6792c")]
[InterfaceType(1)]
public interface IAccount
{
char GroupType { get; set; }
}
C#:
IAccount objAccount= new AccountClass();
((IAccount)objAccount).GroupType = ??//I need to pass char value here
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C++ 中的
char
类型始终为 8 位,这可能意味着您将使用byte
在 C# 中表示相同的事物。 (这假设您的 C++ 平台使用标准 8 位字节,因为 C++char
被定义为 1 字节,但 C++“字节”不一定保证为 8 位!)不确定如何将该值封送回 C++ 例程(如果这是您需要做的)。
The
char
type in C++ is always 8 bits, which presumably means that you'd use abyte
to represent the same thing in C#. (This assumes that your C++ platform uses standard 8-bit bytes, since a C++char
is defined as being 1 byte, but a C++ "byte" isn't necessarily guaranteed to be 8 bits!)I'm not sure how you'd marshal that value back to your C++ routine, if that's what you need to do.
您可以使用继承自“byte”的“Enum”类型:
输出:1100000
您需要发布有关本机方法以及如何调用它的更多信息,以便提供进一步帮助。
You can use a "Enum" type which inheres from "byte":
Output: 1100000
You need to post more information on the native method and how you're invoking it in order to help further.