与 PSECURITY_STRING 不兼容

发布于 2024-12-21 04:13:51 字数 286 浏览 2 评论 0原文

我正在尝试使用 中的代码http://msdn.microsoft.com/en-us/library/windows/desktop/aa380536(v=VS.85).aspx

的行AcquireCredentialsHandle 表示第二个参数与 PSECURITY_STRING 不兼容。有人知道我在这里能做什么吗?

I'm trying to use code from http://msdn.microsoft.com/en-us/library/windows/desktop/aa380536(v=VS.85).aspx

The line for AcquireCredentialsHandle says that the second argument is not compatible with PSECURITY_STRING. Anyone know what I can do here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2024-12-28 04:13:51

与大多数带有字符串参数的 Win32 API 函数一样,AcquireCredentialsHandle() 映射到 AcquireCredentialsHandleA()AcquireCredentialsHandleW(),具体取决于 UNICODE 已定义,因此它分别需要 char*wchar_t* 指针。另一方面,SECURITY_STRING 是根据 UNICODE_STRING 结构 - 两者均仅包含 UTF-16 编码的 Unicode 数据。

要将 SECURITY_STRING 值传递给 AcquireCredentialsHandleA(),您需要先将 SECURITY_STRING::Buffer 成员的内容转换为 Ansi

PSECURITY_STRING str;
...
int len = WideCharToMultiByte(0, 0, (LPWSTR)str->Buffer, str->Length, NULL, 0, NULL, NULL);
std::string tmp(len);
WideCharToMultiByte(0, 0, (LPWSTR)str->Buffer, str->Length, &tmp[0], len, NULL, NULL);
AcquireCredentialsHandle(..., tmp.c_str(), ...); 

:一个 SECURITY_STRING 值到 AcquireCredentialsHandleW(),您需要传递SECURITY_STRING::Buffer 成员按原样:

PSECURITY_STRING str;
...
AcquireCredentialsHandle(..., (LPWSTR)str->Buffer, ...); 

无论哪种方式,您都不会传递指向 SECURITY_STRING 本身的指针。

Like with most Win32 API functions with string parameters, AcquireCredentialsHandle() maps to either AcquireCredentialsHandleA() or AcquireCredentialsHandleW() depending on whether UNICODE is defined, so it expects char* or wchar_t* pointers, respectively. A SECURITY_STRING, on the other hand, is a structure that is modeled after the UNICODE_STRING structure - both of which contain UTF-16 encoded Unicode data only.

To pass a SECURITY_STRING value to AcquireCredentialsHandleA(), you need to convert the contents of the SECURITY_STRING::Buffer member to Ansi first:

PSECURITY_STRING str;
...
int len = WideCharToMultiByte(0, 0, (LPWSTR)str->Buffer, str->Length, NULL, 0, NULL, NULL);
std::string tmp(len);
WideCharToMultiByte(0, 0, (LPWSTR)str->Buffer, str->Length, &tmp[0], len, NULL, NULL);
AcquireCredentialsHandle(..., tmp.c_str(), ...); 

To pass a SECURITY_STRING value to AcquireCredentialsHandleW(), you need to pass the SECURITY_STRING::Buffer member as-is:

PSECURITY_STRING str;
...
AcquireCredentialsHandle(..., (LPWSTR)str->Buffer, ...); 

Either way, you do not pass a pointer to the SECURITY_STRING itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文