#undef UNICODE
#include <windows.h>
 
#include <iostream>
#include <fstream>
using namespace std;
 
int main ()
{
    STARTUPINFO start;
    memset (&start, 0, sizeof (start));
    start.cb = sizeof (start);
 
    PROCESS_INFORMATION info;
 
    BOOL ok = CreateProcess
    (
        "C:\\Program Files\\NotepadPlusPlus\\notepad++.exe",                  // lpApplicationName,
        (char *) "notepad c:\\temp\\abc.txt",   // lpCommandLine,
        NULL,                // lpProcessAttributes,
        NULL,                // lpThreadAttributes,
        false,               // bInheritHandles,
        0,                   // dwCreationFlags,
        NULL,                // lpEnvironment,
        NULL,                // lpCurrentDirectory,
        & start,             // lpStartupInfo,
        & info               // lpProcessInformation
    );
 
    if (! ok)
    {
        // cout << "Nepovedlo se " << GetLastError () << endl;
        int code = GetLastError ();
        cout << "Error code: " << code << endl;
 
        char* answer = (char*) "nic";
 
        FormatMessage
        (
            FORMAT_MESSAGE_ALLOCATE_BUFFER |
            FORMAT_MESSAGE_FROM_SYSTEM /* |
            FORMAT_MESSAGE_IGNORE_INSERTS */, // DWORD dwFlags
 
            NULL, // LPCVOID lpSource,
            code, // DWORD dwMessageId,
            0, // DWORD dwLanguageId,
            (LPTSTR) &answer, //  LPTSTR lpBuffer,
            0, // DWORD nSize,
            NULL // va_list* Arguments
        );
 
        cout << "Error: " << answer << endl;
        LocalFree (answer);
    }
    else
    {
        cout << "Povedlo se" << endl;
 
        int n = WAIT_FAILED;
        while (n != WAIT_OBJECT_0);
        {
            n = WaitForSingleObject (info.hProcess, 1000);
            cout << ".";
        } 
 
        CloseHandle (info.hProcess);
        CloseHandle (info.hThread);
    }
 
    cout << "O.K." << endl;
}
 
zos/create_process_2021.txt · Last modified: 2021/03/29 17:17 by 88.103.111.44
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki