#pragma for WinRT组件中的值struct(C ++) [英] #pragma for value struct in WinRT component(C++)

查看:76
本文介绍了#pragma for WinRT组件中的值struct(C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我有一个WinRT组件(用C ++编写)我打算在C#Metro App中使用它。



这个WinRT组件包含一个自定义结构如下



#pragma pack(1)

公共值struct MyStruct

{

int int1;

int int2;

BOOLEAN bFlag1;

BOOLEAN bFlag2;

UINT32 dwValue;

Platform :: String ^ MyStr;

} ;
$
#pragma pack()



编译时出现以下错误



错误C3621:'myNamespace :: MyStruct':只有默认的打包值(8 )允许使用WinRT类型



如何解决此问题。



感谢任何人帮助。





$
问候。







Hello Everyone,

I have a WinRT component(in C++) and I intend to use it in a C# Metro App.

This WinRT component contains a custom struct as follows

#pragma pack(1)
public value struct MyStruct
{
int int1;
int int2;
BOOLEAN bFlag1;
BOOLEAN bFlag2;
UINT32 dwValue;
Platform::String^ MyStr;
};
#pragma pack()

On compilation I get the following error

error C3621: 'myNamespace::MyStruct': only the default packing value (8) is allowed for WinRT types

How do I go about solving this problem.

Thanks for any help.



Regards.



推荐答案

错误消息很明确:您需要使用WinRT类型的默认打包。

The error message is clear: you need to use the default packing for your WinRT type.

如果您需要在一个地方安装#pragma pack(1)来与需要的代码进行通信,但您不能在其他地方使用#pragma pack(1)因为你需要与需要8的代码进行通信,那么你需要在通信
边界使用单独的结构并在它们之间进行编组。

If you need to have #pragma pack(1) in one place to communicate with code which requires that, but you can't use #pragma pack(1) elsewhere because you need to communicate with code which requires 8 then you will need to use separate structures at the communication boundary and marshal between them.

最好这样做的地方将是取决于具体的用例。

Where it is best to do this will depend on the specific use case.

- Rob


这篇关于#pragma for WinRT组件中的值struct(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆