From: Luke D. <cod...@ho...> - 2007-05-25 16:04:21
|
----- Original Message ----- From: "Vincent Torri" <vt...@un...> To: "Julien Lecomte" <ju...@fa...> Cc: "MinGW Users List" <min...@li...> Sent: Friday, May 25, 2007 11:53 PM Subject: Re: [Mingw-users] CommandLineToArgvW is not working > > > On Fri, 25 May 2007, Julien Lecomte wrote: > >> Vincent Torri wrote: >> >> Using -Wall to have warnings enabled, and then hushing them up by using >> casts >> is a source of errors and undefined behavior. > > I am completely aware of the warnings and such things. But the API of > windows is crappy and you sometimes have to cast to remove warnings. Like > the directdraw 7 interface, for instance. > >>> Is the problem being the fact that I use the lpCmdLine parameter which >>> is >>> not a LPCWSTR ? >> >> Yes. A wide string and a c string are not the same, and nor are pointers >> to >> them. >> Why not use GetCommandLineW() as MSDN recommends ? > >>From the web page i mentioned in my previous mail : > > "ANSI GUI applications can use the lpCmdLine parameter of the WinMain > function to access the command-line string, excluding the program name." Yes, and if you only want the ANSI string then you should be calling CommandLineToArgvA() instead. Luke > > ==BOF test1.c== > #include <stdio.h> >> #include <windows.h> >> >> int APIENTRY >> WinMain (HINSTANCE hinstance, >> HINSTANCE hPrevInstance, >> LPSTR lpCmdLine, >> int nCmdShow) >> { >> int argc, i; >> LPWSTR *argv; >> // NB: Use 'W' versions and %ls in printf >> if ((argv = CommandLineToArgvW(GetCommandLineW(), &argc))) >> { >> // success... >> for (i = 0; i < argc; i++) >> printf("%d=%ls\n", i, argv[i]); >> // MSDN says to LocalFree the memory >> LocalFree(argv); >> } >> return 0; >> } >> ==EOF test1.c== >> $ gcc -o test1.exe test1.c && ./test1.exe --toto --tata >> >>> Actually, I would use the standard C main function, which would solve >>> all >>> my problems, but I create a window and I would need an HINSTANCE for it. >>> I >>> don't know how to create such variable. >> >> Actually HINSTANCE is the same as HMODULE so you can use >> GetModuleHandle(0) >> to get HINSTANCE of your process. > > I'll try that. Thank you > > Vincent Torri |