Jump to content
  • Advertisement

Archived

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

ms291052

Garbage from Command Line

This topic is 5214 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

In my windows app I have int WINAPI WinMain( HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow) { printf("%s\n", cmd); } and I can call it as just C:\> app C:\> app.exe C:\> app -flag C:\> app.exe -flag and no matter what I get garbage. Is there any rhyme or reason to why? All I want is the string so I can grab the flags, is that too much to ask from windows ?

Share this post


Link to post
Share on other sites
Advertisement
Don''t use stdin and stdout with a non-console application. Try something more like:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow)
{
MessageBox(NULL, // Parent window
cmdline, // String to display
"Command line", // Title
MB_OK); // Set of buttons (just OK button)

return 0;
}

Share this post


Link to post
Share on other sites
Thanks for your advice. I actually have a console for the purposes of debugging in the application too, so using cout, cin, printf, and all that jazz does work. However, I tried the same thing with MessageBox and got (different) garbage. Any more advice?

Share this post


Link to post
Share on other sites
Does your system use unicode?

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
The variable name in your WinMain prototype is "cmdline". The variable you are passing to printf is "cmd". Whoopsie.

Brian
miserere nostri Domine miserere nostri

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!