Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Floru

Parsing command line

This topic is 6936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi folks! I have created a simple Win32 application. Now the program starts from WinMain, right? I can give command line parametres for the program and read them from the LPSTR lpCmdLine-variable. But what if I have code for a ms-dos program and want to run it. The ms-dos program has also ability to read command line parametres: int main(int argc, char* argv[])... I just cannot run it like main(lpCmdLine), it doesn''t work. Also I cannot use the GetCommandLine function from Windows. I tested it and it didn''t work. The ms-dos program is supposed to work in a separate thread so I cannot use the CreateProcess funtion... I think I have to parse the command line parameter somehow before giving it to the main() function... Could someone please help?? Thanks for any help Floru

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the help but... It works if you wan''t to run it as a separate program using the system function. But I have to use the code from the dos program and start everything by calling it''s main not actually run a compiled program. It''s actually not a dos-program it''s made in ANSI-C and it''s supoosed to be used in many platforms.

Thanks for help
Floru

Share this post


Link to post
Share on other sites
I''m not sure about threading, so I won''t comment on that.

There is a CommandLineToArgvW function that sounds like what you''re looking for, except it handles unicode. Otherwise, you''ll have to parse the line yourself (which isn''t too hard). First, count the number of arguments (ie. number of whitespaces + 1), declare a char *argv[numargs], then loop allocating space for each arg and copying the sections from lpcmdline (don''t forget to null terminate).

aig

Share this post


Link to post
Share on other sites
I found accidentally a (easy) solution. Here it is if you wan''t to check it out...

DWORD dwArgc = 0;
LPSTR* lpszArgv = NULL;

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
dwArgc = (DWORD) __argc;
lpszArgv = __argv;

main(dwArgc, lpszArgv);
}

Well... what can I say? It works!

Floru

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!