Skip to content

How to specify parameters pvInfo (void*) and lpnLenghtNeeded (uint*) when calling GetUserObjectInformation? #772

Answered by AArnott
vitkuz573 asked this question in Q&A
Discussion options

You must be logged in to vote

Like this:

static bool GetCurrentDesktop([NotNullWhen(true)] out string? desktopName)
{
    using var inputDesktop = OpenInputDesktop_SafeHandle(0, true, 0x10000000);

    unsafe
    {
        const int maxLength = 256;
        fixed (char* pDesktopBytes = new char[maxLength])
        {
            uint cbLengthNeeded;
            if (!GetUserObjectInformation(inputDesktop, USER_OBJECT_INFORMATION_INDEX.UOI_NAME, pDesktopBytes, maxLength, &cbLengthNeeded))
            {
                desktopName = null;
                return false;
            }

            int charLength = (int)cbLengthNeeded / sizeof(char) - 1; // discount the null terminator
            desktopName = new string(pDe…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vitkuz573
Comment options

Answer selected by vitkuz573
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants