c# - 如何将字符串发送到 com 接口(interface)中的方法?

标签 c# c++ com-interop

    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/

相关文章:

events - F# 响应式(Reactive)订阅来自 COM 的非标准事件

c# - WCF:套接字连接已中止。远程主机超过接收超时

c# - 如何在 Visual Studio(而非 MSIL)中查看 C# 的汇编代码?

c++ - 在 C++ 中创建结构数组

c++ - 具有未初始化指针的类是否具有未定义的行为?

c# - 从 Vb 调用时,COM-Interop 程序集未找到 native (.Net) 依赖项

c# - maskedTextBox C# 中的 IP 地址验证

c# - 关闭连接时出现“Only assignment, call increment…”错误

c++ - 有没有办法在 C++/MFC 中使用 SHORT 系统时间图片?

c# - 从 C# 调用 VB DLL 上的方法