这篇教程C++ CreateMutexW函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CreateMutexW函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateMutexW函数的具体用法?C++ CreateMutexW怎么用?C++ CreateMutexW使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CreateMutexW函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: Pimpl Pimpl (String name, const int timeOutMillisecs) : handle (0), refCount (1) { name = name.replaceCharacter ('//', '/'); handle = CreateMutexW (0, TRUE, ("Global//" + name).toWideCharPointer()); // Not 100% sure why a global mutex sometimes can't be allocated, but if it fails, fall back to // a local one. (A local one also sometimes fails on other machines so neither type appears to be // universally reliable) if (handle == 0) handle = CreateMutexW (0, TRUE, ("Local//" + name).toWideCharPointer()); if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS) { if (timeOutMillisecs == 0) { close(); return; } switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs)) { case WAIT_OBJECT_0: case WAIT_ABANDONED: break; case WAIT_TIMEOUT: default: close(); break; } } }
开发者ID:baeksanchang,项目名称:juce,代码行数:33,
示例2: winpidgin_set_runningstatic BOOL winpidgin_set_running(BOOL fail_if_running) { HANDLE h; if ((h = CreateMutexW(NULL, FALSE, L"pidgin_is_running"))) { DWORD err = GetLastError(); if (err == ERROR_ALREADY_EXISTS) { if (fail_if_running) { HWND msg_win; printf("An instance of Pidgin is already running./n"); if((msg_win = FindWindowExW(NULL, NULL, L"WinpidginMsgWinCls", NULL))) if(SendMessage(msg_win, PIDGIN_WM_FOCUS_REQUEST, (WPARAM) NULL, (LPARAM) NULL)) return FALSE; /* If we get here, the focus request wasn't successful */ MessageBoxW(NULL, L"An instance of Pidgin is already running", NULL, MB_OK | MB_TOPMOST); return FALSE; } } else if (err != ERROR_SUCCESS) printf("Error (%u) accessing /"pidgin_is_running/" mutex./n", (UINT) err); } return TRUE;}
开发者ID:gotomypc,项目名称:pidgin_whiteboard,代码行数:28,
示例3: CWE253_Incorrect_Check_of_Function_Return_Value__wchar_t_w32CreateMutex_15_badvoid CWE253_Incorrect_Check_of_Function_Return_Value__wchar_t_w32CreateMutex_15_bad(){ switch(6) { case 6: { HANDLE hMutex = NULL; hMutex = CreateMutexW(NULL, FALSE, NULL); /* FLAW: If CreateMutexW() failed, the return value will be NULL, but we are checking to see if the return value is INVALID_HANDLE_VALUE */ if (hMutex == INVALID_HANDLE_VALUE) { exit(1); } /* We'll leave out most of the implementation since it has nothing to do with the CWE * and since the checkers are looking for certain function calls anyway */ CloseHandle(hMutex); } break; default: /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); break; }}
开发者ID:gpwi970725,项目名称:testJuliet1,代码行数:25,
|