声明 SID Windows C++

Declare SID Windows c++

我试图将 SID 标识符传递给函数

myFunction(SID userSid) {}

我的种子是 "S-1-5-11",但我不知道如何将 SID 传递给函数

PSID sid = "S-1-5-11";
myFunction(sid);

No constructor for PSID to _SID

SID is a distinct type. It is an opaque data structure(作为 C 结构实现),不仅仅是字符串的另一个名称。

您不能将字符串传递给需要 SID 形式参数的函数。您需要创建一个 SID 对象并传递它。

有多种 API 函数可让您创建和操作 SID;他们被列为 here.

如果要从包含 a valid SID, you can call the ConvertStringSidToSid 函数的字符串创建 SID。例如:

PSID psid;
BOOL bSucceeded = ConvertStringSidToSid(TEXT("S-1-5-11"), &psid);
assert(bSucceeded != FALSE);

// ... use the SID via the pointer

// once you are finished, free it:
LocalFree(psid);