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[], wchar_t wtext2[128]) {
- //wchar_t wtext2[128];
- mbstowcs(wtext2, text, strlen(text) + 1);//Plus null
- LPWSTR ptr = wtext2;
- return ptr;
- }
- void titleSet(char a[]) {
- wchar_t wtext2[128];
- LPWSTR ptr2 = winApiFormat(a, wtext2);
- SetConsoleTitle(ptr2);
- }
- void setCharArg(char* cmd, char* arg) {
- sprintf(cmd + strlen(cmd), " %s", arg);
- }
- void controlProcess(int argc, char* argv[]) {
- char title[128] = "slave";
- if (argc != 4) {
- cerr << "Slave: Snachalo slave zapustite MASTER.EXE.\n";
- exit(1);
- }
- int pid = atoi(argv[1]);
- cout << "----------------" << argv[3] << "\n";
- cout << "----------------" << argv[2] << "\n";
- cout << "----------------" << argv[1] << "\n";
- cout << "----------------" << argv[0] << "\n";
- setCharArg(title, argv[2]);
- setCharArg(title, argv[3]);
- titleSet(title);
- 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();
- }
- int main(int argc, char* argv[]) {
- cout << "Slave: start ...\n";
- //cin.get();
- controlProcess(argc, argv);
- //cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement