Skip to main content
gamedev.net
🔒 Locked

Garbage from Command Line

Started by ms291052 May 8, 2004 at 2:13 PM 4 replies 300+ views
Original Post
ms291052
ms291052
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 ?
Aprosenf
Aprosenf
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;
}
ms291052
ms291052
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?
ms291052
ms291052
I got it working with GetCommandLine() but ever with cmdlind. Odd, but atleast it is working.
Thunder_Hawk
Thunder_Hawk
Does your system use unicode?

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
BriTeg
BriTeg
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

Brianmiserere nostri <font color=#BC

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.