using System; using System.Runtime.InteropServices; namespace ConsoleApplication1 { unsafe class Program { [DllImport("user32")] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool SystemParametersInfo( UInt32 uiAction, UInt32 uiParam, [Out] out UInt32 pvParam, UInt32 fWinIni); [DllImport("user32")] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool SystemParametersInfo( UInt32 uiAction, UInt32 uiParam, IntPtr pvParam, UInt32 fWinIni); [DllImport("user32", EntryPoint = "SystemParametersInfoW")] [return: MarshalAs(UnmanagedType.Bool)] private extern static bool UnsafeSystemParametersInfo( UInt32 uiAction, UInt32 uiParam, void* pvParam, UInt32 fWinIni); private const UInt32 SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000; private const UInt32 SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001; static void Main() { UInt32 oldValue = /* dummy value*/ 5678; SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0u, out oldValue, 0u); // ☆ア Console.WriteLine("0x{0:X8} ({0:G})", oldValue); // Int32 value32; // Int64 value64 = /* dummy value */ 0x1122334455667788; // IntPtr p = Marshal.AllocHGlobal(8); // Marshal.WriteInt64(p, value64); // dummy value // SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0u, p, 0u); // ☆イ // value64 = Marshal.ReadInt64(p); // value32 = Marshal.ReadInt32(p); // Console.WriteLine("0x{0:X8} ({0:G}) / 0x{1:X8} ({1:G})", value64, value32); // Marshal.FreeHGlobal(p); // oldValue = /* dummy value*/ 0xAABBCCDDu; // UnsafeSystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0u, &oldValue, 0u); // ☆ウ // Console.WriteLine("0x{0:X8} ({0:G})", oldValue); // SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0u, (IntPtr)20003, 1u); //★エ // SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0u, (IntPtr)0x579BD, 0u); //★オ } } }