Skip to content

Help for use WinStationShadow Win32 function #1124

Closed Answered by dmex
szolnokit asked this question in Questions / Answers
Discussion options

You must be logged in to vote

True as WinStationShadow result

C# boolean is 4 bytes, C boolean is 1 byte. Your dllimport is missing MarshalAs(UnmanagedType.I1) so that result is incorrect.

Win32 last error: 120

Your dllimport is missing SetLastError = true. C# interop won't return the error code for the dllimport without it.

(byte)'*'

Don't cast C# chars (UTF16) to C chars (ANSI).

What I wrong?

Fix the type mashaling:

[DllImport("winsta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern Boolean WinStationShadow(IntPtr hServer, string serverName, uint targetSessionId, uint hotkeyVk, uint hotkeyModifier);

Use the correct types:

const uint KBDCTRL = …

Replies: 1 comment 1 reply

Comment options

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

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