Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Программа Slave
- #define _CRT_SECURE_NO_WARNINGS
- #include <windows.h>
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- using namespace std;
- LPWSTR winApiFormat(char text[128]) {
- wchar_t wtext[128];
- mbstowcs(wtext, text, strlen(text) + 1);//Plus null
- LPWSTR ptr = wtext;
- return ptr;
- }
- void titleSet(char a[]) {
- LPWSTR ptr = winApiFormat(a);
- SetConsoleTitle(ptr);
- }
- //void main() {
- // char title[128] = "slave";
- // titleSet(title);
- // cout << "hI________________";
- // cout << "Slave: Sleeping\n";
- // Sleep(1000);
- // cin.get();
- //}
- int main(int argc, char* argv[]) {
- char title[128] = "slave";
- titleSet(title);
- cout << "Slave: start ...\n";
- //cin.get();
- if (argc != 2) {
- cerr << "Slave: Snachalo slave zapustite MASTER.EXE.\n";
- exit(1);
- }
- int pid = atoi(argv[1]);
- HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
- FALSE, pid);
- if (!process) cout << "Slave: Oshibka otkrytiay protsessa\n";
- cout << "Slave:Ozhidanie zakrytiay protsessa Master\n";
- cout.flush();
- if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
- {
- cout << "Slave: Master zavershil rabotu\n";
- cin.get();
- }
- else
- cout << "Slave: Не известная ошибка\n";
- exit(0);
- cout << "Slave: EXIT\n";
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement