Example #1
0
        // No further mangling.
        NativeDbgProcess CreateProcessDebugRawWorker(string application, string commandArgs, Microsoft.Samples.Debugging.Native.NativeMethods.CreateProcessFlags flags)
        {
            if (application == null)
            {
                throw new ArgumentNullException("application");
            }

            EnsureIsOnWin32EventThread();

            // This is using definition imports from Mdbg core, where these are classes.
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); // class

            STARTUPINFO si = new STARTUPINFO();                 // struct


            bool createOk = NativeMethods.CreateProcess(
                application,
                commandArgs,
                IntPtr.Zero, // process attributes
                IntPtr.Zero, // thread attributes
                false,       // inherit handles,
                flags,
                IntPtr.Zero, // env block
                null,        // current dir
                si,
                pi);

            if (!createOk)
            {
                int err = Marshal.GetLastWin32Error();
                if (err == 2) // file not found
                {
                    if (!File.Exists(application))
                    {
                        throw new FileNotFoundException(application + " could not be found");
                    }
                }
                throw new InvalidOperationException("Failed to create process '" + application + "'. error=" + err);
            }

            // We'll close these handle now. We'll get them again from the CreateProcess debug event.
            NativeMethods.CloseHandle(pi.hProcess);
            NativeMethods.CloseHandle(pi.hThread);

            return(CreateNew(pi.dwProcessId));
        }
Example #2
0
        NativeDbgProcess CreateProcessDebugWorker(string application, string commandArgs, Microsoft.Samples.Debugging.Native.NativeMethods.CreateProcessFlags flags)
        {
            if (application == null)
            {
                throw new ArgumentException("can't be null", "application");
            }

            // Compensate for Win32's behavior, where arg[0] is the application name.
            if (commandArgs != null)
            {
                commandArgs = application + " " + commandArgs;
            }

            // This is using definition imports from Mdbg core, where these are classes.
            PROCESS_INFORMATION pi = new PROCESS_INFORMATION(); // class

            STARTUPINFO si = new STARTUPINFO();                 // struct


            NativeMethods.CreateProcess(
                application,
                commandArgs,
                IntPtr.Zero, // process attributes
                IntPtr.Zero, // thread attributes
                false,       // inherit handles,
                NativeMethods.CreateProcessFlags.CREATE_NEW_CONSOLE | flags,
                IntPtr.Zero, // env block
                null,        // current dir
                si,
                pi);

            // We'll close these handle now. We'll get them again from the CreateProcess debug event.
            NativeMethods.CloseHandle(pi.hProcess);
            NativeMethods.CloseHandle(pi.hThread);

            return(CreateNew(pi.dwProcessId));
        }