/***************************************************************************** FUNCTION : KillPdump PURPOSE : PARAMETERS : RETURNS : *****************************************************************************/ static void KillPdump(void) { HANDLE hEvent; HANDLE hExitDoneEvent; /* Get a handle on the pdump finished event */ if ((hExitDoneEvent=OpenEvent(EVENT_MODIFY_STATE, IMG_FALSE, PDUMP_EXITDONE_EVENT_NAME)) == NULL) { printf("Failed to open pdump exit done event, are you sure pdump is running?\n"); return; } /* Gen a kill pdump event */ if ((hEvent=OpenEvent(EVENT_MODIFY_STATE, IMG_FALSE, PDUMP_EXIT_EVENT_NAME)) == NULL) { printf("Failed to open pdump exit event, are you sure pdump is running?\n"); return; } if (SetEvent(hEvent) == IMG_FALSE) { printf("Failed to set pdump exit event!\n"); return; } printf("Waiting for pdump to exit.....\n"); WaitForSingleObject(hExitDoneEvent, INFINITE); CloseHandle(hEvent); CloseHandle(hExitDoneEvent); return; }
void StopIPCD() { HANDLE hServerStopEvent=NULL; #ifdef TERMINAL_SERVICE char *evtname; #endif /* TERMINAL_SERVICE */ #ifdef TERMINAL_SERVICE if( osvi.dwMajorVersion >= 5 ) /* Windows 2000 */ evtname = "Global\\IPCDSTOP"; else evtname = "IPCDSTOP"; #endif /* TERMINAL_SERVICE */ #ifdef TERMINAL_SERVICE hServerStopEvent=OpenEvent( EVENT_ALL_ACCESS, FALSE, evtname ); #else hServerStopEvent=OpenEvent( EVENT_ALL_ACCESS, FALSE, "IPCDSTOP" ); #endif /* TERMINAL_SERVICE */ksh if (hServerStopEvent == NULL) { sprintf(tbuf, "IPC DAEMON is inactive ...\n"); MessageBox(NULL, tbuf, "IPC DAEMON", MB_OK); return; } SetEvent(hServerStopEvent); CloseHandle(hServerStopEvent); }
BOOL InitFernel (void) { // The fernel32 dll for the File I/O Profiler creates private data that // can't be seen by ohter processec (eg. apf32dmp). Hence, the two // processes need to communicate through shared memory (so that apf32dmp // can pass the name of the file to keep the dumped data to the fernel32 // dll) and events (so that apf32dmp can signal the fernel32 dll that a // dump or a clear of the collected data should take place // Here we create the shared memory section and open the handles to // the Dump and Clear data events. // // Note: A Dump/Clear will make all processes profiled with the // fernel32 dll dump/clear their data hDumpFileMapping = OpenFileMapping ( FILE_MAP_WRITE, FALSE, L"FileProfDumpFileName" ); wszDumpFile = (LPWSTR) MapViewOfFile ( hDumpFileMapping, FILE_MAP_WRITE, 0, 0, MAXFILENAMELEN ); hDumpEvent = OpenEvent ( EVENT_MODIFY_STATE, FALSE, L"FileProfDumpEvent" ); hClearEvent = OpenEvent ( EVENT_MODIFY_STATE, FALSE, L"FileProfClearEvent" ); return ( (hDumpFileMapping!=(HANDLE) NULL) && (wszDumpFile!=(LPWSTR) NULL) && (hDumpEvent!=(HANDLE) NULL) && (hClearEvent!=(HANDLE) NULL) ); }
CScheduler::CScheduler(int pno) : CSerialPort(pno) { char name[32]; spac_shm * shm = (spac_shm *)&ports[m_iPortNo-1]; SECURITY_DESCRIPTOR sd, *pSD; SECURITY_ATTRIBUTES sa,*_sa; this->m_iPortNo = m_iPortNo; pSD = &sd; if (pSD == NULL){ utils_error("Error creating security descriptor.\n"); return; } if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)){ utils_error("Error initializing security descriptor.\n"); return; } // Add a NULL DACL to the security descriptor.. // see MSDN Knowledge base Q106387 for detail if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)){ utils_error("Error setting security descriptor.\n"); return; } sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = pSD; sa.bInheritHandle = TRUE; _sa=&sa; sprintf(name,"rtkm_spac_event_0_%d",m_iPortNo); m_hEvents[0]=CreateEvent(_sa, 0, 0, name); if(!m_hEvents[0]){ m_hEvents[0]=OpenEvent(EVENT_ALL_ACCESS,0,name); } sprintf(name,"rtkm_spac_event_1_%d",m_iPortNo); m_hEvents[1]=CreateEvent(_sa, 0, 0, name); if(!m_hEvents[1]){ m_hEvents[1]=OpenEvent(EVENT_ALL_ACCESS,0,name); } shm->is_open=false; if(!m_hEvents[0] || !m_hEvents[1]){ utils_error( ">> COM%d, Error creating event, code %d.\n", m_iPortNo, GetLastError() ); m_hEvents[0]? CloseHandle(m_hEvents[0]) : 0; m_hEvents[1]? CloseHandle(m_hEvents[1]) : 0; return; } ports[m_iPortNo-1].port_no=m_iPortNo; }
BOOL CreateWow64Events(DWORD pid, HANDLE *hParent, HANDLE *hChild, BOOL bOpenExisting) { SECURITY_ATTRIBUTES sa; char parentname[256],childname[256]; *hParent = *hChild = NULL; // make darn sure they're not inherited sa.nLength = sizeof(sa); sa.lpSecurityDescriptor =0; sa.bInheritHandle = FALSE; // #pragma warning(disable:4995) // This event tells the child to hold for gForkData to be copied wsprintfA(parentname, "Local\\%d-%s",pid, TCSH_WOW64_PARENT_EVENT_NAME); wsprintfA(childname, "Local\\%d-%s",pid, TCSH_WOW64_CHILD_EVENT_NAME ); #pragma warning(default:4995) *hParent = OpenEvent(EVENT_ALL_ACCESS,FALSE, parentname); if(*hParent) { if (bOpenExisting == FALSE) { // didn't expect to be a child process CloseHandle(*hParent); *hParent = NULL; return FALSE; } *hChild = OpenEvent(EVENT_ALL_ACCESS,FALSE, childname); if (!*hChild) { CloseHandle(*hParent); *hParent = NULL; return FALSE; } return TRUE; } else { //event does not exist if (bOpenExisting == TRUE) return FALSE; } *hParent = CreateEvent(&sa,FALSE,FALSE,parentname); if (!*hParent) return FALSE; *hChild = CreateEvent(&sa,FALSE,FALSE,childname); if (!*hChild){ CloseHandle(*hParent); *hParent = NULL; return FALSE; } return TRUE; }
DWORD __stdcall MonitorThread(VOID* Parameter) { HANDLE processEvent; HANDLE d3dImageEvent; VOID *handles[2]; processEvent = OpenEvent(L"Global\\" PUSH_PROCESS_EVENT_NAME); d3dImageEvent = OpenEvent(L"Global\\" PUSH_IMAGE_EVENT_NAME); handles[0] = processEvent; handles[1] = d3dImageEvent; while (processEvent) { NTSTATUS result; HANDLE threadHandle; result = NtWaitForMultipleObjects(2, &handles[0], WaitAny, FALSE, NULL); if (processEvent && handles[result - STATUS_WAIT_0] == processEvent) { NtCreateThreadEx( &threadHandle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(), &RetrieveProcessEvent, NULL, NoThreadFlags, 0, 0, 0, NULL ); } else if (handles[result - STATUS_WAIT_0] == d3dImageEvent) { NtCreateThreadEx( &threadHandle, THREAD_ALL_ACCESS, NULL, NtCurrentProcess(), &RetrieveImageEvent, NULL, NoThreadFlags, 0, 0, 0, NULL ); } } return 0; }
/* in : val 0 or 1 (コントローラとの併用 : 1) */ void InitMemCard(long val) { InitCARD(val); /* 通常 val=1 : コントローラと併用 */ StartCARD(); _bu_init(); ChangeClearPAD(0); EnterCriticalSection(); ev0 = OpenEvent(SwCARD, EvSpIOE, EvMdNOINTR, NULL); ev1 = OpenEvent(SwCARD, EvSpERROR, EvMdNOINTR, NULL); ev2 = OpenEvent(SwCARD, EvSpTIMOUT, EvMdNOINTR, NULL); ev3 = OpenEvent(SwCARD, EvSpNEW, EvMdNOINTR, NULL); ev10 = OpenEvent(HwCARD, EvSpIOE, EvMdNOINTR, NULL); ev11 = OpenEvent(HwCARD, EvSpERROR, EvMdNOINTR, NULL); ev12 = OpenEvent(HwCARD, EvSpTIMOUT, EvMdNOINTR, NULL); ev13 = OpenEvent(HwCARD, EvSpNEW, EvMdNOINTR, NULL); ExitCriticalSection(); EnableEvent(ev0); EnableEvent(ev1); EnableEvent(ev2); EnableEvent(ev3); EnableEvent(ev10); EnableEvent(ev11); EnableEvent(ev12); EnableEvent(ev13); }
int main() { HANDLE isWait=OpenEvent(EVENT_MODIFY_STATE, FALSE, "test"); SetEvent(isWait); getchar(); return 0; }
bool APIDataReceiver::startup() { if(!memMapFileHandle) { memMapFileHandle = OpenFileMapping( FILE_MAP_READ, FALSE, IRSDK_MEMMAPFILENAME); lastTickCount = std::numeric_limits<int>::max(); } if(memMapFileHandle) { if(!sharedMem) { sharedMem = static_cast<const char*>(MapViewOfFile(memMapFileHandle, FILE_MAP_READ, 0, 0, 0)); header = reinterpret_cast<const irsdk_header*>(sharedMem); lastTickCount = std::numeric_limits<int>::max(); } if(sharedMem) { if(!dataValidEventHandle) { dataValidEventHandle = OpenEvent(SYNCHRONIZE, false, IRSDK_DATAVALIDEVENTNAME); lastTickCount = std::numeric_limits<int>::max(); } if(dataValidEventHandle) { initialized = true; return true; } } } initialized = false; return false; }
bool CMSWindowsKeyState::fakeCtrlAltDel() { if (!m_is95Family) { // to fake ctrl+alt+del on the NT family we broadcast a suitable // hotkey to all windows on the winlogon desktop. however, the // current thread must be on that desktop to do the broadcast // and we can't switch just any thread because some own windows // or hooks. so start a new thread to do the real work. HANDLE hEvtSendSas = OpenEvent( EVENT_MODIFY_STATE, FALSE, "Global\\SendSAS" ); if ( hEvtSendSas ) { LOG((CLOG_DEBUG "found the SendSAS event - signaling my launcher to simulate ctrl+alt+del")); SetEvent( hEvtSendSas ); CloseHandle( hEvtSendSas ); } else { CThread cad(new CFunctionJob(&CMSWindowsKeyState::ctrlAltDelThread)); cad.wait(); } } else { // simulate ctrl+alt+del fakeKeyDown(kKeyDelete, KeyModifierControl | KeyModifierAlt, virtualKeyToButton(VK_DELETE)); } return true; }
bool resetSyncAborted() { HANDLE syncAbortEvent = NULL; bool ret = false; syncAbortEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("Global\\AbortSyncEvent")); if (syncAbortEvent == NULL) { DWORD err = GetLastError(); // if event wasn't created don't log any error: if (err != ERROR_FILE_NOT_FOUND) { LOG.error("%s: error opening sync abort event: %d", __FUNCTION__, err); } return ret; } if (! ResetEvent(syncAbortEvent) ) { LOG.error("%s: error resetting cancelled sync event handle", __FUNCTION__); ret = false; } CloseHandle(syncAbortEvent); return ret; }
void xampp_stop(char *pidfile,char *eventformat) { HANDLE shutdownEvent; char shutdownEventName[32]; FILE *fp; long pid; fp=fopen(pidfile,"r"); if(!fp) { printf("Can't find %s.\n", pidfile); } else { fscanf(fp,"%d", &pid); fclose(fp); sprintf_s(shutdownEventName, sizeof(shutdownEventName), eventformat, pid); shutdownEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, shutdownEventName); if (shutdownEvent != NULL) { SetEvent(shutdownEvent); } else { printf("Can't find process #%d.\n", pid); } } }
static int OCAC_PWrkStop(OCACProc *pProc) { HANDLE hCREvt; BOOL bResult; int nProcExit = CA_PROC_EXIT_OK; hCREvt = OpenEvent(EVENT_ALL_ACCESS,TRUE, OCASS_EVT_NAME_SHELL_WRK); if (NULL == hCREvt) { nProcExit = CA_PROC_EXIT_FATAL; OCAC_Panic(CA_SRC_MARK, TEXT("Can't open event %s. system error %u"), OCASS_EVT_NAME_SPY_RUN, GetLastError()); goto EXIT; } bResult = SetEvent(hCREvt); CloseHandle(hCREvt); if (!bResult) { nProcExit = CA_PROC_EXIT_FATAL; OCAC_Panic(CA_SRC_MARK, TEXT("Set event %s failed. system error %u"), OCASS_EVT_NAME_SPY_RUN, GetLastError()); goto EXIT; } OCAC_PrintMsgLine(TEXT("Send shutdown event successed")); EXIT: return nProcExit; }
ngx_int_t ngx_os_signal_process(ngx_cycle_t *cycle, char *sig, ngx_int_t pid) { HANDLE ev; ngx_int_t rc; char evn[NGX_PROCESS_SYNC_NAME]; ngx_sprintf((u_char *) evn, "Global\\ngx_%s_%ul%Z", sig, pid); ev = OpenEvent(EVENT_MODIFY_STATE, 0, evn); if (ev == NULL) { ngx_log_error(NGX_LOG_ERR, cycle->log, ngx_errno, "OpenEvent(\"%s\") failed", evn); return 1; } if (SetEvent(ev) == 0) { ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, "SetEvent(\"%s\") failed", evn); rc = 1; } else { rc = 0; } ngx_close_handle(ev); return rc; }
DWORD CMySql::StopExe() { DWORD dwRetour = ERROR_SUCCESS; HANDLE hEventShutdown = NULL; char szShutdownEvent[31] = {0}; _snprintf(szShutdownEvent, sizeof(szShutdownEvent)-1, "MySQLShutdown%u", GetProcID()); CUtils::Log("MySqlSutdown event = %s", szShutdownEvent); if ((hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, szShutdownEvent)) != NULL) { SetEvent(hEventShutdown); CloseHandle(hEventShutdown); } else { dwRetour = GetLastError(); CUtils::Log("MySqlSutdown event open fail = %d", dwRetour); // if (dwRetour==ERROR_FILE_NOT_FOUND || ) { char szToExecute[MAX_PATH+50] = {0}; _snprintf(szToExecute, sizeof(szToExecute)-1, "%sbin\\mysqladmin.exe -u root shutdown", (LPCTSTR) m_sMySqlPath); dwRetour = WinExec(szToExecute, SW_HIDE); if (dwRetour > 31) dwRetour = ERROR_SUCCESS; } } return dwRetour; }
void CommThread(void *arg) { DWORD Evt; PComVar cv = (PComVar)arg; DWORD DErr; HANDLE REnd; char Temp[20]; _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%s%d", READENDNAME, cv->ComPort); REnd = OpenEvent(EVENT_ALL_ACCESS,FALSE, Temp); while (TRUE) { if (WaitCommEvent(cv->ComID,&Evt,NULL)) { if (! cv->Ready) { _endthread(); } if (! cv->RRQ) { PostMessage(cv->HWin, WM_USER_COMMNOTIFY, 0, FD_READ); } WaitForSingleObject(REnd,INFINITE); } else { DErr = GetLastError(); // this returns 995 (operation aborted) if a USB com port is removed if (! cv->Ready || ERROR_OPERATION_ABORTED == DErr) { _endthread(); } ClearCommError(cv->ComID,&DErr,NULL); } } }
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { if(dwReason == DLL_PROCESS_ATTACH) { // make sure advapi32 is loaded LoadLibrary("advapi32"); // there's a small list of processes which we don't want to inject if(is_ignored_process()) { return TRUE; } // hide our module from peb hide_module_from_peb(hModule); // obtain all protected pids int pids[MAX_PROTECTED_PIDS], length = sizeof(pids); pipe2(pids, &length, "GETPIDS"); for (int i = 0; i < length / sizeof(pids[0]); i++) { add_protected_pid(pids[i]); } // initialize file stuff file_init(); // read the config settings read_config(); g_pipe_name = g_config.pipe_name; // initialize the log file log_init(g_config.host_ip, g_config.host_port, 0); // initialize the Sleep() skipping stuff init_sleep_skip(g_config.first_process); // we skip a random given amount of milliseconds each run init_startup_time(g_config.startup_time); // disable the retaddr check if the user wants so if(g_config.retaddr_check == 0) { hook_disable_retaddr_check(); } // initialize all hooks set_hooks(); // notify analyzer.py that we've loaded char name[64]; sprintf(name, "CuckooEvent%d", GetCurrentProcessId()); HANDLE event_handle = OpenEvent(EVENT_ALL_ACCESS, FALSE, name); if(event_handle != NULL) { SetEvent(event_handle); CloseHandle(event_handle); } } else if(dwReason == DLL_PROCESS_DETACH) { log_free(); } return TRUE; }
unsigned __stdcall SendThread( void* Param ) { //--------------------------------------------------------- ClientInfo* ciData = (ClientInfo*) Param; #ifdef _SCROUT_ cout << "SendThread" << endl; cout << "Got " << ciData->dpMessage.dPackage.nNum << " of bread!" << endl; #endif HANDLE hEvent = OpenEvent( EVENT_ALL_ACCESS, FALSE, L"ZZRTY-ARARA-03" ); //-------------------------------------------------------- char* pMess = new char[ciData->zBuff.nSize]; //allocate memory memcpy( pMess, ciData->zBuff.pSend, ciData->zBuff.nSize ); //get decoded data here SetEvent( hEvent ); //--------------------------------------------------------- int nSent = send( ciData->sSock, pMess, ciData->zBuff.nSize, 0 ); if( nSent == -1 ) { cout << "Error!" << endl; return 0; } //--------------------------------------------------------- delete pMess; delete ciData; ciData = NULL; pMess = NULL; //--------------------------------------------------------- return 0; }
void open() { if (hEvent) CloseHandle(hEvent); hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE,name_.empty()?NULL:name_.c_str()); if (hEvent == NULL) throw event_exception(_T("Failed to create ") + name_ + _T(" event: ") + error::lookup::last_error()); }
//*================================================================================= //*原型: void TServer::EndService(LPCTSTR pszServiceName) //*功能: 终止服务 //*参数: pszServiceName -- 服务名称 //*返回: 无 //*说明: WINNT服务器基类 //*================================================================================= void TServer::EndService(LPCTSTR pszServiceName) { // SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; HANDLE hShutdown = OpenEvent(EVENT_MODIFY_STATE, FALSE, "__SMART_SERVER_SHUTDOWN__"); if( hShutdown != NULL ) { PostQuitMessage(0); SetEvent(hShutdown); Sleep(5000); CloseHandle(hShutdown); } else { PostQuitMessage(0); SetEvent(hShutdown); TCHAR sErrorText[256]; DWORD nErrorCode = GetLastError(); lstrcpy(sErrorText, "不能停止服务!"); WriteLog(sErrorText); MessageBox(NULL, sErrorText, SERVICE_TITLE, MB_OK|MB_ICONINFORMATION); } }
void st_event_producer_test(void) { P_ST_MEMMAP_T p_token = NULL; p_token = st_memmap_open("RPC_SHARE", 1, 1); char* ptr = p_token->location; *ptr = '\0'; char buf[512]; if (!p_token) return; P_ST_WINSYNC_T p_event = (P_ST_WINSYNC_T)OpenEvent(0, 0, "RPC_EVENT"); int i = 0, nloop = 100; WAIT_FOR_ENTER; /* back to parent process */ for (i = 0; i < nloop; i++) { snprintf(buf, sizeof(buf), "THIS IS MESSAGE: ID-%d", i); lseek(p_token->fd, 0, SEEK_SET); write(p_token->fd, buf, strlen(buf)+1); st_print("POSTING:%s\n", buf); SetEvent(p_event); } st_memmap_close(p_token); CloseHandle(p_event); st_winsync_destroy(p_event); }
extern "C" __declspec(dllexport) void entryPoint() { #ifdef _DEBUG OutputDebugString("entryPoint called"); #endif HANDLE hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENTNAME); if (!hEvent) displayError(L"Could not open interprocess communication event."); WCHAR pwszError[ERROR_BUFFER_SIZE]; if (!validateVersion()) displayError(L"You must at least have Microsoft Windows XP to use this library."); if (!CRawInput::initialize(pwszError)) displayError(pwszError); if (!CRawInput::hookLibrary(true)) displayError(L"Failed to hook Windows API cursor functions."); // Signal the injector that the injection and hooking are successful if (!SetEvent(hEvent)) displayError(L"Failed to signal the initialization event."); CloseHandle(hEvent); if (!CRawInput::pollInput()) displayError(L"Failed to poll mouse input"); #ifdef _DEBUG OutputDebugString("Finished entryPoint"); #endif }
static int DdeModulesLoaded2(WPARAM, LPARAM) { /* create message window */ WNDCLASS wcl; wcl.lpfnWndProc = DdeMessageWindow; wcl.cbClsExtra = 0; wcl.cbWndExtra = 0; wcl.hInstance = hInst; wcl.hCursor = NULL; wcl.lpszClassName = WNDCLASS_DDEMSGWINDOW; wcl.hbrBackground = NULL; wcl.hIcon = NULL; wcl.lpszMenuName = NULL; wcl.style = 0; RegisterClass(&wcl); /* Note: use of HWND_MESSAGE does not fit for DDE as the window must be a top-level one */ hwndDdeMsg = CreateWindow(WNDCLASS_DDEMSGWINDOW, NULL, 0, 0, 0, 0, 0, NULL, NULL, hInst, NULL); /* make known dde startup code is passed */ HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, WNDCLASS_DDEMSGWINDOW); if (hEvent != NULL) { SetEvent(hEvent); CloseHandle(hEvent); } CleanupRegTreeBackupSettings(); CleanupMimeTypeAddedSettings(); CleanupAssocEnabledSettings(); return 0; }
//--------------------------------------------------------------------------- // Puts up the standard file.run dialog. // REVIEW UNDONE This should use a RUNDLG structure for all the various // options instead of just passing them as parameters, a ptr to the struct // would be passed to the dialog via the lParam. int WINAPI RunFileDlg(HWND hwndParent, HICON hIcon, LPCTSTR lpszWorkingDir, LPCTSTR lpszTitle, LPCTSTR lpszPrompt, DWORD dwFlags) { RUNDLG_DATA rd; rd.hIcon = hIcon; rd.lpszWorkingDir = lpszWorkingDir; rd.lpszTitle = lpszTitle; rd.lpszPrompt = lpszPrompt; rd.dwFlags = dwFlags; rd.hEventReady = 0; rd.dwThreadId = 0; // We do this so we can get type-ahead when we're running on a // seperate thread. The parent thread needs to block to give us time // to do the attach and then get some messages out of the queue hence // the event. if (hwndParent) { // HACK The parent signals it's waiting for the dialog to grab type-ahead // by sticking it's threadId in a property on the parent. rd.dwThreadId = (DWORD)GetProp(hwndParent, c_szWaitingThreadID); if (rd.dwThreadId) { // DebugMsg(DM_TRACE, "s.rfd: Attaching input to %x.", idThread); AttachThreadInput(GetCurrentThreadId(), rd.dwThreadId, TRUE); // NB Hack. rd.hEventReady = OpenEvent(EVENT_ALL_ACCESS, TRUE, c_szRunDlgReady); } } return DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_RUN), hwndParent, RunDlgProc, (LPARAM)(LPRUNDLG_DATA)&rd); }
DWORD WINAPI CDateTime::PollDateTime(LPVOID lpParameter) { CDateTime* p_this = (CDateTime*)lpParameter; HANDLE hEvents[1]; hEvents[0] = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_FLIPPEREXIT); DWORD dwEvent = 0; DWORD dwSleep = 1000 * 60; while (WAIT_ABANDONED_0 != (dwEvent = WaitForMultipleObjects(ARRAYSIZE(hEvents), hEvents, FALSE, dwSleep))) { // Update weather here if (dwEvent == WAIT_OBJECT_0) { break; } else { SYSTEMTIME st; GetLocalTime(&st); dwSleep = 1000 * (60 - st.wSecond); p_this->g_pFlipper->Redraw(p_this->g_pPlugin, &(p_this->g_dateNode), 1); } } CloseHandle(hEvents[0]); return 0; }
/* * CreateMetSectEvent */ BOOL CreateMetSectEvent(LPMETERED_SECTION lpMetSect, LPCTSTR lpName, BOOL bOpenOnly) { TCHAR sz[MAX_PATH]; if (lpName) { wsprintf(sz, _TEXT("DKC_MSECT_EVT_%s"), lpName); #ifndef _WIN32_WCE if (bOpenOnly) { lpMetSect->hEvent = OpenEvent(0, FALSE, sz); } else { #endif // Create an auto-reset named event object lpMetSect->hEvent = CreateEvent(NULL, FALSE, FALSE, sz); #ifndef _WIN32_WCE } #endif } else { // Create an auto-reset unnamed event object lpMetSect->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); } return (lpMetSect->hEvent ? TRUE : FALSE); }
int InitPlugin(char* data, int obj_id, HANDLE ExitEvent) { DieEvent=ExitEvent; MenuXml.Parse(data,"item"); xml* child; for(int i=0; i<MenuXml.vec.RealCount; i++) { child=MenuXml.vec[i]; if(child->name!=NULL) { if(!_stricmp(child->name,"CallEvent")) { child=MenuXml.GetItemOnlyChild(child,"Name",1); HANDLE h=OpenEvent(EVENT_MODIFY_STATE,0,child->subtext); if(h==NULL) { CString err; err="Handle for "; err.Append(child->subtext); err.Append(" could not be opened!"); ShowError(err); } else SetEvent(h); } } } return 1; }
void LogWr::init() { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); sa.bInheritHandle = FALSE; sa.lpSecurityDescriptor = 0; //创建内存映射文件,得到缓存 wchar_t buf[20] = {0}; wchar_t *id = L"LogWr"; if (m_hMemFile == 0){ //int id = GetCurrentProcessId(); swprintf_s(buf, sizeof(buf)/sizeof(buf[0]), L"File-%s", id); m_hMemFile = OpenFileMapping(PAGE_READWRITE, FALSE, buf); if (m_hMemFile == 0){ m_hMemFile = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, MEMFILE_SIZE, buf); } m_pBuffer = (char*)MapViewOfFile(m_hMemFile, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (m_pBuffer == 0) throw; } swprintf_s(buf, sizeof(buf)/sizeof(buf[0]), L"Event-%s", id); m_hReadEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, buf); if (m_hReadEvent == 0){ m_hReadEvent = CreateEvent(&sa, TRUE, FALSE, buf); } SetEvent(m_hReadEvent); //表示这里已经创建了内存映射文件 }
// Open the adapter SU_ADAPTER *SuOpenAdapter(SU *u, char *adapter_id) { char filename[MAX_PATH]; void *h; SU_ADAPTER *a; SL_IOCTL_EVENT_NAME t; UINT read_size; // Validate arguments if (u == NULL || adapter_id == NULL) { return NULL; } Format(filename, sizeof(filename), SL_ADAPTER_DEVICE_FILENAME_WIN32, adapter_id); h = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (h == INVALID_HANDLE_VALUE) { Debug("Create File %s failed. %u\n", filename, GetLastError()); return NULL; } else { Debug("Create File %s ok.\n", filename); } a = ZeroMalloc(sizeof(SU_ADAPTER)); StrCpy(a->AdapterId, sizeof(a->AdapterId), adapter_id); StrCpy(a->DeviceName, sizeof(a->DeviceName), filename); a->hFile = h; Zero(&t, sizeof(t)); // Get the event name if (DeviceIoControl(h, SL_IOCTL_GET_EVENT_NAME, &t, sizeof(t), &t, sizeof(t), &read_size, NULL) == false) { // Acquisition failure SuCloseAdapter(a); return NULL; } Debug("Event Name: %s\n", t.EventNameWin32); // Get the event a->hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, t.EventNameWin32); if (a->hEvent == NULL) { // Acquisition failure SuCloseAdapter(a); return NULL; } return a; }
bool CWaitingSignal::Open(LPCTSTR signalName) { ASSERT(m_hSignal==NULL); if(signalName) m_signalName=signalName; else return false; m_hSignal=OpenEvent(EVENT_ALL_ACCESS,false,signalName); return m_hSignal!=NULL; }