473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

WinMain()

i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){

while(1)
;

}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?
Jul 3 '08 #1
10 3483
Jrdman <ah*********@gmail.comwrote:
i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){
while(1)
;
}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?
The difference is that main() is the start of a standard compliant
C program, understood by all C compilers, while the above is some
"dialect" of C that may be understood by (some?) compilers on Win-
dows machines but hardly anywhere else. So, unless you have some
specific needs that require the use of this "dialect", better stick
with main() (and also avoid <windows.hwhich also is only available
on Windows machines).
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jul 3 '08 #2
Jrdman wrote:
i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){

while(1)
;

}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?
One of them isn't required to work (by the C standard), and the other is
(on a conforming implementation).

--
"I don't make decisions. I'm a bird." /A Fine and Private Place/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

Jul 3 '08 #3
Chris Dollin said:
Jrdman wrote:
>i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){

while(1)
;

}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?

One of them isn't required to work (by the C standard), and the other is
(on a conforming implementation).
The C Standard /does/ require the WinMain code to work under freestanding
implementations (such as, for example, Win32 compilers) that allow that
code as a legal entry point syntax for a C program. See C89 2.1.2.1:

"In a freestanding environment (in which C program execution may take place
without any benefit of an operating system), the name and type of the
function called at program startup are implementation-defined. There are
otherwise no reserved external identifiers. Any library facilities
available to a freestanding program are implementation-defined."

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #4
Jrdman wrote:
i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){

while(1)
;

}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?
To avoid the console window you have to tell the linker
that your program is a windows application. How do you do
this is specific to the compiler system. If you use
lcc-win, for instance, you should add
lc myprog.c -subsystem windows

or

lcc -c myprog.c
lcclnk -subsystem windows myprog.obj

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jul 3 '08 #5
On Jul 3, 1:53*pm, jacob navia <ja...@nospam.comwrote:
Jrdman wrote:
i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
* * * * * * * * * * *HINSTANCE hpinstance,
* * * * * * * * * * *LPSTR lpcmdline,
* * * * * * * * * * *int cmdshow){
* * * *while(1)
* * * *;
* * * *}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?

To avoid the console window you have to tell the linker
that your program is a windows application. How do you do
this is specific to the compiler system. If you use
lcc-win, for instance, you should add
lc myprog.c -subsystem windows

or

lcc -c myprog.c
lcclnk -subsystem windows myprog.obj

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatiquehttp://www.cs.virginia.edu/~lcc-win32
how to avoid the console window with the compiler MinGW of Dev-C++?
Jul 3 '08 #6
Richard Heathfield wrote:
Chris Dollin said:
>Jrdman wrote:
>>i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
.... snip ...
>>>
and when i excute it,it gives me a console window like the
ordinary one that we get when we use main().so what's the
difference between main() and WinMain() in ths case?

One of them isn't required to work (by the C standard), and the
other is (on a conforming implementation).

The C Standard /does/ require the WinMain code to work under
freestanding implementations (such as, for example, Win32
compilers) that allow that code as a legal entry point syntax for
a C program. See C89 2.1.2.1:
While your statement is perfectly true, bringing it up here simply
obscures the important points made by other replies.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

Jul 3 '08 #7
Jrdman <ah*********@gmail.comwrites:
[...]
how to avoid the console window with the compiler MinGW of Dev-C++?
Consulting the documentation would be a good start.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 3 '08 #8
CBFalconer said:
Richard Heathfield wrote:
>Chris Dollin said:
>>Jrdman wrote:

i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
... snip ...
>>>>
and when i excute it,it gives me a console window like the
ordinary one that we get when we use main().so what's the
difference between main() and WinMain() in ths case?

One of them isn't required to work (by the C standard), and the
other is (on a conforming implementation).

The C Standard /does/ require the WinMain code to work under
freestanding implementations (such as, for example, Win32
compilers) that allow that code as a legal entry point syntax for
a C program. See C89 2.1.2.1:

While your statement is perfectly true, bringing it up here simply
obscures the important points made by other replies.
No, it doesn't. It expands on those other points. This is a newsgroup about
C, not just "C on hosted implementations".

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #9
On Thu, 03 Jul 2008 13:13:19 +0000, Richard Heathfield wrote:
Chris Dollin said:
>Jrdman wrote:
>>i wrote this code :
#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){

while(1)
;

}
and when i excute it,it gives me a console window like the ordinary
one that we get when we use main().so what's the difference between
main() and WinMain() in ths case?

One of them isn't required to work (by the C standard), and the other
is (on a conforming implementation).

The C Standard /does/ require the WinMain code to work under
freestanding implementations (such as, for example, Win32 compilers)
that allow that code as a legal entry point syntax for a C program. See
C89 2.1.2.1:
I'm curious, does that apply even if you need to use a non-standard header
(or similarly, identifiers such as __stdcall) which would otherwise render
the code undefined? If an implementation defines WinMain with the given
declaration as the correct entry point, must this program be accepted?

#include<windows.h>
int APIENTRY WinMain(HINSTANCE hinstane,
HINSTANCE hpinstance,
LPSTR lpcmdline,
int cmdshow){
int APIENTRY = 0;
return APIENTRY;
}

I assume non-standard headers are permitted to define non-reserved
identifiers as macros, so the implementation may legitimately reject my
code. If so, who's to say in the original example that <windows.hdoesn't
define int, hinstance, hpinstance, lpcmdline, cmdshow, or while as a macro?
Jul 3 '08 #10
Harald van D?k said:
On Thu, 03 Jul 2008 13:13:19 +0000, Richard Heathfield wrote:
<snip>
>The C Standard /does/ require the WinMain code to work under
freestanding implementations (such as, for example, Win32 compilers)
that allow that code as a legal entry point syntax for a C program. See
C89 2.1.2.1:

I'm curious, does that apply even if you need to use a non-standard
header (or similarly, identifiers such as __stdcall) which would
otherwise render the code undefined?
All I can sensibly say about this is that you would need to consult the
implementation's documentation to find out how to play nice with the entry
point.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Sgier | last post by:
Hi While trying to compile the follwoing example with devC++ I get errors: D:\SDL-1.2.7MingW\lib\libSDLmain.a(SDL_win32_main.o.b)(.text+0x34b) In function `console_main': undefined reference...
2
by: Michael Sgier | last post by:
Hi While trying to compile the follwoing example with devC++ I get errors: D:\SDL-1.2.7MingW\lib\libSDLmain.a(SDL_win32_main.o.b) (.text+0x34b) In function `console_main': undefined...
2
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been...
1
by: Helen | last post by:
Hi I am trying to compile a package of avi to mpeg1 C source codes by Visual C++ 6.0. But I got the link error --------------------Configuration: AviMp1 - Win32 Debug--------------------...
1
by: Steve Richter | last post by:
I am working from the C++ .net step by step book ... my project compiles and runs as a console application: #include "stdafx.h" #using <mscorlib.dll> #using <System.dll> #using...
2
by: mahmoudlemeny | last post by:
Hi I was wondering if someone can help me with this. I am modifying a code that is an interface to a scanner. In the code there is a main function and when I try to debug it , it gives two errors: ...
11
Hunderpanzer
by: Hunderpanzer | last post by:
Hey guys. I'm trying to learn some windows programming, but i'm getting some errors with the code: #include <windows.h> // include the basic windows header file // the entry point for any...
12
by: eric dexter | last post by:
I want to compare what I get on the command line in winmain with an if statement.. I am getting a beginers error but I don't have an example to use to fix it.. cannot convert from 'const int' to...
7
by: jessy | last post by:
i have a date picker js file which i downloaded and used in my script ..the problem is that this script is able to write the picked date even in disabled fields i have a date field which is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.