-
Notifications
You must be signed in to change notification settings - Fork 439
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1336,6 +1336,27 @@ internal static extern SafeKernelObjectHandle CreateWindowStation( | |
SECURITY_ATTRIBUTES lpsa | ||
); | ||
|
||
[DllImport("user32.dll", EntryPoint = "CreateDesktop", CharSet = CharSet.Unicode, SetLastError = true)] | ||
internal static extern SafeKernelObjectHandle CreateDesktop( | ||
string desktopName, | ||
IntPtr device, // must be null. | ||
IntPtr deviceMode, // must be null, | ||
int flags, // use 0 | ||
AccessMask dwDesiredAccess, | ||
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 commentThe 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. |
||
string desktopName, | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd use |
||
SECURITY_ATTRIBUTES attributes, | ||
ulong heapSize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the definition of the function the |
||
IntPtr pVoid); | ||
|
||
|
||
[DllImport("kernel32.dll", SetLastError = true)] | ||
internal static extern SafeKernelObjectHandle CreateRemoteThreadEx( | ||
SafeKernelObjectHandle hProcess, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,35 @@ public static NtWindowStation CreateWindowStation(string name) | |
return new NtWindowStation(handle); | ||
} | ||
|
||
/// <summary> | ||
/// This creates a Desktop using the User32 API. | ||
/// </summary> | ||
/// <param name="name">The name of the Desktop.</param> | ||
/// <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 commentThe reason will be displayed to describe this comment to others. Learn more. Call the |
||
if (handle.IsInvalid) | ||
throw new SafeWin32Exception(); | ||
return new NtDesktop(handle); | ||
} | ||
|
||
/// <summary> | ||
/// This creates a Desktop using the User32 API. | ||
/// </summary> | ||
/// <param name="name">The name of the Desktop.</param> | ||
/// <param name="heapSize">The size of the desktop heap, in kilobytes.</param> | ||
/// <returns>The Desktop.</returns> | ||
public static NtDesktop CreateDesktop(string name, ulong heapSize) | ||
{ | ||
var handle = Win32NativeMethods.CreateDesktopEx(name, IntPtr.Zero, IntPtr.Zero, 0, WindowStationAccessRights.MaximumAllowed, null, heapSize, | ||
IntPtr.Zero); | ||
if (handle.IsInvalid) | ||
throw new SafeWin32Exception(); | ||
return new NtDesktop(handle); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Create a remote thread. | ||
/// </summary> | ||
|
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.