Files
Yaulw/Win32/Structures.cs
2016-02-15 12:32:26 -05:00

167 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace Yaulw.Win32
{
/// <summary>
/// Win32 Structs
/// </summary>
public static class Structures
{
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public static RECT FromXYWH(int x, int y, int width, int height)
{
RECT rect = new RECT();
rect.left = x;
rect.top = y;
rect.right = x + width;
rect.bottom = y + height;
return rect;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SIZE
{
public int cx;
public int cy;
}
[StructLayout(LayoutKind.Sequential)]
public struct ShellExecuteInfo
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
public string lpVerb;
public string lpFile;
public string lpParameters;
public string lpDirectory;
public uint nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
public string lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon_Monitor; // union DUMMYUNIONNAME
public IntPtr hProcess;
}
[StructLayout(LayoutKind.Explicit, Size = 28)]
public struct INPUT
{
[FieldOffset(0)]
public uint type;
[FieldOffset(4)]
public KEYBDINPUT ki;
};
[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
public ushort wVk;
public ushort wScan;
public uint dwFlags;
public long time;
public uint dwExtraInfo;
};
[StructLayout(LayoutKind.Sequential)]
public struct MONITORINFOEX
{
public int cbSize;
public RECT rcMonitor;
public RECT rcWork;
public int dwFlags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string szDeviceName;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct PAINTSTRUCT
{
public IntPtr hdc;
public int fErase;
public RECT rcPaint;
public int fRestore;
public int fIncUpdate;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public byte[] rgbReserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct NCCALCSIZE_PARAMS
{
public RECT rgrc0, rgrc1, rgrc2;
public IntPtr lppos;
}
[StructLayout(LayoutKind.Sequential)]
public struct SERVICE_STATUS_PROCESS
{
public int dwServiceType;
public int dwCurrentState;
public int dwControlsAccepted;
public int dwWin32ExitCode;
public int dwServiceSpecificExitCode;
public int dwCheckPoint;
public int dwWaitHint;
public int dwProcessId;
public int dwServiceFlags;
}
[StructLayout(LayoutKind.Sequential)]
public struct FileDescriptorSet
{
// how many are set?
public int Count;
// an array of Socket handles
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxCount)]
public IntPtr[] Array;
public static readonly int Size = Marshal.SizeOf(typeof(FileDescriptorSet));
public static readonly FileDescriptorSet Empty = new FileDescriptorSet(0);
public const int MaxCount = 64;
public FileDescriptorSet(int count)
{
Count = count;
Array = count == 0 ? null : new IntPtr[MaxCount];
}
}
/// <summary>
/// Structure used in select() call, taken from the BSD file sys/time.h.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct TimeValue
{
public int Seconds; // seconds
public int Microseconds; // and microseconds
}
[StructLayout(LayoutKind.Sequential)]
public struct WSAData
{
public short wVersion;
public short wHighVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 257)]
public string szDescription;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 129)]
public string szSystemStatus;
public short iMaxSockets;
public short iMaxUdpDg;
public int lpVendorInfo;
}
}
}