我在C部与微软视像C++共同撰写了一个老方案,我需要实施某种“管理”,因此,我得以将这种通信纳入一个新方案,如果在最后5秒中没有收到任何ms,将首先杀人并重新发射。
问题在于,我一直在研究用C语文使用Windows的电传或视像,但我发现的几乎是C++。
任何帮助或资源?
EDIT:As @Adriano在答复中建议,Im试图使用共同记忆。 但是,由于某种例外情况,Im无法捕获,发射器方案正在由Windows终止。 Happens when callsbookmory.
该法典如下:
#include "stdafx.h"
#include "windows.h"
#include "iostream"
using namespace std;
int launchMyProcess();
void killMyProcess();
bool checkIfMyProcessIsAlive();
STARTUPINFO sInfo;
PROCESS_INFORMATION pInfo;
HANDLE mappedFile;
LPVOID pSharedMemory;
long lastReceivedBeatTimeStamp;
const int MSECONDS_WITHOUT_BEAT = 500;
const LPTSTR lpCommandLine = "MyProcess.exe configuration.txt";
int main(int argc, char* argv[])
{
mappedFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(int), "Global\ActivityMonitor");
LPVOID pSharedMemory = MapViewOfFile(mappedFile, FILE_MAP_READ, 0, 0, sizeof(int));
if(!launchMyProcess()){
cout<<"Error creating MyProcess.exe"<<endl;
UnmapViewOfFile(pSharedMemory);
CloseHandle(mappedFile);
return -1;
}
while(true){
Sleep(100);
if(!checkIfMyProcessIsAlive()){
cout<<"Relaunching MyProcess...";
killMyProcess();
if(!launchMyProcess()){
cout<<"Error relaunching MyProcess.exe"<<endl;
UnmapViewOfFile(pSharedMemory);
CloseHandle(mappedFile);
return -1;
}
}
}
UnmapViewOfFile(pSharedMemory);
CloseHandle(mappedFile);
return 0;
}
bool checkIfMyProcessIsAlive()
{
static int volatile latestMagicNumber = 0;
int currentMagicNumber = 0;
CopyMemory(¤tMagicNumber, pSharedMemory, sizeof(int));
if(currentMagicNumber != latestMagicNumber){
latestMagicNumber = currentMagicNumber;
return true;
}
return false;
}
int launchMyProcess()
{
ZeroMemory(&sInfo, sizeof(sInfo));
sInfo.cb = sizeof(sInfo);
ZeroMemory(&pInfo, sizeof(pInfo));
return CreateProcess(NULL, lpCommandLine, NULL, NULL, FALSE, 0, NULL, NULL, &sInfo, &pInfo);
}
void killMyProcess()
{
TerminateProcess(pInfo.hProcess, 0);
CloseHandle(pInfo.hProcess);
CloseHandle(pInfo.hThread);
Sleep(3000);
}