发送字节数组 [英] Sending an Array of Bytes

查看:110
本文介绍了发送字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是从CPP DLL向C#应用程序发送一个字节数组。

My aim is to send an array of bytes from CPP DLL to a C# Application.

我正在设置消息属性如下所示

I am setting message properties as given below




	unsigned char acBuf[10] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
	// Define the required constants and variables.
	const int NUMBEROFPROPERTIES = 5;                   // Number of properties
	DWORD cPropId = 0;                                  // Property counter
	HRESULT hr = MQ_OK;                                 // Return code
	HANDLE hQueue = NULL;                               // Queue handle

	// Define an MQMSGPROPS structure.
	MQMSGPROPS msgProps;
	MSGPROPID aMsgPropId[NUMBEROFPROPERTIES];
	MQPROPVARIANT aMsgPropVar[NUMBEROFPROPERTIES];
	HRESULT aMsgStatus[NUMBEROFPROPERTIES];


	// Specify the message properties to be sent.
	aMsgPropId[cPropId] = PROPID_M_BODY_TYPE; // PROPID_M_BODY_TYPE;               // Property ID
	aMsgPropVar[cPropId].vt = VT_ARRAY | VT_UI1;                // Type indicator
	aMsgPropVar[cPropId].caub.pElems = acBuf;
	aMsgPropVar[cPropId].caub.cElems = 10;
	//aMsgPropVar[cPropId].pwszVal = L"Test Message";     // The message label
	cPropId++;

但在发送期间我收到0xC00E0002错误。

But during send I get 0xC00E0002 error.

告诉我如何解决这个。

Let me know how to fix this.

当接收者读取消息时,它会获得指针或数据本身。如果指针被解除分配后发送消息,那么在接收方那将是一个问题是理解正确吗?

When the receiver reads message does it gets a pointer or the data itself. After sending message if the pointer is deallocated, then it will be an issue at receiver side is mu understanding correct?

问候,

GSR

推荐答案

代码C00E0002的意思是"一个或多个传递的属性无效"。您是否已初始化阵列的所有五个元素? 
或者 NUMBEROFPROPERTIES 太大。

另请查看使用 PROPID_M_BODY PROPID_M_BODY_TYPE :
https:// msdn。 microsoft.com/en-us/library/ms704328(v=vs.85).aspx 。也许你应该建立并发送一个类似的对。

Also check the example that uses PROPID_M_BODY and PROPID_M_BODY_TYPE: https://msdn.microsoft.com/en-us/library/ms704328(v=vs.85).aspx. Perhaps you should build and send a similar pair.


这篇关于发送字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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