Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functions to create custom desktops with CreateDesktop and CreateDesktopEx #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ashley-pillay
Copy link

Win32Utils has a CreateWindowStation function, but did not have any helper methods to create custom desktops via CreateDesktop and CreateDesktopEx.

Copy link
Collaborator

@tyranid tyranid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. There's a few changes which would be good to implement. Thanks.

@@ -1336,6 +1336,27 @@ SafeKernelObjectHandle hTemplateFile
SECURITY_ATTRIBUTES lpsa
);

[DllImport("user32.dll", EntryPoint = "CreateDesktop", CharSet = CharSet.Unicode, SetLastError = true)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to specify the EntryPoint property.

SECURITY_ATTRIBUTES attributes);

[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern SafeKernelObjectHandle CreateDesktopEx(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just define the Ex version which is supported on Vista+, no need to specify both versions of the function.

IntPtr device, // must be null.
IntPtr deviceMode, // must be null,
int flags, // use 0
AccessMask dwDesiredAccess,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use DesktopAccessRights for this type rather than AccessMask.

int flags, // use 0
AccessMask dwDesiredAccess,
SECURITY_ATTRIBUTES attributes,
ulong heapSize,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the definition of the function the heapSize is ULONG, which is 32-bit in the native APIs. ulong in C# is 64bit. Use int or uint instead.

/// <returns>The Desktop.</returns>
public static NtDesktop CreateDesktop(string name)
{
var handle = Win32NativeMethods.CreateDesktop(name, IntPtr.Zero, IntPtr.Zero, 0, WindowStationAccessRights.MaximumAllowed, null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call the CreateDesktop(string name, ulong heapsize) to use the Ex version of the function with the heapsize set to 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants