• WIN32 子进程继承父进程消息句柄


    // 消息句柄继承.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;
    }
  • 相关阅读:
    从开发人员角度对软件测试的些许理解
    ObjectiveC的语法
    HttpModule与HttpHandler使用
    我为什么学习HASKELL?
    Linux下C语言编程环境Make命令和Makefile
    一个简单的验证框架
    程序员之路
    ObjectiveC语法之ObjectiveC语言和IOS系统(简介,语法,系统结构)
    Teamcity
    Python进阶 错误处理
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13219784.html
Copyright © 2020-2023  润新知