-
Notifications
You must be signed in to change notification settings - Fork 435
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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)] |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Win32Utils has a CreateWindowStation function, but did not have any helper methods to create custom desktops via CreateDesktop and CreateDesktopEx.