How could i pass a structure as CmdLine parameter while using CreateProcess?

Hi all,
While i use

CreateProcess(
LPCWSTR pszImageName,
LPCWSTR pszCmdLine,
LPSECURITY_ATTRIBUTES psaProcess,
LPSECURITY_ATTRIBUTES psaThread,
BOOL fInheritHandles,
DWORD fdwCreate,
LPVOID pvEnvironment,
LPWSTR pszCurDir,
LPSTARTUPINFOW psiStartInfo,
LPPROCESS_INFORMATION pProcInfo
);
I want to pass a structure as second parameter(pszCmdLine) in this function. But somehow child process can't correctly get the structure! Should i do anything like "cast" or.. before i pass it? thanks for any advice!

[603 byte] By [ginee] at [2007-12-16]
# 1
Since the string is null terminating passing a structure isn't plausible like it is with sockets. You will have to communicate your binary data through a named pipe or another IPC method.
RITZ at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 2

RITZ wrote:
Since the string is null terminating passing a structure isn't plausible like it is with sockets. You will have to communicate your binary data through a named pipe or another IPC method.

According to the MSDN document, system will append NULL (in unicode is \0\0) to the command line argument. But i thought i can still get correct infromation while child process get pszCmdLine and cast it to the propriated point i want. Actually the CreateProcess is invoking a window application, the part of the code is like:

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPWSTR lpCmdLine, int nCmdShow) {
MSG msg;
HWND hwndMain;
RILSUPSERVICEDATA* ServiceData;

// Initialize this instance.
hwndMain = InitInstance (hInstance, lpCmdLine, nCmdShow);

if(*lpCmdLine != NULL)
ServiceData = (RILSUPSERVICEDATA*) ussd;
.
.
.

Does it cause any problem in this way?

ginee at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 3
You kinda missed the point. Strings can be null terminating because you know that a null character will not occur and when the delimiter is encountered you have for sure reached the end of the string. With binary data like an int you can encounter a byte that just happends to equal 0 which will terminate the string. For example, 4294967040 in a 4 byte unsigned int would read byte by byte as 255, 255, 255, NULL. Well, that string is parsed and it hits that null byte and stops reading the rest of the data.
RITZ at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 4
If the structure is small and a POD, you can encode the stuff in base64 and decode it in the process.
MartinRichter at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 5
Thats a suitable solution if you absolutely need to pass the data through the command line, otherwise it is more efficient to transfer the data through a pipe. But as Martin said, if it is small then that is just fine.
RITZ at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...
# 6
When you know what your are dealing with ( here structure ) then convert all contents of the structure members to a wide string and seperate each field with a special character.

A pointer to a widestring is only pointer to a character terminated with double 0. The CreateProcess function does check the contents of pszCmdLine i think so pass the address of the structure and make a typecast. Maybe that works.
Bye
Martin

maddinthegreat at 2007-9-9 > top of Msdn Tech,Visual C++,Visual C++ Language...