Jump to content
  • Advertisement
Sign in to follow this  


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

Hey all, I've been doing c++ programming for a while, mostly for mathematical computations that school requires. Recently, I've wanted to tinker around with developing Windows applications, with the aim of working on a simple game. Thus far, my experience has been limited to "int main()". Of course windows apps use the winmain(). I've been looking at a lot of sample window programs and most I see use "int WINAPI WinMain()" and others use "int PASCAL WinMain". I've tried compiling code from both methods. So far I can only get the 'PASCAL' version to build properly- the other gives a 'symbols not loaded' error repeated. My question is: whats the difference between the two and is one better than the other for game development? Thanks for the insight, kotold

Share this post

Link to post
Share on other sites
Nothing, actually. PASCAL and WINAPI are macros that resolve to the same thing -- they're different only in semantic contexts.

They resolve to __stdcall, which is a compiler extension that indicates the calling convention of the function (which describes how parameters are passed and cleaned up). The decoration is neccessary in some form or another, the default in MSVC++ is __cdecl but everything in the Win32 API expects __stdcall.

Googling those terms can yeild more details.

Share this post

Link to post
Share on other sites
Well last time I did some window programming PASCAL was considered deprecated and obsolete so if I see it nowadays I assume it's some pretty old cold I"m looking at!

PASCAL, it is documented that this is obsolete. But it continues to appear in any number of Microsoft header files and is erroneously used in other parts of the documentation as if it still had meaning. It should be consistently replaced, as the documentation of the "Pascal calling convention" topic suggests, by WINAPI, in all other instances of the documentation. Microsoft has failed to actually delete it from all other documentation and from the header files and replace it as their own documentation says should be done.

Given it has been obsolete since the release of Windows NT 3.1, something like 15 years ago, there is no excuse for it to still exist in any documentation file (except the one saying it is obsolete) or header file. See also FAR.

If you are having problems with your compiler I'd question what version of MSVC you are using?

Anyways, if you create a default win32 project in C++ in Visual Studio 2008 it actually uses this for your winmain:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

where _tWinMain maps to either WinMain or wWinMain depending on if you are using Unicode or not. The default is to use unicode.
In reality I've had tons of old game programming code that failed to compile unless I switch to older multi-byte char setting unless I want to go through the old code and update all the strings to use Unicode!
You can see Visual Studio actually switch the define for you if you change your project options from unicode to multi-byte char set or vice-versa for yourself.

"The name WinMain is used by convention by many programming frameworks. Depending on the programming framework, the call to the WinMain function can be preceded and followed by additional activities specific to that framework.

Your WinMain should initialize the application, display its main window, and enter a message retrieval-and-dispatch loop that is the top-level control structure for the remainder of the application's execution. Terminate the message loop when it receives a WM_QUIT message. At that point, your WinMain should exit the application, returning the value passed in the WM_QUIT message's wParam parameter. If WM_QUIT was received as a result of calling PostQuitMessage, the value of wParam is the value of the PostQuitMessage function's nExitCode parameter. For more information, see Creating a Message Loop.

ANSI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. Note that lpCmdLine uses the LPSTR data type instead of the LPTSTR data type. This means that WinMain cannot be used by Unicode programs. The GetCommandLineW function can be used to obtain the command line as a Unicode string. Some programming frameworks might provide an alternative entry point that provides a Unicode command line. For example, the Microsoft Visual Studio C++ complier uses the name wWinMain for the Unicode entry point."

[Edited by - daviangel on July 5, 2008 11:48:58 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!