问题标签 [bstr]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
216 浏览

c++ - 释放从 char* 创建的 _bstr_t

我有 char* 数组,我正在为它动态分配内存。

这个 char* 我传递给 _bstr_t 如下,

如何通过 bstrData 释放分配给 char* 的内存?

0 投票
3 回答
4583 浏览

c# - Reading single chars from a .NET SecureString in C#?

WPF's PasswordBox returns a SecureString, which hides the password from snoopers.

The problem is that you eventually have to get the value of the password, and the suggestions I've found on the net all involve copying the value into a string, which gets you back to the problem of snoopers.

But if you really think about it, you don't really need the value, as a string. I mean, what do you do with a password? You hash it and then compare the result to a saved hash, and see if they are the same.

In other words, you don't need to convert the SecureString into a string, you just need to be able to iterate over the individual characters in the string.

But how?

How do I loop over the individual characters in a BSTR, in C#, without converting it to a managed string?

EDITING: the solution, in case the link disappears:

The Marshall class provides methods that can extract individual bytes or ints from an IntPtr, at given offsets. A BSTR object contains an array of 16-bit characters, terminated by two null bytes. So you can access them by looping:

(I don't care for that flow control. I'd have used a do...while, rather than prepopulate b with a dummy value, or I'd have used a for(;;) loop, with internal breaks, or I'd have looped on the length, which I explain how to get, below.)

Also, I'd probably use:

Reading the entire unicode chars, instead of just the low bytes of each.

You can get the length of the BSTR with:

This is the number of bytes, not including the nulls, not the number of chars.

Also - use:

0 投票
1 回答
1216 浏览

visual-c++ - CComBSTR 内存管理

我在以下场景中使用 CComBSTR,

计时器将每隔 5 秒执行一次。

在上述情况下,内存每 5 秒增加一次。据我了解,CComBSTR 在超出范围时会清理内存。因此,每当计时器结束时,必须释放分配的内存。但它不是。

我需要了解使用 CCOMBSTR 时何时释放内存。

0 投票
1 回答
2000 浏览

c++ - 使用 _bstr_t 时无效的空指针

我有一个正在开发的 COM DLL,但遇到了一些问题。我对一段代码进行了尝试捕获,并且在捕获中我_bstr_t从异常中得到了一个。我想要做的是捕获该异常并将其打印到一个字符串中,但是,当该异常被抛出时,它会向我抛出一个无效的空指针错误。我尝试查看有关如何检查空指针的 MSDN,但它似乎不起作用。我无法真正调试该错误,因为这是在客户端计算机上,并且在尝试输出信息时出现此错误。

0 投票
2 回答
449 浏览

c++ - 寻找最短的字符串类型转换C++

我正在制作一个使用 C# 托管 DLL 的非托管 C++ DLL。我正在编写 C++ 库,因为我需要使用在软件中定义的函数和头文件,C++ 库可以作为插件添加。但是我想做的事情太复杂了,以至于我对 C++ 的了解会减慢我的速度,所以我决定用我最喜欢的 C# 做事情,并通过 COM 连接 DLL,我成功了。

我在使代码工作方面取得了某种成功,但在保持代码简洁方面不太成功,因为我显然不是专业的 C++ 程序员。

问题在于转换各种字符串类型。特别是 BSTR 和 const char *。

以下代码将 const char * 转换为 BSTR:

问题是,我有很多离散的 someChars 和相应的离散接口方法......属性方法是从 C# 接口生成的,所以我无法更改它。每个“someChar”都需要以下三行代码,因此对于 30 个离散变量,我需要编写 90 行代码。

问题是:如何为此编写一些快捷方式以便它只适合一行?

我用“getter”函数指针和 someChar 指针尝试了某种函数。

但是随后编译器说了一些关于绑定函数的奇怪事情,以及它们如何不允许作为指针......我用谷歌搜索了它的含义以及更改函数定义所需的解决方案,但我不能这样做,因为定义是生成的来自 C# 代码(通过 regasm.exe)。

重要说明:最后我需要获取 const char * 类型,因为它是我正在为其制作 C++ DLL 的程序的函数所需的输入类型。

0 投票
1 回答
1751 浏览

string - BSTR 和字符串

或者可以将 TCHAR * 传递给以 BSTR 作为输入参数的 API。

是否可以通过return语句将wchar_t字符串转换为BSTR。会导致一些内存损坏吗?

0 投票
2 回答
2478 浏览

string - Visual C++ 将 BSTR 写入文件

我是 C++ 的新手。我正在尝试将 BSTR 写入 CSV 文件,但是使用 wcout 打印时的数据与文件中存在的数据不匹配。

  1. 如果 tempString = L"TestData" -> 我可以在文件中看到相同的值。
  2. 如果 tempString = getData(); 在函数返回 BSTR 的地方,我无法在文件中看到相同的值。

有人可以澄清一下吗?另请解释将BSTR写入文件的方法到底是什么?

编辑:添加代码

0 投票
2 回答
2360 浏览

c++ - 在 LPCSTR 中附加 BSTR

我有一个接收 BSTR 的类函数。在我的课堂上,我有一个成员变量是 LPCSTR。现在我需要在 LPCSTR 中附加 BSTR。我怎么能做到这一点。这是我的功能。

在我的 m_classMember 中,我希望在这个函数值之后应该是“名称:text_received_in_function”。我怎么能做到这一点。

0 投票
4 回答
4979 浏览

c++ - _bstr_t 内存泄漏

我有一个 C++ 代码。但它没有正确释放内存。告诉我哪里错了,这是我的代码

GetXML(第 5 行)返回一个 BSTR。在这个程序的内存增加。但是在 SysFreeString(第 7 行)之后内存没有释放。我在这里做错了什么?

0 投票
3 回答
1648 浏览

c++ - 如何在 C++ 中删除 BSTR 类型的变量

下面的代码是我的结构和包含结构引用的类。

当我编译上面的代码时,我在 DeleteMessageQueue 函数中收到以下错误

错误 C2451:'_bstr_t' 类型的条件表达式是非法的 错误 C2228:'.Detach' 的左侧必须有类/结构/联合