CreateProcess(/**/) causing segmentation fault.

Hello, my name is legolizard. I am not *totally* new to C++, but I need just a small bit of help. I need to use the CreateProcess() in my program, however it gives me a segmentation fault every time I run it, when I have done a very similar thing before with no errors. v.v

My code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <Windows.h>

int main(){
    STARTUPINFO suf;
    PROCESS_INFORMATION pi;
    memset(&suf, 0, sizeof(suf));
    memset(&pi, 0, sizeof(pi));
    suf.cb = sizeof(suf);
    CreateProcess(NULL,
                  L"\"C:\\Program Files (x86)\\ImageJ\\ImageJ.exe\"" ,// Could the error be here?
                  NULL,
                  NULL,
                  TRUE,
                  CREATE_NO_WINDOW,
                  NULL,
                  NULL,
                  &suf,
                  &pi);
    return 0;
}

Any adive would be greatly appreciated. Thank you. : )
More info: I am using MSVC++ compiler, but oddly it works(without the L) on MingW. O.o
:D I actually figured it out. There is a flag I found CREATE_UNICODE_ENVIROMENT that makes everything work. ^_^
Last edited on
do you need to inialise suf & pi?
I initialize them with memset() which takes a void* an int to fill the block and a size_t, to specify the number of bytes to fill.
Last edited on
Beware that CreateprocessW() does not take a const string as second argument, it could change it in some conditions, which will crash your application too.
Topic archived. No new replies allowed.