tags:

views:

164

answers:

2

Hi, what is the difference between CreateProcess and CreateProcessA, also are there any alternatives to these in VC++ 2008 ?

I have also a problem, that i use the CreateProcessA function, this works well in one system but fails in other systems.

Also when i use CreateProcess i get the error cannot convert 2 parameter from 'CHAR[40]' to 'LPWSTR' i am in unicode mode

+2  A: 

CreateProcess is identical to either CreateProcessA ("ANSI") or to CreateProcessW ("Wide characters"), depending on whether you're compiling your code without or with the unicode option enabled.

The difference is whether the string which you pass as a parameter should be an ANSI (8-bit character) or a unicode (16-bit character) string.


There are also alternatives, like ShellExecuteEx.

ChrisW
I have also a problem, that i use the CreateProcessA function, this works well in one system but fails in other systems. what may be reason. are there any other functions ?
rajivpradeep
@rajivpradeep - "what may be reason" What is the value returned by the `GetLastError()` function immedately after the call to `CreateProcessA` fails?
ChrisW
A is for "ANSI" but otherwise the answer is corret (ASCII is a 7 bit only character set)
Frank Bollack
Note that the A in CreateProcessA stands for [ANSI](http://en.wikipedia.org/wiki/Windows-1252), not for [ASCII](http://en.wikipedia.org/wiki/Ascii). Similar, but not the same.
0xA3
A corollary of this answer is: Only use `CreateProcess` and don't use `CreateProcessA` or `CreateProcessW` directly in your code.
0xA3
@rajivpradeep@ try using the `CreateProcess` function instead.
Frank Bollack
@Frank I don't see that making a difference, since any distinction between the two would be determined at compile-time not at run-time.
ChrisW
@Chris: if you refer to my last comment, you are right, it is a compile time issue and the compiler will most likely point you to the solution.
Frank Bollack
I am using CreatProcess now, but an error is showing that cannot convert 'char [40]' to 'LPWSTR', i am using unicode mode
rajivpradeep
Using CreateProcess in unicode mode is equivalent to using CreateProcessW. It requires an array of `wchar_t` instead of an array of `char`, for example `L"foo.exe"` instead of `"foo.exe"` (note the extra `L` to specify a wide-string literal). See also the `TCHAR` macro.
ChrisW
+2  A: 

First, CreateProcess is a macro that switches between CreateProcessA and CreateProcessW, which take strings in ANSI or Unicode, respectively. This depends on your project build settings (the character set project property), Unicode vs Multi-Byte. Generally, you want things to be in Unicode, as this allows for globalization and adds the option of allowing more supported languages.

The complaint in converting from char to LPCWSTR shows that it's expecting a type of WSTR, or wide string, or unicode string. A workaround is to declare your chars using the _T("blahblah") macro.

Stefan Valianu