- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很少直接使用Windows API,但我遇到了一种不可避免的情况,我不知道如何处理它。
MS API 文档引用了 API 调用的参数,例如
out Something LPWSTR
所以我显然必须提供一个缓冲区来接收它,但是我应该如何知道要提供多大的缓冲区?我想我可以尝试在 Something 上调用 StrLen,但这似乎意味着我需要调用 API 两次,一次是为了获取长度,第二次是为了实际检索结果,并且长度可能在此期间发生了变化。
OTOH,我可以预先分配缓冲区(例如作为本地 WideChar 数组),但这似乎有点不切实际,因为返回的字符串可以是任意长度(?)。
那么,我的q是如何正确接收一个Out LPWSTR的值呢?另外,作为补充,我如何找到它的编码(或者 Win API 是否始终使用相同的编码,如果是的话,是哪一个?)
我正在询问 Delphi 的后 Unicode 版本。
最佳答案
在等待您对评论的回复时:请考虑一下 GetTempPathW()
函数。是documented如下
DWORD GetTempPathW(
DWORD nBufferLength,
LPWSTR lpBuffer
);
nBufferLength
The size of the string buffer identified by lpBuffer, in TCHARs.
lpBuffer
A pointer to a string buffer that receives the null-terminated string specifying the temporary file path.
Return value
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the length, in TCHARs, of the buffer required to hold the path.
所以,是的,如果您想分配正确长度的缓冲区,您需要首先使用 nBufferLength = 0
调用它,或者足够小。然后使用返回值分配缓冲区并再次调用该函数。
关于delphi - 提供缓冲区来接收 Out LPWSTR 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58628671/
我在将值转换为 LPWSTR 时遇到困难。我正在获取一个注册表值,并尝试将结果作为 LPWSTR 返回。看起来使用 RegQueryValueExW 的注册表调用适用于各种类型来存储结果,但我无法将它
我正在按照本教程在 Windows 中进行串行通信 (http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/
编译C++项目时出现以下错误。 Error C2664 'BOOL CryptBinaryToStringW(const BYTE *,DWORD,DWORD,LPWSTR,DWORD *)': ca
我有一个函数,它只接受一个 LPWSTR 作为参数。但是,我需要在它的末尾添加整数。 这是一个示例伪代码: int theNumber = 5; LPWSTR myLPWSTR = L"Number
好的,我的程序有问题。我之前提出过一个问题,但没有人真正理解我的问题,所以这次我尝试了一种新的方法。 如果你好奇这是我的问题: My program takes arguments in the fo
这个问题在这里已经有了答案: How to convert std::string to LPCWSTR in C++ (Unicode) (6 个答案) 关闭 8 年前。 我很难将字符串转换为 L
我正在尝试初始化 MENUITEMINFO 以调用 InsertMenuItem。尝试将 const 字符串分配给 dwTypeData 时,出现错误。以下代码来自 MSDN 示例。 两种类型的赋值都
我很少直接使用Windows API,但我遇到了一种不可避免的情况,我不知道如何处理它。 MS API 文档引用了 API 调用的参数,例如 out Something LPWSTR 所以我显然必须提
我正在尝试编码一个如下所示的 C++ 结构: typedef struct _SOME_STRUCT { DWORD count; LPWSTR *items; } “items”
我正在替换一个旧的 DLL,它有一个函数,通过引用传递一个 LPWSTR。这些函数应该创建一个新的 wchar 缓冲区并返回新创建的 LPWSTR 指针。我找到了解决方案,但我认为它可以更好地解决!?
我正在使用 WinAPI GetLogicalDriveStrings() 需要 LPWSTR 的函数并且想知道是否有更安全的方法来确保没有内存泄漏。 目前我构造了一个指向缓冲区的初始指针 buf使用
我正在尝试使用 cmd.exe 执行一些操作,但我想隐藏 cmd.exe。当我尝试使用完整路径而不是 cmd.exe 时,我总是会收到此错误: char Process[] = "C:\\WINDOW
我有一个 LPWSTR 类型的变量,其中包含 "true" 或 "false"。有没有一种方法可以将其转换为具有 true 或 false 的 bool 类型的变量? 理想情况下我想做这样的事情: F
我已经使用 wstringstream 构建了一个字符串,需要将其分配给类型为 LPWSTR 的 struct 成员。我尝试使用 my_stringstream.str().c_str() 但出现以下
根据我的理解(如果我错了请纠正我),它们之间的唯一区别是字符串是否可以被调用的函数修改。 ( PCWSTR , LPWSTR ) 我现在正尝试将字符串从 C# 传递到需要 PCWSTR 的函数,但我能
在 Visual C++ 中,我有一个 LPWSTR mystring; 它已经在代码的其他地方定义了。 我想创建一个新的 LPWSTR 包含: "hello " + mystring + " bla
作为一个 C++ 新手,我似乎无法正确地做到这一点,尽管我知道它应该很简单:{ - 我需要创建一个 LPWSTR 数组,然后用唯一的字符串填充它。我们的想法是做这样简单的事情: LPWSTR *wsz
这可能是一个非常愚蠢的问题,但这是我一直在努力解决的问题。在方法中更改 LPWSTR 后,它似乎只针对该特定方法进行更改,并在之后立即恢复。我知道全局变量是邪恶的,但这不是我的选择,因为它需要更改相当
Function CommandLineToArgvW 给了我 LPWSTR 类型的命令行参数。我需要 string 中的这些参数。有人能告诉我如何将 LPWSTR 转换为 string 吗? 我正在
我有一个 LPTSTR 类型的变量,我将其打印到 std::cout与 << 。在 ANSI 系统中(不知道它是在哪里确定的)它工作得很好,它打印了字符串。现在,在 Unicode 系统中,我得到的是
我是一名优秀的程序员,十分优秀!