【发布时间】:2012-03-29 17:41:03
【问题描述】:
cVector3d newPosition = tool->getDeviceGlobalPos();
char sendBuf[sizeof(double)*3 + 1];
int sendBufLen = sizeof(double)*3 + 1;
memset( (void *)&sendBuf, '\0', sizeof(sendBuf));
memcpy(&sendBuf, &newPosition[0], sendBufLen -1);
其中 cpi 是指向 com 接口对象的指针。 多播是一种接受字符串参数的 c# 方法。 当我打印 Multicast 收到的 message.length,即 sendBuf 时,它只显示 2 而不是 24。
cvector3d 参考http://www.chai3d.org/doc/structc_vector3d.html
cpi->Multicast(sendBuf); 有什么问题?
--edit-- 我认为我需要将sendBuf转换为_bstr_t
我转换为 _bstr_t 但 message.length 仍然显示 2 而不是 24?
我用过
_bstr_t bstrt(sendBuf);
我猜 bstr 已损坏,因为我在调试时在 bstr->m_data->m_str 中看到了 BAD PTR
----编辑---- 当我转换 “123456789012378901234”
char sendBuf[sizeof(double)*3 + 1];
memcpy(&sendBuf, "123456789012345678901234", sendBufLen -1);
_bstr_t bstrt(sendBuf);
bstrt 有“123456789012378901234”
但是当我在 sendBuf 中有奇怪的字符时,例如。 sendBuf[14] = "16 'ð' " 我的程序需要的 bstr 没有从 sendBuf 获取这些值
为什么?
【问题讨论】:
标签: c# c++ com-interop