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?
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?
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.