I'm using Visual C++.NET. I need to pass a port number to my gui. What the syntax for passing arguments to "int __stdcall WinMain()." For regular C++ it would be "int main(int argc, char* argv[])" Thanks.
the third param to WinMain to get command line as ascii
GetCommandLine() to get the command line as unicode
CommandLineToArgvW() to convert it to an array of strings if necessary
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
);
lpCmdLine [in] Pointer to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function.
Then parse the lpCmdLine string. (REMEMBER IT DOES NOT INCLUDE THE PROGRAM PATH).
Also, a Visual C++ dependent way is to use __argv and __argc as you would argv and argc. This only applies to 32-bit windows programs. 16-bit windows programs require you to declare the variables the following way:
Below is a simple example I found on MSDN. I added the #include <windows.h> but it still has an error. Am I forgetting to set something in my environment? I'm using Visual C++.NET 2003.
error C2731: 'WinMain' : function cannot be overloaded
#undef MessageBox // undefine the MessageBox macro of windows.h to use the managed MessageBox class
void __stdcall WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
long lpCmdLine,
int nCmdShow)
{
System::Windows::Forms::MessageBox:how("Hello, Windows Forms");
}
I added stdafx.h/.cpp and now it's working. But, how do you detect that no arguments were passed in? I want to set a default value when arguments are not provided.
I added stdafx.h/.cpp and now it's working. But, how do you detect that no arguments were passed in? I want to set a default value when arguments are not provided.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.