ReactOS 0.4.15-dev-7998-gdb93cb1
p_dup_handle.c File Reference
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for p_dup_handle.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 11 of file p_dup_handle.c.

11 {
12 HANDLE h_process;
13 HANDLE h_process_in_parent;
14
15 fprintf( stderr, "%lu: Starting\n", GetCurrentProcessId() );
16
17 if( argc == 2 ) {
18 h_process = (HANDLE)(ULONG_PTR)atoi(argv[1]);
19 } else {
23 &h_process,
24 0,
25 TRUE,
27 fprintf( stderr, "%lu: Could not duplicate my own process handle.\n",
29 return 101;
30 }
31 }
32
33 if( argc == 1 ) {
34 STARTUPINFO si;
36 char cmdline[1000];
37
38 memset( &si, 0, sizeof( si ) );
39 memset( &pi, 0, sizeof( pi ) );
40
41 sprintf( cmdline, "%s %p", argv[0], h_process );
43 &si, &pi ) ) {
44 fprintf( stderr, "%lu: Could not create child process.\n",
46 return 5;
47 }
48
49 if( WaitForSingleObject( pi.hThread, INFINITE ) != WAIT_OBJECT_0 ) {
50 fprintf( stderr, "%lu: Failed to wait for child process to terminate.\n",
52 return 6;
53 }
54 } else {
57 h_process,
58 &h_process_in_parent,
59 0,
60 TRUE,
62 fprintf( stderr, "%lu: Could not duplicate my handle into the parent.\n",
64 return 102;
65 }
66 }
67
68 return 0;
69}
static int argc
Definition: ServiceArgs.c:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define GetCurrentProcess()
Definition: compat.h:759
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
#define INFINITE
Definition: serial.h:102
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static refpint_t pi[]
Definition: server.c:96
#define argv
Definition: mplay32.c:18
#define memset(x, y, z)
Definition: compat.h:39
TCHAR * cmdline
Definition: stretchblt.cpp:32
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
PVOID HANDLE
Definition: typedefs.h:73
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CreateProcess
Definition: winbase.h:3758
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define WAIT_OBJECT_0
Definition: winbase.h:406
#define DUPLICATE_SAME_ACCESS