//初始化接口 bool COcrInput::Init(void) { CStdString strMsg = _T(""); CStdString strDir = GetInstallPath(); m_hDLL = LoadLibrary(strDir + _T("\\bin\\InputOCR.dll")); if(m_hDLL) { m_pfuncPushOCRData = (PUSH_OCR_DATA)GetProcAddress(m_hDLL, PUSHCODEDATA); m_pfuncSetOcrInputFocus = (SET_OCR_INPUTFOCUS)GetProcAddress(m_hDLL, SETOCRINPUTFOCUS); m_pfunGetCodeDataBack = (GET_CODEDATA_BACK)GetProcAddress(m_hDLL, GETCODEDATABACK) ; } if (!m_hDLL || !m_pfuncPushOCRData || !m_pfuncSetOcrInputFocus) { strMsg.Format(_T("加载验证码输入模块失败! err:%d"), GetLastError()); MessageBox(NULL, strMsg, _T("程序错误"), MB_OK); return false; } m_hMutexSyncFocus = OpenMutex(MUTEX_ALL_ACCESS, FALSE, _T("InputFocus")); if (NULL == m_hMutexSyncFocus) { strMsg.Format(_T("打开同步焦点对象失败! err:%d"), GetLastError()); MessageBox(NULL, strMsg, _T("程序错误"), MB_OK); return false; } m_hMutexSystemInput = OpenMutex(MUTEX_ALL_ACCESS, FALSE, _T("Engine_SystemInPutMutex")); return true; }
bool RenderFunc() { hge->Gfx_BeginScene(); hge->Gfx_Clear(0); if (menu) { HANDLE mutex1 = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX1); if (mutex1) WaitForSingleObject(mutex1, INFINITE); RenderGUI(); ReleaseMutex(mutex1); if (menu == 4) { text->printf(SCREEN_WIDTH/2, 200, HGETEXT_CENTER, "NESTERENKO DIMA"); text->printf(SCREEN_WIDTH/2, 250, HGETEXT_CENTER, "COMPUTER ACADEMY \"STEP\""); } } else { world->Render(); mouse_cursor->Render(mouse_pos.x, mouse_pos.y); if (text) { char str[8]; int life; HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2); if (mutex) WaitForSingleObject(mutex, INFINITE); life = player->GetLife(); ReleaseMutex(mutex); hard->Render(32, 32); text->printf(74, 16, HGETEXT_LEFT, "%d", life); if (level_end == 1) { text->printf(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, HGETEXT_CENTER, "GO TO NEXT LEVEL!!!"); } else if (level_end == 2) { text->printf(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, HGETEXT_CENTER, "YOU WIN!!!"); } if (ENTITY_DEATH == player->GetState()) { text->printf(SCREEN_WIDTH/2, SCREEN_HEIGHT/2, HGETEXT_CENTER, "Please press a space....."); } } } hge->Gfx_EndScene(); return false; }
DWORD WINAPI CaptureThread(HANDLE hDllMainThread) { bool bSuccess = false; //wait for dll initialization to finish before executing any initialization code if(hDllMainThread) { WaitForSingleObject(hDllMainThread, INFINITE); CloseHandle(hDllMainThread); } WNDCLASS wc; ZeroMemory(&wc, sizeof(wc)); wc.hInstance = hinstMain; wc.lpszClassName = SENDER_WINDOWCLASS; wc.lpfnWndProc = (WNDPROC)SenderWindowProc; if(RegisterClass(&wc)) { hwndSender = CreateWindow(SENDER_WINDOWCLASS, NULL, 0, 0, 0, 0, 0, NULL, 0, hinstMain, 0); if(hwndSender) { textureMutexes[0] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX1); if(textureMutexes[0]) { textureMutexes[1] = OpenMutex(MUTEX_ALL_ACCESS, FALSE, TEXTURE_MUTEX2); if(textureMutexes[1]) { while(!AttemptToHookSomething()) Sleep(50); MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); AttemptToHookSomething(); } CloseHandle(textureMutexes[1]); textureMutexes[1] = NULL; } CloseHandle(textureMutexes[0]); textureMutexes[0] = NULL; } DestroyWindow(hwndSender); } } return 0; }
static void test_mutex(void) { DWORD wait_ret; BOOL ret; HANDLE hCreated; HANDLE hOpened; hCreated = CreateMutex(NULL, FALSE, "WineTestMutex"); ok(hCreated != NULL, "CreateMutex failed with error %d\n", GetLastError()); wait_ret = WaitForSingleObject(hCreated, INFINITE); ok(wait_ret == WAIT_OBJECT_0, "WaitForSingleObject failed with error 0x%08x\n", wait_ret); /* yes, opening with just READ_CONTROL access allows us to successfully * call ReleaseMutex */ hOpened = OpenMutex(READ_CONTROL, FALSE, "WineTestMutex"); ok(hOpened != NULL, "OpenMutex failed with error %d\n", GetLastError()); ret = ReleaseMutex(hOpened); todo_wine ok(ret, "ReleaseMutex failed with error %d\n", GetLastError()); ret = ReleaseMutex(hCreated); todo_wine ok(!ret && (GetLastError() == ERROR_NOT_OWNER), "ReleaseMutex should have failed with ERROR_NOT_OWNER instead of %d\n", GetLastError()); /* test case sensitivity */ SetLastError(0xdeadbeef); hOpened = OpenMutex(READ_CONTROL, FALSE, "WINETESTMUTEX"); ok(!hOpened, "OpenMutex succeeded\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME, /* win9x */ "wrong error %u\n", GetLastError()); SetLastError(0xdeadbeef); hOpened = OpenMutex(READ_CONTROL, FALSE, "winetestmutex"); ok(!hOpened, "OpenMutex succeeded\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_INVALID_NAME, /* win9x */ "wrong error %u\n", GetLastError()); SetLastError(0xdeadbeef); hOpened = CreateMutex(NULL, FALSE, "WineTestMutex"); ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError()); ok(GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError()); CloseHandle(hOpened); SetLastError(0xdeadbeef); hOpened = CreateMutex(NULL, FALSE, "WINETESTMUTEX"); ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError()); ok(GetLastError() == 0, "wrong error %u\n", GetLastError()); CloseHandle(hOpened); CloseHandle(hCreated); }
JNIEXPORT jint JNICALL Java_com_tkym_labs_sharedmem_win_BaseNamedObjectsJni_openMutex(JNIEnv * env, jobject, jstring name){ LPCTSTR lpName = (LPCTSTR)env->GetStringChars(name, NULL); HANDLE handle = OpenMutex(MUTEX_ALL_ACCESS, FALSE, lpName); env->ReleaseStringChars(name, (const jchar *)lpName); if (handle == NULL) return (jint) (-1*GetLastError()); else return (jint) handle; }
bool CSingleAccess::Setup(LPCTSTR signalName) { if(signalName) { #ifdef _DEBUG m_signalName=signalName; #endif } else { #ifdef _DEBUG m_signalName=""; #endif return false; } ASSERT(m_hSignal==NULL); if(OpenMutex(MUTEX_ALL_ACCESS,false,signalName)) { TRACE("CSingleAccess无法构造对象,因为名称[%s]已经存在!\n",signalName); return false; } m_hSignal=CreateMutex(NULL,FALSE,signalName); if(m_hSignal) ReleaseMutex(m_hSignal); return m_hSignal!=NULL; }
int Mymutex::openwrite(wchar_t* name){ mutex=OpenMutex(MUTEX_ALL_ACCESS,false, (LPCWSTR)name); if(mutex==NULL){ if(GetLastError()==ERROR_FILE_NOT_FOUND){ mutex=CreateMutex(NULL,false,(LPCWSTR)name); }else{ printf("BBBBBBBB\n"); return -1; } } int wr=WaitForSingleObject(mutex,INFINITE); if(wr==WAIT_FAILED){ printf("BBBBBBBB1\n"); return -1; } file=CreateFileW(name,GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if (file==INVALID_HANDLE_VALUE){ return -1; } int pos=0; int sr=SetFilePointer(file,0,(PLONG)&pos,FILE_END); if(sr==INVALID_SET_FILE_POINTER){ return -1; } return 0; }
long CUpdateBar::OnSelfUpdateInit(WPARAM wParam, LPARAM lParam) { // Wait for terminating MUpdate.exe HANDLE hMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, MUPDATE_MUTEXNAME); if (hMutex) { DWORD dwVal = WaitForSingleObjectEx(hMutex, INFINITE, TRUE); TRACE("MUTEX Result = %d \n", dwVal); } // Copy MUpdate_New.exe to MUpdate.exe if (!CopyFile("MUpdate_New.exe", "MUpdate.exe", FALSE)) { DWORD dwError = GetLastError(); TRACE("CopyFile Error : %d \n", dwError); } DeleteFile("MUpdate_New.exe"); // Shutdown exit(0); // CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); // pFrame->DestroyWindow(); // pFrame->PostMessage(WM_CLOSE); return TRUE; }
BOOL CSageApp::InitInstance() { LPCTSTR szSingleInstanceMutex = _T("EGAR SAGE {1772A390-F4B7-4d4c-8949-1A11955CC803}"); m_hSingleInstanceMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, szSingleInstanceMutex); if (m_hSingleInstanceMutex) { return FALSE; } m_hSingleInstanceMutex = CreateMutex(NULL, FALSE, szSingleInstanceMutex); // Change the registry key under which our settings are stored. SetRegistryKey(APP_KEY); CoInitialize(NULL); CTracer::CreateFileName(); CSageDlg dlg; m_pMainWnd = &dlg; dlg.DoModal(); CoUninitialize(); if (m_hSingleInstanceMutex) CloseHandle(m_hSingleInstanceMutex); return FALSE; }
void ClientManager::SubstractUser(int fd) { #if 0 /* Mutex Open */ m_hMutex = OpenMutex(MUTEX_ALL_ACCESS, TRUE, (LPCWSTR)SHARE_MUTEX); if (m_hMutex == NULL) { printf("Mutex Handle is NULL.. \n"); m_hMutex = CreateMutex(NULL, FALSE, (LPCWSTR)SHARE_MUTEX); } WaitForSingleObject(m_hMutex, INFINITE); #endif /* Mutex Open */ unordered_map<int, ObjectUser*>::iterator it_user; it_user = map_user.find(fd); if (it_user != map_user.end()) { map_user.erase(it_user); delete UserInfo[fd]; SubtractClientCnt(); }; #if 0 /* Mutex Close */ ReleaseMutex(m_hMutex); //CloseHandle(m_hMutex); m_hMutex = NULL; /* Mutex Close */ #endif }
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpCmdLine, int nShowCmd) { lua_State *L; int hostCommand, initTop, endTop; if (OpenMutex(MUTEX_ALL_ACCESS, FALSE, g_mutex)) { MessageBoxA(0, "CWG4 is already loaded.", g_appName, MB_ICONERROR); return 1; } CreateMutex(NULL, TRUE, g_mutex); do { hostCommand = 0; L = luaL_newstate(); if (!L) return 2; luaL_openlibs(L); initTop = lua_gettop(L); if (luaL_loadfile(L, "init.lua") || lua_pcall(L, 0, LUA_MULTRET, 0)) { MessageBoxA(0, lua_tostring(L, -1), g_appName, MB_ICONERROR); lua_close(L); return 3; } endTop = lua_gettop(L); if (endTop > initTop) hostCommand = lua_tointeger(L, -1); lua_close(L); } while (hostCommand == 42); return 0; }
void World::UpdateGraphic() { bg->Update(); map->UpdateGraphic(); HANDLE mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, NAME_MUTEX2); if (mutex) { WaitForSingleObject(mutex, INFINITE); for (int i = 0; i < entitys.size(); i++) { entitys[i]->UpdateGraphic(); } if (player) player->UpdateGraphic(); ReleaseMutex(mutex); for (size_t i = 0; i < bullets.size(); i++) { bullets[i]->UpdateGraphic(); } } }
// // すでに起動済みかどうかを Mutex で判定 // out: TRUE .. 起動済み // BOOL check_already(void) { SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; TCHAR mutex_name[MAX_PATH]; wsprintf(mutex_name, MUTEX_STRING, service_name); // 排他処理用 mutex を作成 mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutex_name); if(mutex != NULL) { if(!service_flag) { // すでに起動されています。 MessageBoxResourceText(NULL, IDS_ERROR_ALREADY_EXECUTE, NULL, ERROR_HEADER, MB_OK); } return TRUE; } sa.lpSecurityDescriptor = NULL; if(InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) { if(SetSecurityDescriptorDacl(&sd, TRUE, (PACL)NULL, FALSE)) { sa.lpSecurityDescriptor = &sd; } } sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; mutex = CreateMutex(&sa, FALSE, mutex_name); return FALSE; }
CONDITION THR_ObtainMutex(int fac) { #ifdef CTN_USE_THREADS #ifdef _MSC_VER char name[32]; HANDLE hTmpMutex; mutexName(fac, name); hTmpMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name); WaitForSingleObject(hMutex[fac], INFINITE); /* From JCS, close temp handle to get eliminate resource leak. */ CloseHandle(hTmpMutex); return THR_NORMAL; #else int cond; if (!initialized) { fprintf(stderr, "Threads not initialized in call to THR_ObtainMutex: exiting\n"); exit(1); } cond = mutex_lock(&mutex[fac]); if (cond != 0) { fprintf(stderr, "Failed on call to mutex_lock in THR_ObtainMutex\n"); return THR_GENERICFAILURE; } return THR_NORMAL; #endif #else return THR_NORMAL; #endif }
BOOL CTabletInfoApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinApp::InitInstance(); AfxEnableControlContainer(); hMutex=OpenMutex(MUTEX_ALL_ACCESS,FALSE,"TabletInfo"); if(hMutex) { //AfxMessageBox("程序已经启动,请双击对应的系统图标打开程序!",MB_ICONERROR); HWND hWnd=FindWindow(NULL,"TabletInfo v1.4"); if (hWnd) { if(!IsWindowVisible(hWnd)) ShowWindow(hWnd,SW_SHOW); SetForegroundWindow(hWnd); } return FALSE; } else { hMutex=CreateMutex(NULL,FALSE,"TabletInfo"); } // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need // Change the registry key under which our settings are stored // TODO: You should modify this string to be something appropriate // such as the name of your company or organization SetRegistryKey(_T("TabletInfo")); CTabletInfoDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
etk_win32_sem_locker_t() { const char *lockerName = "_etk_global_"; if((iLocker = OpenMutex(MUTEX_ALL_ACCESS, FALSE, lockerName)) == NULL) iLocker = CreateMutex(NULL, FALSE, lockerName); if(iLocker == NULL) ETK_ERROR("[KERNEL]: Can't initialize global semaphore!"); }
void Renderer::startRendering(size_t i_threadCount) { threadCount = i_threadCount; mThreadHandle = ThreadHandle(threadCount); imageWidth = renderImage.GetWidth(); imageHeight = renderImage.GetHeight(); noOfRowsToRenderPerThread = imageHeight / threadCount; renderingImage = renderImage.GetPixels(); zBufferImage = renderImage.GetZBuffer(); sampleCountImage = renderImage.GetSampleCount(); operationCountImage = renderImage.GetOperationCountImage(); myEngine::Timing::Clock *clock = myEngine::Timing::Clock::createAndStart(); /*for (int i = 0; i < renderImage.GetHeight(); ++i) { for (int j = 0; j < renderImage.GetWidth(); ++j) { calculatePixelColor(rootNode,lights,j, i); } }*/ int *threadVal = new int[threadCount]; for (size_t i = 0; i < threadCount; i++) { threadVal[i] = i; std::cout << "\nPassing Value to thread" << threadVal[i]; mThreadHandle.thread[i] = CreateThread(nullptr, 0, static_cast<LPTHREAD_START_ROUTINE>(renderPixel), &threadVal[i], CREATE_SUSPENDED, nullptr); } for (size_t i = 0; i < threadCount;i++) { ResumeThread(mThreadHandle.thread[i]); } std::cout << "Wait Val"<<std::endl << WaitForMultipleObjects(threadCount, mThreadHandle.thread, TRUE, INFINITE) << std::endl;; std::cout << "Wait finished"; if (WaitForMultipleObjects(threadCount + 1, mThreadHandle.thread, TRUE, INFINITE)) { mThreadHandle.destroyThread(); } TCHAR* mutexName = __T("WritingMutex"); HANDLE mutexHandle = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutexName); CloseHandle(mutexHandle); renderImage.SaveImage("RayCasted.ppm"); renderImage.ComputeZBufferImage(); renderImage.SaveZImage("RayCastWithZ.ppm"); renderImage.ComputeSampleCountImage(); renderImage.SaveSampleCountImage("SampleCountImage.ppm"); clock->updateDeltaTime(); double time = clock->getdeltaTime(); printf("Time to render ray casting %f", clock->getdeltaTime()); }
HWND GetSakuraHwnd( LPCTSTR lpszAgentName ) { HANDLE hMutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, lpszAgentName ); if ( hMutex == NULL ) { return NULL; } CloseHandle(hMutex); HANDLE hMapFile = OpenFileMapping( FILE_MAP_READ, FALSE, TEXT( "Sakura" ) ); if( hMapFile == NULL ) { return NULL; } char * pBuf = (char *) MapViewOfFile( hMapFile, FILE_MAP_READ, 0UL, 0UL, 1024UL * 64UL ); if( pBuf == NULL ) { CloseHandle( hMapFile ); return NULL; } char hcSakuraHwnd[ 128 ] = ""; for( int p = 0; p < 1000; p++ ) { if( pBuf[ p ] == 'h' && pBuf[ p+1 ] == 'w' && pBuf[ p+2 ] == 'n' && pBuf[ p+3 ] == 'd' && pBuf[ p+4 ] == 0x01 ) { for( int q = p + 5; pBuf[ q ] >= '0' && pBuf[ q ] <= '9'; q++ ) { char tmpstr[ 10 ]; wsprintfA( tmpstr, "%hc", pBuf[ q ] ); lstrcatA( hcSakuraHwnd, tmpstr ); } break; } } UnmapViewOfFile( pBuf ); CloseHandle( hMapFile ); if( lstrcmpA( hcSakuraHwnd, "" ) == 0 ) { return NULL; } return (HWND) atoi( hcSakuraHwnd ); }
bool mutex::open( const tdk::tstring& name ) { _mutex = OpenMutex( MUTEX_ALL_ACCESS, FALSE, name.c_str() ); if ( _mutex == NULL ) { tdk::set_last_error( tdk::platform::error()); return false; } return true; }
///////////////////////////////////////////////////////////////////////////////////////// // Name : CMutex // Full name : CMutex::CMutex // Access : public // Brief : // Parameter : LPCTSTR lpName, BOOL bInheritHandle /*= FALSE */ // Return : // Notes : CMutex::CMutex(LPCTSTR lpName, BOOL bInheritHandle /*= FALSE */) : m_hMutex( OpenMutex( MUTEX_ALL_ACCESS, bInheritHandle, lpName ) ) { if ( m_hMutex==NULL && GetLastError()==ERROR_FILE_NOT_FOUND ) { m_hMutex=CreateMutex( NULL, false, lpName ); } if( m_hMutex == NULL ) throw CEXP( "CMutex::CMutex - Can't open a Mutex object. ErrCode:%d", ::GetLastError() ); } // End of function CMutex(...
ReturnCode SyncUtil::SyncOpenMutex( const wchar_t* mutex_name, int& mutex_handle ) { //Open Mutex if(mutex_handle = (int)OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutex_name)) return RC_OK; //General error occurred return RC_ERR_GENERAL; }
static HANDLE check_sakura(void) { HANDLE hsakura; hsakura = OpenMutex(MUTEX_ALL_ACCESS, FALSE, _T("sakura")); if (hsakura != NULL) { CloseHandle(hsakura); } return(hsakura); }
/*--------------------------------------------------------------------------*/ BOOL haveInnosetupMutex(void) { HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, SCI_VERSION_STRING); if (hMutex) { CloseHandle(hMutex); return TRUE; } return FALSE; }
Boolean rocs_mutex_open( iOMutexData o ) { #ifdef __ROCS_MUTEX__ o->handle = OpenMutex( MUTEX_ALL_ACCESS, False, o->name ); if( o->handle == NULL ) { o->rc = GetLastError(); return False; } #endif return True; }
void initMemory() { for(int i=0; i<MAXSHAREDMEMOBJECTS; i++) { reserveObjectAddresses(i); } for(;;) { hPoolMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "os2sharemem_mutex"); if(hPoolMutex==NULL) { hPoolMutex = CreateMutex(NULL, TRUE, "os2sharemem_mutex"); if(hPoolMutex!=NULL) break; } else { WaitForSingleObject(hPoolMutex,INFINITE); break; } } BOOL init=FALSE; for(;;) { hPoolFileMapping = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, "os2sharemem_pool"); if(hPoolFileMapping==NULL) { hPoolFileMapping = CreateFileMapping((HANDLE)0xffffffff, NULL, PAGE_READWRITE, 0, sizeof(SM_Pool), "os2sharemem_pool" ); if(hPoolFileMapping!=NULL) { init = TRUE; break; } } else { break; } } //map pool into address space SM_Pool *ppool = (SM_Pool*)MapViewOfFile(hPoolFileMapping, FILE_MAP_ALL_ACCESS, 0,0, sizeof(SM_Pool)); //initialize pool if needed if(init) { ppool->BaseAddress = (LPVOID)SHAREDMEMBASEADDRESS; for(int i=0; i<MAXSHAREDMEMOBJECTS; i++) ppool->SM_Object[i].SM_ReferenceCount=0; } UnmapViewOfFile(ppool); ReleaseMutex(hPoolMutex); //start thread that handles DosGiveMem from other processes { DWORD tid; HANDLE h=CreateThread(NULL, 8192, giveMemThread, 0, 0, &tid); CloseHandle(h); } }
void Renderer::calculatePixelColor(Node &i_rootNode, LightList &i_lightList, int offsetAlongWidth, int offsetAlongHeight) { HitInfo hitInfo; Color noHitPixelColor = { 0,0,0 }; Color finalColor = { 0,0,0 }; RandomSampler sampler = RandomSampler(MIN_SAMPLE_COUNT, MAX_SAMPLE_COUNT, MIN_VARIANCE, MAX_VARIANCE); while (sampler.needMoreSamples()) { sampler.generateSamples(offsetAlongWidth, offsetAlongHeight); for (int k = 0; k < sampler.getSampleBucketSize(); ++k) { hitInfo.Init(); Ray sampleRay = sampler.getSampleRay(k); if (TraceRay(&i_rootNode, sampleRay, hitInfo)) { finalColor = hitInfo.node->GetMaterial()->Shade(sampleRay, hitInfo, i_lightList, REFLECTION_BOUNCE_COUNT, GI_BOUNCE_COUNT); /*finalColor.r = pow(finalColor.r, 1/2.2); finalColor.g = pow(finalColor.g, 1/2.2); finalColor.b = pow(finalColor.b, 1/2.2);*/ sampler.setSampleColor(k, finalColor); sampler.setIsSampleHit(k, true); } else { sampler.setSampleColor(k, background.Sample(sampleRay.dir)); } sampler.setHitInfo(k, hitInfo); } } Color tempColor = sampler.getAveragedSampleListColor(); tempColor.r = pow(tempColor.r, 1 / 2.2); tempColor.g = pow(tempColor.g, 1 / 2.2); tempColor.b = pow(tempColor.b, 1 / 2.2); float depth = sampler.getAveragedDepth(); int sampleCount = sampler.getSampleBucketSize(); int pixel = offsetAlongHeight * imageWidth + offsetAlongWidth; TCHAR* mutexName = __T("WritingMutex"); static HANDLE mutexHandle = NULL; if( mutexHandle == NULL ) mutexHandle = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutexName); DWORD dSuccess = WaitForSingleObject(mutexHandle, INFINITE); assert(dSuccess == WAIT_OBJECT_0); renderingImage[pixel] = tempColor; operationCountImage[pixel] = Color(1.0f,0.0f,0.0f) * static_cast<float>(hitInfo.operationCount/BIGFLOAT); zBufferImage[pixel] = depth; sampleCountImage[pixel] = sampleCount; bool bSuccess = ReleaseMutex(mutexHandle); assert(bSuccess == true); sampler.resetSampler(); }
bool CSingleInstance::IsExistingInstanceOf( PCTSTR szName ) { if( OpenMutex(MUTEX_ALL_ACCESS, FALSE, szName) == NULL ) { CreateNullDaclSd(); CreateMutex(&m_sa, FALSE, szName); FreeNullDaclSd(); return false; } return true; }
int main() { // there we go LoadLibrary("../cuckoomon.dll"); FILE *fp = fopen("test-hello", "r"); if(fp != NULL) fclose(fp); fp = fopen("test-hello", "wb"); fwrite("whatsup", 1, 6, fp); fclose(fp); fp = fopen("test-hello", "rb"); char buf[6]; fread(buf, 1, 6, fp); fclose(fp); _mkdir("abc"); DeleteFile("test-hello"); HKEY hKey; if(RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS) { RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); RegSetValueEx(hKey, "TestApiHooks", 0, REG_SZ, (BYTE *) "Hoi", 3); RegDeleteValue(hKey, "TestApiHooks"); RegCloseKey(hKey); } system("echo hai"); WinExec("echo hi there", SW_SHOW); CreateMutex(NULL, FALSE, "MutexNam3"); OpenMutex(MUTEX_ALL_ACCESS, FALSE, "OpenMutexName"); // just some random dll LoadLibrary("urlmon.dll"); FARPROC sleep = GetProcAddress(GetModuleHandle("kernel32"), "Sleep"); sleep(1000); printf("debugger: %d\n", IsDebuggerPresent()); CloseHandle(CreateThread(NULL, 0, &dummy, NULL, 0, NULL)); HANDLE thread_handle = CreateRemoteThread(GetCurrentProcess(), NULL, 0, &dummy, NULL, 0, NULL); WaitForSingleObject(thread_handle, INFINITE); CloseHandle(thread_handle); }
/*--------------------------------------------------------------------------*/ BOOL haveMutexClosingScilab(void) { char *mutexname = getClosingScilabMutexName(); if (mutexname) { HANDLE hMutex; hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, mutexname); FREE(mutexname); mutexname = NULL; if (hMutex) return TRUE; } return FALSE; }
/*---------------------------------------------------------------------------- CheckSakuraMutex() SSTP サーバー存在確認 ----------------------------------------------------------------------------*/ BOOL CheckSakuraMutex() { //return TRUE; HANDLE hMutex; hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MY_SAKURA_MUTEX); if(hMutex == NULL) { hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MY_SSP_MUTEX); if(hMutex == NULL) { return FALSE; } CloseHandle(hMutex); return TRUE; } CloseHandle(hMutex); return TRUE; }