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 接口(interface)对象的指针。 Multicast 是一种接受字符串参数的 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 获取这些值
为什么?
最佳答案
如您的编辑所示,请查看 _bstr_t .
关于c# - 如何将字符串发送到 com 接口(interface)中的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9682050/