Advertisement
Savelyev_Vyacheslav

slave

May 8th, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. //Программа Slave
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <windows.h>
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <string.h>
  7. using namespace std;
  8.  
  9. LPWSTR winApiFormat(char text[], wchar_t wtext2[128]) {
  10.     mbstowcs(wtext2, text, strlen(text) + 1);//Plus null
  11.     LPWSTR ptr = wtext2;
  12.     return ptr;
  13. }
  14. void titleSet(char a[]) {
  15.     wchar_t wtext2[128];
  16.     LPWSTR ptr2 = winApiFormat(a, wtext2);
  17.     SetConsoleTitle(ptr2);
  18. }
  19.  
  20. void setCharArg(char* cmd, char* arg) {
  21.     sprintf(cmd + strlen(cmd), " %s", arg);
  22. }
  23. void controlProcess(int argc, char* argv[]) {
  24.     char title[128] = "slave";
  25.     if (argc != 4) {
  26.         cerr << "Slave: Snachalo slave zapustite MASTER.EXE.\n";
  27.         exit(1);
  28.     }
  29.    
  30.     int pid = atoi(argv[1]);
  31.     cout << "----------------" << argv[3] << "\n";
  32.     cout << "----------------" << argv[2] << "\n";
  33.     cout << "----------------" << argv[1] << "\n";
  34.     cout << "----------------" << argv[0] << "\n";
  35.     setCharArg(title, argv[2]);
  36.     setCharArg(title, argv[3]);
  37.     titleSet(title);
  38.  
  39.     HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE,
  40.         FALSE, pid);
  41.     if (!process) cout << "Slave: Oshibka otkrytiay protsessa\n";
  42.     cout << "Slave:Ozhidanie zakrytiay protsessa Master\n";
  43.     cout.flush();
  44.     if (WaitForSingleObject(process, INFINITE) == STATUS_WAIT_0)
  45.     {
  46.         cout << "Slave: Master zavershil rabotu\n";
  47.         cin.get();
  48.     }
  49.     else
  50.         cout << "Slave: Не известная ошибка\n";
  51.     exit(0);
  52.     cout << "Slave: EXIT\n";
  53.     cin.get();
  54. }
  55.  
  56.  
  57. int main(int argc, char* argv[]) {
  58.  
  59.     cout << "Slave: start ...\n";
  60.     //cin.get();
  61.     controlProcess(argc, argv);
  62.  
  63.  
  64.     //cin.get();
  65.  
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement