![]() |
ZenWINX Architecture - Reference Manual - Guides |
|
00001 /* 00002 * ZenWINX - WIndows Native eXtended library. 00003 * Copyright (c) 2007-2010 by Dmitri Arkhangelski (dmitriar@gmail.com). 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00027 #include "ntndk.h" 00028 #include "zenwinx.h" 00029 00043 int __stdcall winx_create_event(short *name,int type,HANDLE *phandle) 00044 { 00045 UNICODE_STRING us; 00046 NTSTATUS Status; 00047 OBJECT_ATTRIBUTES oa; 00048 00049 DbgCheck3(name,(type == SynchronizationEvent) || (type == NotificationEvent), 00050 phandle,"winx_create_event",-1); 00051 *phandle = NULL; 00052 00053 RtlInitUnicodeString(&us,name); 00054 InitializeObjectAttributes(&oa,&us,0,NULL,NULL); 00055 Status = NtCreateEvent(phandle,STANDARD_RIGHTS_ALL | 0x1ff,&oa,type,1/*TRUE*/); 00056 if(Status == STATUS_OBJECT_NAME_COLLISION){ 00057 *phandle = NULL; 00058 DebugPrint("Event %ws already exists!",name); 00059 /* useful for allowing a single instance of the program */ 00060 return (signed int)(STATUS_OBJECT_NAME_COLLISION); 00061 } 00062 if(!NT_SUCCESS(Status)){ 00063 *phandle = NULL; 00064 DebugPrintEx(Status,"Cannot create %ws",name); 00065 return (-1); 00066 } 00067 return 0; 00068 } 00069 00078 int __stdcall winx_open_event(short *name,int flags,HANDLE *phandle) 00079 { 00080 UNICODE_STRING us; 00081 NTSTATUS Status; 00082 OBJECT_ATTRIBUTES oa; 00083 00084 DbgCheck2(name,phandle,"winx_open_event",-1); 00085 *phandle = NULL; 00086 00087 RtlInitUnicodeString(&us,name); 00088 InitializeObjectAttributes(&oa,&us,0,NULL,NULL); 00089 Status = NtOpenEvent(phandle,flags,&oa); 00090 if(!NT_SUCCESS(Status)){ 00091 *phandle = NULL; 00092 DebugPrintEx(Status,"Cannot open %ws",name); 00093 return (-1); 00094 } 00095 return 0; 00096 } 00097 00103 void __stdcall winx_destroy_event(HANDLE h) 00104 { 00105 if(h) NtClose(h); 00106 } 00107