Skip to content

Instantly share code, notes, and snippets.

@hidori
Created August 9, 2012 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hidori/3301996 to your computer and use it in GitHub Desktop.
Save hidori/3301996 to your computer and use it in GitHub Desktop.
SystemParametersInfo Issue
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