Correct me if im wrong

See this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  PSTR szCmdLine, int iCmdShow)
{
  MSG         msg;
  static int  iTickTrigger = 0;
  int         iTickCount;

  if (GameInitialize(hInstance))
  {
    // Initialize the game engine
    if (!GameEngine::GetEngine()->Initialize(iCmdShow))
      return FALSE;

    // Enter the main message loop
    while (TRUE)
    {
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
        // Process the message
        if (msg.message == WM_QUIT)
          break;
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      else
      {
        // Make sure the game engine isn't sleeping
        if (!GameEngine::GetEngine()->GetSleep())
        {
          // Check the tick count to see if a game cycle has elapsed
          iTickCount = GetTickCount();
          if (iTickCount > iTickTrigger)
          {
            iTickTrigger = iTickCount +
              GameEngine::GetEngine()->GetFrameDelay();
            HandleKeys();
            GameEngine::GetEngine()->CheckJoystick();
            GameCycle();
          }
        }
      }
    }
    return (int)msg.wParam;
  }

  // End the game
  GameEnd();

  return TRUE;
}

As far as i can tell WinMain() is returning a TRUE value, i do see the "return (int)msg.wParam;" but its not where it should be???? This is out of my book. The program works with this btw.


There isn't anything wrong with having more than one 'return' in your functions, including main (except that it might sometimes make them hard to understand) nor with returning something else than 0 from main, though a value other than 0 is usually understood as some sort of failure.
This code returns msg.wParam if GameInitialize succeeds and 1 otherwise.
But GameInitialize has the type of bool?
But GameInitialize has the type of bool?


What does that have to do with anything? I am telling you, put that book of yours away and learn programming before you start reading it again. There is nothing wrong with seeking help once in a while, but quite frankly I get the impression you go here after every single chapter because you have absolutely no idea what is going on.
closed account (3hM2Nwbp)
You might want to take a look at this page that describes the windows data types. It should provide a bit more insight for you.

http://msdn.microsoft.com/en-us/library/aa383751%28v=vs.85%29.aspx

additionally:

MSDN wrote:
The type "BOOL" is a Windows type, and it's just a typedef for int.


So even though it may appear that you're returning different data types, under the hood, you are in fact returning what the method declaration is expecting. I'd question returning a boolean value from a method that is declared to return an int as well.
Last edited on
Luc Lieber, thanks!

So thats why WinMain() can return TRUE, so is that the same as returning 1, seeing as TRUE == 1?
closed account (3hM2Nwbp)
I can't definitively say that TRUE == 1, only that TRUE != 0.

Welcome to Windows Programming. This is the first of many windows-isms that you'll encounter. Be prepared to be looking through the WINAPI documentation 95% of the time and coding the other 5% until you memorize the many hacks decisions that Microsoft has made to preserve backward compatibility.
That's not particular to Windows programming. Any non-zero numerical value is considered true in a boolean context in C and in C++ (and in many other languages).
I think he was just talking about the TRUE and FALSE macros there.
Topic archived. No new replies allowed.