Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

who passes all four arguments to winmain(...)

34 views
Skip to first unread message

Nagrik

unread,
Apr 22, 2013, 1:17:19 PM4/22/13
to
Hello Group,

I am just a beginner in learning win32 api. The winmain

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

takes 4 arguments. When I run this programme in visual studio, I am
not passing any arguments on command line. I am comparing it with C/C+
+ main, where if you use main, which takes two arguments the user has
to pass those arguments on the command line. But this is not the case
over here.

I am totally confused and want to understand the structure of Win32
API, and how does my program get the values of each parameters
declared in WinMain.

Could some person guide me in the right direction please.

Thanks

vandana

ScottMcP [MVP]

unread,
Apr 22, 2013, 2:12:24 PM4/22/13
to
These arguments are passed by the operating system. You should usually save a copy of hInstance because you may need to pass it to some API calls. If there is a command line you receive a pointer to it in lpCmdLine. (The user can enter a command line, even for a GUI program. And you can create a command line in the Visual Studio debugger settings if you want to pass a command line when debugging.) But so many things have changed since WinMain was defined years ago it is better to call GetCommandLine if you want to process a command line.

>> how does my program get the values of each parameters declared in WinMain?

The same way it gets the parameters passed to any other function. The only thing different about WinMain is that most of its parameters have become useless over the years.

If you can explain what is confusing you perhaps someone can be more help.

By the way, there is a much more active forum for Windows C++ programming questions at:

http://social.msdn.microsoft.com/forums/en-US/vcgeneral/threads/



Deanna Earley

unread,
Apr 23, 2013, 4:01:57 AM4/23/13
to
On 22/04/2013 18:17, Nagrik wrote:
> Hello Group,
>
> I am just a beginner in learning win32 api. The winmain
>
> int APIENTRY _tWinMain(HINSTANCE hInstance,
> HINSTANCE hPrevInstance,
> LPTSTR lpCmdLine,
> int nCmdShow)
>
> takes 4 arguments. When I run this programme in visual studio, I am
> not passing any arguments on command line. I am comparing it with C/C+
> + main, where if you use main, which takes two arguments the user has
> to pass those arguments on the command line. But this is not the case
> over here.

They don't HAVE to pass the parameters on the command line, but if they
do, they'll be available in arg*.
With _tWinMain, the command line parameters (if any) will be passed as
lpCmdLine.
The others parameters have meanings, but in most cases can be ignored if
you don;t need them.

--
Deanna Earley (dee.e...@icode.co.uk)
iCatcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored. Please reply to the
group.)
0 new messages