55
66using namespace qqimpl ;
77
8- void __stdcall OnUsrReceiveMsg32 (void *, char *, int , int , char *, int );
9- void OnUsrReceiveMsg64 (void *, char *, int , char *, int );
8+ void __stdcall OnParentReceiveMsg32 (void *, char *, int , int , char *, int );
9+ void OnParentReceiveMsg64 (void *, char *, int , char *, int );
1010
1111int main ()
1212{
13- std::cout << " Parent Ipc Begin!\n " ;
13+ std::cout << " [+] [P] Parent Ipc Begin!\n " ;
1414 int child_pid_1 = 0 , child_pid_2 = 0 ;
1515
1616 qqipc::QQIpcParentWrapper parent_ipc;
1717 // 初始化环境
1818 if (!parent_ipc.InitEnv ())
1919 {
20- std::cout << " [!] Init ParentIpc Err: " << parent_ipc.GetLastErrStrA () << std::endl;
20+ std::cout << " [!] [P] Init ParentIpc Err: " << parent_ipc.GetLastErrStr () << std::endl;
2121 getchar (); return 0 ;
2222 }
2323 parent_ipc.InitLog (5 );
2424 parent_ipc.InitParentIpc ();
2525
2626 qqipc::callback_ipc cb_ptr;
2727#ifdef _WIN64
28- cb_ptr = OnUsrReceiveMsg64 ;
28+ cb_ptr = OnParentReceiveMsg64 ;
2929#else
30- cb_ptr = OnUsrReceiveMsg32 ;
30+ cb_ptr = OnParentReceiveMsg32 ;
3131#endif // _WIN64
3232
33+ const char * child_path;
34+ #ifdef _DEBUG
35+ child_path = " qqipc_child_test_d.exe" ;
36+ #else
37+ child_path = " qqipc_child_test.exe" ;
38+ #endif // _WIN64
39+
40+
3341 const char * cmd_args[] = {" -test1" , " -test2" };// 传递命令行参数
34- child_pid_1 = parent_ipc.LaunchChildProcess (L" ChildIpc.exe " , cb_ptr, (void *)" Child_1" , (char **)cmd_args, 2 );// "Child_1"为传递给OnUsrReceiveMsg的参数
42+ child_pid_1 = parent_ipc.LaunchChildProcess (child_path , cb_ptr, (void *)" Child_1" , (char **)cmd_args, 2 );// "Child_1"为传递给OnUsrReceiveMsg的参数
3543 if (child_pid_1 == 0 )
3644 {
37- std::cout << " [!] Launch CihldIpc.exe Err: " << parent_ipc.GetLastErrStrA () << std::endl;
45+ std::cout << " [!] [P] Launch CihldIpc.exe Err: " << parent_ipc.GetLastErrStr () << std::endl;
3846 getchar (); return 0 ;
3947 }
4048
41- std::cout << " Launch OK! Ready to Connect!\n " ;
49+ std::cout << " [+] [P] Launch OK! Ready to Connect!\n " ;
4250 parent_ipc.ConnectedToChildProcess (child_pid_1);
4351
44- std::cout << " Press any key to SendIpcMessage to Child1: " ;
52+ std::cout << " [=] [P] Press any key to SendIpcMessage to Child1: \n " ;
4553 getchar ();
46- parent_ipc.SendIpcMessage (child_pid_1, " test_parent" , " addition_parent" );
54+ std::string addtion_msg = " addition_parent" ;
55+ parent_ipc.SendIpcMessage (child_pid_1, " test_parent" , addtion_msg.data (), addtion_msg.size ());
4756
4857
49- std::cout << " Press any key to Terminate Child1: " ;
58+ std::cout << " [=] [P] Press any key to Terminate Child1: \n " ;
5059 getchar ();
5160 parent_ipc.TerminateChildProcess (child_pid_1, 0 , true );
5261
53- std::cout << " Press any key to ReLaunchChildProcess Child1: " ;
62+ std::cout << " [=] [P] Press any key to ReLaunchChildProcess Child1: \n " ;
5463 getchar ();
5564 child_pid_1 = parent_ipc.ReLaunchChildProcess (child_pid_1);
5665 parent_ipc.ConnectedToChildProcess (child_pid_1);
@@ -66,58 +75,60 @@ int main()
6675 return 0 ;
6776}
6877
69- void __stdcall OnUsrReceiveMsg32 (void * pArg, char * msg, int arg3, int arg4, char * addition_msg, int addition_msg_size)
78+ void __stdcall OnParentReceiveMsg32 (void * pArg, char * msg, int arg3, int arg4, char * addition_msg, int addition_msg_size)
7079{
7180 char * cb_arg = (char *)pArg;
72- std::cout << " [ " << __FUNCTION__ << " ] | Arg: " << cb_arg << std::endl;
81+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Arg: " << cb_arg << std::endl;
7382
7483 std::string msg_str = msg, add_msg_str (addition_msg, addition_msg_size);
75- std::cout << " [ " << __FUNCTION__ << " ] | Msg: " << msg_str << std::endl;
76- std::cout << " [ " << __FUNCTION__ << " ] | Addition Msg Size: " << addition_msg_size << std::endl;
84+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Msg: " << msg_str << std::endl;
85+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Addition Msg Size: " << addition_msg_size << std::endl;
7786 if (addition_msg_size != 0 )
7887 {
79- std::cout << " [ " << __FUNCTION__ << " ] | The Addition Msg: " ;
88+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | The Addition Msg: " ;
8089 for (size_t i = 0 ; i < addition_msg_size; i++)
81- printf (" 0x%02X " , (byte)(addition_msg[i]));
90+ printf_s (" 0x%02X " , (byte)(addition_msg[i]));
91+ printf_s (" (%s)" , addition_msg);
8292 puts (" " );
8393 }
8494
8595 if (msg_str == " IPC_CONNECTED" )
8696 {
87- std::cout << " [ " << __FUNCTION__ << " ] | " << cb_arg << " : Alive!" << std::endl;
97+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | " << cb_arg << " : Alive!" << std::endl;
8898 }
8999 else if (msg_str == " IPC_DISCONNECTED" )
90100 {
91- std::cout << " [ " << __FUNCTION__ << " ] | " << cb_arg << " : Dead!" << std::endl;
101+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | " << cb_arg << " : Dead!" << std::endl;
92102 }
93103
94104 // qqimpl::QQIpcParentWrapper::OnDefaultReceiveMsg(pArg, msg, arg3, arg4, addition_msg, addition_msg_size);
95105}
96106
97107
98- void OnUsrReceiveMsg64 (void * pArg, char * msg, int arg3, char * addition_msg, int addition_msg_size)
108+ void OnParentReceiveMsg64 (void * pArg, char * msg, int arg3, char * addition_msg, int addition_msg_size)
99109{
100110 char * cb_arg = (char *)pArg;
101- std::cout << " [ " << __FUNCTION__ << " ] | Arg: " << cb_arg << std::endl;
111+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Arg: " << cb_arg << std::endl;
102112
103113 std::string msg_str = msg, add_msg_str (addition_msg, addition_msg_size);
104- std::cout << " [ " << __FUNCTION__ << " ] | Msg: " << msg_str << std::endl;
105- std::cout << " [ " << __FUNCTION__ << " ] | Addition Msg Size: " << addition_msg_size << std::endl;
114+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Msg: " << msg_str << std::endl;
115+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | Addition Msg Size: " << addition_msg_size << std::endl;
106116 if (addition_msg_size != 0 )
107117 {
108- std::cout << " [ " << __FUNCTION__ << " ] | The Addition Msg: " ;
118+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | The Addition Msg: " ;
109119 for (size_t i = 0 ; i < addition_msg_size; i++)
110- printf (" 0x%02X " , (byte)(addition_msg[i]));
120+ printf_s (" 0x%02X " , (byte)(addition_msg[i]));
121+ printf_s (" (%s)" , addition_msg);
111122 puts (" " );
112123 }
113124
114125 if (msg_str == " IPC_CONNECTED" )
115126 {
116- std::cout << " [ " << __FUNCTION__ << " ] | " << cb_arg << " : Alive!" << std::endl;
127+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | " << cb_arg << " : Alive!" << std::endl;
117128 }
118129 else if (msg_str == " IPC_DISCONNECTED" )
119130 {
120- std::cout << " [ " << __FUNCTION__ << " ] | " << cb_arg << " : Dead!" << std::endl;
131+ std::cout << " [*] [P] [ " << __FUNCTION__ << " ] | " << cb_arg << " : Dead!" << std::endl;
121132 }
122133
123134 // qqimpl::QQIpcParentWrapper::OnDefaultReceiveMsg(pArg, msg, arg3, addition_msg, addition_msg_size);
0 commit comments