Страница 13 из 24 22)--------------------------------------------------------------------------- Q> Как в мультипроцессорной системе указать задаче на каком процессоре работать? A> HANDLE threadHandle = GetCurrentThread(); SetThreadIdealProcessor(threadHandle, 1); 23)--------------------------------------------------------------------------- Q> Как установить (узнать) приоритет процесса? A> { HANDLE procHandle = GetCurrentProcess(); if (!SetPriorityClass(procHandle, HIGH_PRIORITY_CLASS)) RET_ERR("SetPriorityClass"); DWORD priorityClass = GetPriorityClass(procHandle); ADD_STR("Priority Class is set to : "); switch(priorityClass) { case HIGH_PRIORITY_CLASS: ADD_STR("HIGH_PRIORITY_CLASS\r\n"); break; case IDLE_PRIORITY_CLASS: ADD_STR("IDLE_PRIORITY_CLASS\r\n"); break; case NORMAL_PRIORITY_CLASS: ADD_STR("NORMAL_PRIORITY_CLASS\r\n"); break; case REALTIME_PRIORITY_CLASS: ADD_STR("REALTIME_PRIORITY_CLASS\r\n"); break; default: ADD_STR("Unknown priority class\r\n"); } return result_buffer; } 24)--------------------------------------------------------------------------- Q> Как установить (узнать) приоритет нити? A> { HANDLE threadHandle = GetCurrentThread(); if (!SetThreadPriority(threadHandle, THREAD_PRIORITY_HIGHEST)) RET_ERR("SetThreadPriority"); int priority = GetThreadPriority(threadHandle); if (priority == THREAD_PRIORITY_ERROR_RETURN) RET_ERR("GetThreadPriority"); switch (priority) { case THREAD_PRIORITY_ABOVE_NORMAL: ADD_STR("THREAD_PRIORITY_ABOVE_NORMAL\r\n"); break; case THREAD_PRIORITY_BELOW_NORMAL: ADD_STR("THREAD_PRIORITY_BELOW_NORMAL\r\n"); break; case THREAD_PRIORITY_HIGHEST: ADD_STR("THREAD_PRIORITY_HIGHEST\r\n"); break; case THREAD_PRIORITY_IDLE: ADD_STR("THREAD_PRIORITY_IDLE\r\n"); break; case THREAD_PRIORITY_LOWEST: ADD_STR("THREAD_PRIORITY_LOWEST\r\n"); break; case THREAD_PRIORITY_NORMAL: ADD_STR("THREAD_PRIORITY_NORMAL\r\n"); break; case THREAD_PRIORITY_TIME_CRITICAL: ADD_STR("THREAD_PRIORITY_TIME_CRITICAL\r\n"); break; default: ADD_STR("Unknown\r\n"); } return result_buffer;} 25)--------------------------------------------------------------------------- Q> Как определить тип NT - server или workstation? A> Через регистри - HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ProductOptions Значение "Product Type". Три возможных варианта : "WinNT" workstation "ServerNT" server "LanmanNT" domain controller 26)-------------------------------------------------------------------------- Q> Как проследить чтобы только одна копия приложения работала в данный момент A> BOOL WeAreAlone (LPSTR szName) { HANDLE hMutex = CreateMutex (NULL, TRUE, szName); if (GetLastError() == ERROR_ALREADY_EXISTS) { CloseHandle(hMutex); return FALSE; } return TRUE; } И в начале WinMain или main - if (WeAreAlone ("Some_Unique_Name_Or_Other")) { // Proceed } else { MessageBox (NULL,"Error","Error: app already running!",MB_OK|MB_ICONERROR); exit(1); } |