Hallo,
I have a problem with the direct execution of a console programm from the IDE:
This is the code:
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <shellapi.h>
int __cdecl wmain(void)
{
LPWSTR *szArglist;
int nArgs;
int i;
printf("%ls\n", GetCommandLineW());
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if( NULL == szArglist )
{
wprintf(L"CommandLineToArgvW failed\n");
return 1;
}
else for( i=0; i<nArgs; i++) printf("[%d] [%ls]\n", i, szArglist[i]);
LocalFree(szArglist);
return(0);
}
This is a test call with 4 parameters.
D:\C\CMDLIN~1>cmdlinetst2 /1 "c:\pa\"th with blanks"\ /3 /4
The second parameter should have
a literal doublequote after the first 'a'. This has to be protected with the backslash
and
a backslash after the closing doublequote, to get a literal backslash at the parameters end.
If I execute this from CMD, I get:
cmdlinetst2 /1 "c:\pa\"th with blanks"\ /3 /4
[0] [cmdlinetst2]
[1] [/1]
[2] [c:\pa"th with blanks\]
[3] [/3]
[4] [/4]
This is exactly what I want!
From Pelles IDE I get:
D:\C\cmdlinetst\cmdlinetst2.exe /1 "c:\pa"th with blanks\" /3 /4
[0] [D:\C\cmdlinetst\cmdlinetst2.exe]
[1] [/1]
[2] [c:\path]
[3] [with]
[4] [blanks"]
[5] [/3]
[6] [/4]
The return value from GetCommandLineW() is not any more the real command line.
The \" is replaced by a single " and the "\ is turned to an \".
So I get garbage.
What exactly is happening here?
What is the function (sort of ExecProgram()) used to execute exe's from Pelles IDE?
czerny
Have others tested my examples?
Is the question to silly to answer or to difficult?
czerny
Quote from: czerny on October 13, 2011, 12:24:16 AM
This is the code:
/1 "c:\pa\"th with blanks"\ /3 /4
/1 "c:\pa"th with blanks\" /3 /4
Look closely... see any difference between your first and second command line?
The command I typed is allways the same.
What is different is the commandline GetCommandLineW() is returning.
That is the point!!!
czerny
No actually the point is that the two example command lines you typed are different... and in both cases the returned value is correct but, of course, different.
How do you know, what I have typed?
I have typed both times the same (first code in my post).
First: on the command line
Second: in the IDE
And I got two different results.
Try it!
czerny
Only in the console program.
#define UNICODE
#define _UNICODE
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#pragma comment(lib, "user32")
// /1 "c:\pa\"th with blanks"\ /3 /4 <- copy that to project Command line arguments:
//int __cdecl WinMainCRTStartup(void)
int __cdecl mainCRTStartup(void)
{
TCHAR szTmp[260];
lstrcpy(szTmp, L"/1 \"c:\\pa\\\"th with blanks\"\\ /3 /4\n");
lstrcat(szTmp, GetCommandLineW());
OutputDebugString(szTmp);
MessageBoxW(0, szTmp, 0, MB_OK);
ExitProcess(0);
}
EDIT:
Console:ODS: /1 "c:\pa\"th with blanks"\ /3 /4
C:\code\PellesC\Forum\TestGetCommandLineW3.exe /1 "c:\pa"th with blanks\" /3 /4
Windows:ODS: /1 "c:\pa\"th with blanks"\ /3 /4
"C:\code\PellesC\Forum\TestGetCommandLineW3.exe" /1 "c:\pa\"th with blanks"\ /3 /4
Quote from: czerny on November 02, 2011, 08:29:41 AM
How do you know, what I have typed?
I'm going by the examples you gave in your first message...
cmdlinetst2 /1 "c:\pa\"th with blanks"\ /3 /4
[0] [cmdlinetst2]
[1] [/1]
[2] [c:\pa"th with blanks\]
[3] [/3]
[4] [/4]
and
D:\C\cmdlinetst\cmdlinetst2.exe /1 "c:\pa"th with blanks\" /3 /4
[0] [D:\C\cmdlinetst\cmdlinetst2.exe]
[1] [/1]
[2] [c:\path]
[3] [with]
[4] [blanks"]
[5] [/3]
[6] [/4]
Quote
I have typed both times the same (first code in my post).
Nope... you didn't. Seriously... look again!
Ok, I tried it once more.
This is was I had in the project options in the IDE:
/1 "c:\pa\"th with blanks"\ /3 /4
and I got:
D:\C\cmdlinetst\cmdlinetst2.exe /1 "c:\pa"th with blanks\" /3 /4
[0] [D:\C\wwl\cmdlinetst\cmdlinetst2.exe]
[1] [/1]
[2] [c:\path]
[3] [with]
[4] [blanks"]
[5] [/3]
[6] [/4]
Press any key to continue...
then I added the command name and copied and pasted the result to the commandline
cmdlinetst2 /1 "c:\pa\"th with blanks"\ /3 /4
and I got:
cmdlinetst2 /1 "c:\pa\"th with blanks"\ /3 /4
[0] [cmdlinetst2]
[1] [/1]
[2] [c:\pa"th with blanks\]
[3] [/3]
[4] [/4]
Isn't that the same I posted the first time?
czerny
Test this example in POIDE with commandline:
/1 "c:\pa\"th with blanks"\ /3 /4
with and without #define CON
and see what czerny has found
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <shellapi.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "shell32.lib")
//#define CON
#ifdef CON
#pragma comment(linker, "/SUBSYSTEM:CONSOLE")
int __cdecl mainCRTStartup(void)
#else
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
int __cdecl WinMainCRTStartup(void)
#endif
{
LPWSTR *szArglist;
int nArgs;
int i, idx;
TCHAR sTmp[1024];
idx = wsprintf(sTmp, TEXT("%ls\n"), GetCommandLineW());
OutputDebugString(sTmp);
szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (NULL == szArglist)
{
OutputDebugString(L"CommandLineToArgvW failed\n");
return 1;
}
else
for (i = 0; i < nArgs; i++)
idx += wsprintf(&sTmp[idx], TEXT("[%d] [%ls]\n"), i, szArglist[i]);
OutputDebugString(sTmp);
MessageBox(0, sTmp, 0, MB_OK);
LocalFree(szArglist);
return (0);
}
Hmm,
what does this mean?
One would expect, that the CON variant behaves like the cmd, but this is not the case.
Can someone explain this?
czerny
Hallo timovjl and CommonTater and others,
I do not understand your response.
Don't you see that
the commandline tipped in and
the commandline shown from GetCommandLineW
are different
if you run this from within the IDE?
czerny