Play with Bindings

来源:互联网 发布:macbook音乐剪辑软件 编辑:程序博客网 时间:2024/06/04 18:10
D语言是新兴语言。个人感觉相当友善,而且更新速度快。下面是做一个简单的列出进程的程序是tlhelp32的bindingwindows/core.d绑定代码,略有冗余module windows.core;import std.c.windows.windows;enum{DELETE= 0x00010000L,READ_CONTROL = 0x00020000L,SYNCHRONIZE = 0x00100000L,//Required to wait for the process to terminate using the wait functions.WRITE_DAC = 0x00040000L,WRITE_OWNER = 0x00080000L,}enum{PROCESS_ALL_ACCESS = 0x1F0FFF,// All possible access rights for a process object.PROCESS_CREATE_PROCESS = 0x0080,// Required to create a process.PROCESS_CREATE_THREAD = 0x0002,// Required to create a thread.PROCESS_DUP_HANDLE = 0x0040, // Required to duplicate a handle using DuplicateHandle.PROCESS_QUERY_INFORMATION = 0x0400,// Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob).PROCESS_QUERY_LIMITED_INFORMATION = 0x1000,// Required to retrieve certain information about a process (see QueryFullProcessImageName).PROCESS_SET_QUOTA = 0x0100,// Required to set memory limits using SetProcessWorkingSetSize.PROCESS_SET_INFORMATION = 0x0200,// Required to set certain information about a process, such as its priority class (see SetPriorityClass).PROCESS_SUSPEND_RESUME = 0x0800, // Required to suspend or resume a process.PROCESS_TERMINATE = 0x0001,// Required to terminate a process using TerminateProcess.PROCESS_VM_OPERATION = 0x0008, // Required to perform an operation on the address space of a process (see VirtualProtectEx and WriteProcessMemory).PROCESS_VM_READ = 0x0010, // Required to read memory in a process using ReadProcessMemory.PROCESS_VM_WRITE = 0x0020, // Required to write to memory in a process using WriteProcessMemory.}enum{TH32CS_SNAPHEAPLIST = 0x00000001,TH32CS_SNAPPROCESS = 0x00000002,TH32CS_SNAPTHREAD = 0x00000004,TH32CS_SNAPMODULE = 0x00000008,TH32CS_SNAPMODULE32 = 0x00000010,TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST|TH32CS_SNAPPROCESS|TH32CS_SNAPTHREAD|TH32CS_SNAPMODULE),TH32CS_INHERIT = 0x80000000,}typedef char TCHAR;struct PROCESSENTRY32 { DWORD dwSize; DWORD cntUsage; DWORD th32ProcessID; DWORD th32DefaultHeapID; DWORD th32ModuleID; DWORD cntThreads; DWORD th32ParentProcessID; LONG pcPriClassBase; DWORD dwFlags; TCHAR szExeFile[MAX_PATH]; DWORD th32MemoryBase; DWORD th32AccessKey; }; typedef PROCESSENTRY32* PPROCESSENTRY32; typedef PROCESSENTRY32* LPPROCESSENTRY32; export extern (Windows){ DWORD GetWindowThreadProcessId( // The return value is the identifier of the thread that created the window. HWND hWnd,// Handle to the window. LPDWORD lpdwProcessId// Pointer to a variable that receives the process identifier. );HWND FindWindowEx( HWND hwndParent,//Handle to the parent window whose child windows are to be searched. HWND hwndChildAfter,//Handle to a child window. LPCTSTR lpszClass,//Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. LPCTSTR lpszWindow//Pointer to a null-terminated string that specifies the window name (the window's title).);HWND FindWindow( LPCTSTR lpClassName,//Pointer to a null-terminated string that specifies the class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. LPCTSTR lpWindowName//Pointer to a null-terminated string that specifies the window name (the window's title).);BOOL Process32First( HANDLE hSnapshot, //Handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function. LPPROCESSENTRY32 lppe //Pointer to a PROCESSENTRY32 structure.);BOOL Process32Next( HANDLE hSnapshot,// Handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function. LPPROCESSENTRY32 lppe// Pointer to a PROCESSENTRY32 structure.);HANDLE CreateToolhelp32Snapshot( DWORD dwFlags, //Portions of the system to include in the snapshot. DWORD th32ProcessID //Process identifier of the process to be included in the snapshot.);HANDLE OpenProcess( DWORD dwDesiredAccess,//The access to the process object. BOOL bInheritHandle,//If this value is TRUE, processes created by this process will inherit the handle. Otherwise, the processes do not inherit this handle. DWORD dwProcessId//The identifier of the local process to be opened.);}列出我们的进程哦~import std.c.windows.windows;import std.stdio;import windows.core;void main(){HWND a;PROCESSENTRY32 lppe;a=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);writefln(a);lppe.dwSize=PROCESSENTRY32.sizeof; if (Process32First(a, cast(LPPROCESSENTRY32)&lppe) )writefln ("hello");while( Process32Next(a,cast(LPPROCESSENTRY32)&lppe) ){printf("%s/n",&lppe.szExeFile);}}
原创粉丝点击