Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- void __stdcall ThreadFun1()
- {
- printf("Hi This is my first thread.\n");
- }
- int main()
- {
- ThreadFun1();
- ////===========================GetCurrentProcess();=======================
- HANDLE h = GetCurrentProcess();
- SetPriorityClass(h, HIGH_PRIORITY_CLASS);
- printf("%x\n", GetPriorityClass(h));
- ////============================SetPriorityClass();=======================
- STARTUPINFO Sinfo = { 0 };
- PROCESS_INFORMATION Pinfo = { 0 };
- CreateProcess(TEXT("C:\\Windows\\notepad.exe"), NULL, NULL, NULL, FALSE, NULL, NULL, NULL, &Sinfo, &Pinfo);
- DWORD Prior = GetPriorityClass(Pinfo.hProcess); // pobieram prior procesu, na poczatku jest rowny 32 (czemu?)
- printf("PRIOR: %x\n", Prior);
- SetPriorityClass(Pinfo.hProcess, BELOW_NORMAL_PRIORITY_CLASS); // ustawiam se taki prior, msdn mowi : 0x00004000
- Prior = GetPriorityClass(Pinfo.hProcess); // pobieram zowu, teraz jest 16384, czyli sie zgadza z szesnastkowym 0x00004000
- printf("PRIOR: %x\n", Prior);
- CloseHandle(Pinfo.hProcess);
- CloseHandle(Pinfo.hThread);
- ////============================CREATE_THREAD()===========================
- printf("Entered In Main\n");
- HANDLE hThread;
- HANDLE hThread2;
- DWORD threadID;
- DWORD threadID2;
- //
- hThread = CreateThread(
- NULL, // security attributes ( default if NULL )
- 0, // stack SIZE default if 0
- (LPTHREAD_START_ROUTINE)ThreadFun1, // Start Address
- NULL, // input data
- 0, // creational flag ( start if 0 )
- &threadID); // thread ID
- SetThreadPriority(hThread, 1);
- int prior1 = GetThreadPriority(hThread);
- //
- hThread2 = CreateThread(
- NULL, // security attributes ( default if NULL )
- 0, // stack SIZE default if 0
- (LPTHREAD_START_ROUTINE)ThreadFun1, // Start Address
- NULL, // input data
- 0, // creational flag ( start if 0 )
- &threadID2); // thread ID
- SetThreadPriority(hThread2, 2);
- int prior2 = GetThreadPriority(hThread2);
- printf("Priorytet pierwszego watku: %d\n", prior1);
- printf("Priorytet drugiego watku: %d\n", prior2);
- printf("Main is exiting\n");
- //
- CloseHandle(hThread);
- CloseHandle(hThread2);
- //_getch();
- ////============================CREATE_PROCESS()===========================
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory(&si, sizeof(si));
- si.cb = sizeof(si);
- ZeroMemory(&pi, sizeof(pi));
- //// Start the child process.
- if (!CreateProcess(
- TEXT("c:\\WINDOWS\\system32\\calc.exe"), // No module name (use command line)
- NULL, // Command line
- NULL, // Process handle not inheritable
- NULL, // Thread handle not inheritable
- FALSE, // Set handle inheritance to FALSE
- 0, // No creation flags
- NULL, // Use parent's environment block
- NULL, // Use parent's starting directory
- &si, // Pointer to STARTUPINFO structure
- &pi) // Pointer to PROCESS_INFORMATION structure
- )
- printf("CreateProcess failed (%d).\n", GetLastError());
- //return;
- //}
- //// Wait until child process exits.
- WaitForSingleObject(pi.hProcess, INFINITE);
- //// Close process and thread handles.
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement