Created
August 9, 2012 07:34
-
-
Save hidori/3301996 to your computer and use it in GitHub Desktop.
SystemParametersInfo Issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace CSConsoleApplication1 | |
{ | |
class Program | |
{ | |
[UnmanagedFunctionPointer(CallingConvention.Winapi)] | |
delegate bool SystemParametersInfoDelegate(uint uiAction, uint uiParam, ref uint pvParam, uint fWinIni); | |
const uint SPI_GETFOREGROUNDLOCKTIMEOUT = 0x02000; | |
static void Main(string[] args) | |
{ | |
var module = Kernel32.LoadLibrary("User32.dll"); | |
var address = Kernel32.GetProcAddress(module, "SystemParametersInfoW"); | |
var proc = (SystemParametersInfoDelegate)Marshal.GetDelegateForFunctionPointer(address, typeof(SystemParametersInfoDelegate)); | |
var value = default(uint); | |
var result = proc(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, ref value, 0); | |
Console.WriteLine("result={0}, value={1}", result, value); | |
} | |
} | |
static class Kernel32 | |
{ | |
[DllImport("Kernel32")] | |
public static extern IntPtr LoadLibrary(string dllToLoad); | |
[DllImport("Kernel32")] | |
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); | |
[DllImport("Kernel32")] | |
public static extern bool FreeLibrary(IntPtr hModule); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment