0

Following works

#include <windows.h>

int main(int argc, char** argv)
{
    STARTUPINFOA  start_info = { 0 };
    PROCESS_INFORMATION process_info = { 0 };
    LPSTR str = "C:\\Windows\\System32\\PING.EXE";

    CreateProcessA(
        NULL,
        str,
        NULL,
        NULL,
        TRUE,
        CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
        NULL,
        NULL,
        &start_info,
        &process_info
    );

    return 0;
}

As can be seen in

C:\Users\Admin\source\repos\ConsoleApplication1\Debug
λ ConsoleApplication1.exe

C:\Users\Admin\source\repos\ConsoleApplication1\Debug
λ echo %ERRORLEVEL%
0

But wide version I want to implement for utf8 support doesn't:

#include <windows.h>

int main(int argc, char** argv)
{
    STARTUPINFOW  start_info = { 0 };
    PROCESS_INFORMATION process_info = { 0 };
    LPWSTR str = L"C:\\Windows\\System32\\PING.EXE";

    CreateProcessW(
        NULL,
        str,
        NULL,
        NULL,
        TRUE,
        CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
        NULL,
        NULL,
        &start_info,
        &process_info
    );

    return 0;
}

That can be seen in

C:\Users\Admin\source\repos\ConsoleApplication1\Debug
λ ConsoleApplication1.exe

C:\Users\Admin\source\repos\ConsoleApplication1\Debug
λ echo %ERRORLEVEL%
-1073741819

I have no clue what is the problem, since both compile without problem

Running second one with debugger leads to this error:

Exception thrown at 0x744106F2 (KernelBase.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0x00C47B68. occurred

gadelat
  • 1,390
  • 1
  • 17
  • 25

0 Answers0