// 消息句柄继承.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <WINDOWS.H>
int main(int argc, char* argv[])
{
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
char s1[50] = {0};
char s2[255] = {0};
HANDLE g_Event = CreateEvent(&sa,TRUE,FALSE,NULL);
sprintf(s1,"%x",g_Event);
sprintf(s2,"F:/zzz.exe %s",s1);
STARTUPINFOA si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
//si.dwFlags = STARTF_USESHOWWINDOW; // 指定wShowWindow成员有效
//si.wShowWindow = TRUE; // 此成员设为TRUE的话则显示新建进程的主窗口,
BOOL res = CreateProcess(NULL,s2,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi);
if (!res)
{
DWORD dwcode = GetLastError();
printf("%x\n",dwcode);
}
SetEvent(g_Event);
CloseHandle(g_Event);
getchar();
printf("Hello World!\n");
return 0;
}
// zzz.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
int main(int argc, char* argv[])
{
char st1[50] = {0};
char st2[50] = {0};
DWORD g = 0;
sprintf(st1,"%s",argv[1]);
sscanf(st1,"%x",&g);
printf("%s\n",argv[0]);
printf("%x\n",g);
HANDLE g_e = HANDLE(g);
printf("等待消息中。。。。\n");
WaitForSingleObject(g_e,INFINITE);
DWORD dwcode = GetLastError();
printf("等到消息。。。。%x\n",dwcode);
getchar();
return 0;
}