   [Help] WinMain
  I've been trying to fix this for a while now and can't seem to get it to work. Could any of you figure this out please?I've added "Checkpoints" within the WinMain function to know what works and where it stops.I get to Checkpoint 10 and the Title and Class check after it and then it breaks at the last parameter for CreateWindowEx(). I click continue and then it goes to the 2nd AK.exe break in the call stack and won't go any further.Call stack at break: user32.dll!7714dff7()  [Frames below may be incorrect and/or missing, no symbols loaded for user32.dll] AK.exe!WinMain(HINSTANCE__ * hInstance=0x010f0000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x003026c2, int nCmdShow=1)  Line 235C++>AK.exe!__tmainCRTStartup()  Line 527 + 0x1c bytesC kernel32.dll!775cd0e9()  ntdll.dll!776a19bb()  ntdll.dll!776a198e() -------------------------------------------------------------------------------#include <sstream>#include <iostream>#include "winmain.h"//macro to read the key states#define KEY_DOWN(vk) ((GetAsyncKeyState(vk) & 0x8000)?1:0)HINSTANCE g_hInstance;HWND g_hWnd;int g_nCmdShow;//declare global engine objectAKEngine::Engine *g_akengine;bool gameend;//window event callback functionLRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){switch(msg){case WM_CREATE:case WM_QUIT:case WM_CLOSE:case WM_DESTROY:gameend = true;break;default:return DefWindowProc(hWnd, msg, wParam, lParam);}//return DefWindowProc(hWnd, msg, wParam, lParam);return 0;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){MSG msg;srand((unsigned int)time(NULL));g_hInstance = hInstance;g_nCmdShow = nCmdShow;DWORD dwstyle, dwExstyle;RECT windowRect;MessageBox(g_hWnd, "Checkpoint: 1", "AK Engine Checkpoint", MB_OK);/*** Create engine object first!**/g_akengine = new AKEngine::Engine();MessageBox(g_hWnd, "Checkpoint: 2", "AK Engine Checkpoint", MB_OK);//Game enters here and says version.if (!game_preload()) {MessageBox(g_hWnd, "Failed to preload game.", "AK Engine Error", MB_OK);return 0;}MessageBox(g_hWnd, "Checkpoint: 3", "AK Engine Checkpoint", MB_OK);char AKClass[] = "AKClass";sprintf_s(AKClass, "%s", g_akengine->getAppClass().c_str());//get window caption string from enginechar title[255]; //sprintf is what sets the value to it.sprintf_s(title, "%s", g_akengine->getAppTitle().c_str() );MessageBox(g_hWnd, "Checkpoint: 4", "AK Engine Checkpoint", MB_OK);//set window dimensionswindowRect.left = (long)0;windowRect.right = (long)g_akengine->getScreenWidth();windowRect.top = (long)0;windowRect.bottom = (long)g_akengine->getScreenHeight();MessageBox(g_hWnd, "Checkpoint: 5", "AK Engine Checkpoint", MB_OK);//create the window class structureWNDCLASSEX wcex;//fill the struct with infowcex.cbSize = sizeof(wcex);//wcex.cbSize = sizeof(WNDCLASSEX);wcex.style = CS_HREDRAW | CS_VREDRAW;wcex.lpfnWndProc= (WNDPROC)WndProc; //WndProc above.wcex.cbClsExtra= 0;wcex.cbWndExtra= 0;//wc.cbClsExtra = wc.cbWndExtra = 0;wcex.hInstance= g_hInstance;wcex.hIcon= NULL; //Icon = LoadIcon(g_hInstance, IDI_APPLICATION);wcex.hCursor= LoadCursor(NULL, IDC_ARROW); //Cursorwcex.hbrBackground= (HBRUSH)COLOR_WINDOW; //NULLwcex.lpszMenuName= NULL;wcex.lpszClassName= AKClass; //prev titlewcex.hIconSm= NULL; //Small Icon = LoadIcon(g_hInstance, IDI_APPLICATION);//wcex.hIconSm= LoadIcon(wc.hInstance, (LPCTSTR)IDI_SMALL);MessageBox(g_hWnd, "Checkpoint: 6", "AK Engine Checkpoint", MB_OK);//set up the window with the class info//RegisterClassEx(&wcex);MessageBox(g_hWnd, "Checkpoint: 7", "AK Engine Checkpoint", MB_OK);if (!RegisterClassEx(&wcex)){MessageBox(g_hWnd, "Register Class Error" , "AK Engine Error", MB_OK);return (0);}MessageBox(g_hWnd, "Checkpoint: 8", "AK Engine Checkpoint", MB_OK);//set up the screen in windowed or fullscreen modeif (g_akengine->getFullscreen()){DEVMODE dm;memset(&dm, 0, sizeof(dm));dm.dmSize = sizeof(dm);dm.dmPelsWidth = g_akengine->getScreenWidth();dm.dmPelsHeight = g_akengine->getScreenHeight();dm.dmBitsPerPel = g_akengine->getColorDepth();dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {MessageBox(NULL, "Failed to create window", "AK Engine Error", MB_OK);g_akengine->setFullscreen(false);}dwstyle = WS_POPUP;dwExstyle = WS_EX_APPWINDOW;ShowCursor(FALSE);}else {dwstyle = WS_OVERLAPPEDWINDOW;dwExstyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;}MessageBox(g_hWnd, "Checkpoint: 9", "AK Engine Checkpoint", MB_OK);//adjust window to true requested sizeAdjustWindowRectEx(&windowRect, dwstyle, FALSE, dwExstyle);MessageBox(g_hWnd, "Checkpoint: 10", "AK Engine Checkpoint", MB_OK);//create the program windowg_akengine->message(AKClass, title);MessageBox(g_hWnd, LPCSTR(windowRect.right - windowRect.left), "Width", MB_OK);g_hWnd = CreateWindowEx( WS_EX_APPWINDOW, //WS_EX_TOPMOST,AKClass, //window classtitle, //title bardwstyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,0, 0, //x,y coordinates//1024, //width of the window//1024, //height of the windowwindowRect.right - windowRect.left, //width of the windowwindowRect.bottom - windowRect.top, //height of the windowNULL, //handle to parent window //no parent window so NULL?NULL, //menug_hInstance, //application instanceNULL); //lpParamMessageBox(g_hWnd, "Checkpoint: 11", "AK Engine Checkpoint", MB_OK);//was there an error creating the window?if (!g_hWnd){MessageBox(g_hWnd, "Failed to create program window.", "AK Engine Error", MB_OK);return (0);}MessageBox(g_hWnd, "Checkpoint: 12", "AK Engine Checkpoint", MB_OK);//display the windowShowWindow(g_hWnd, g_nCmdShow);UpdateWindow(g_hWnd);//initialize the engineg_akengine->setWindowHandle(g_hWnd);if (!g_akengine->Init(g_akengine->getScreenWidth(), g_akengine->getScreenHeight(), g_akengine->getColorDepth(), g_akengine->getFullscreen())) {MessageBox(g_hWnd, "Error initializing AK Engine!", "AK Engine Error", MB_OK);return (0);}//main message loopgameend = false;while (!gameend){while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){TranslateMessage(&msg);DispatchMessage(&msg);}g_akengine->Update();}if (g_akengine->getFullscreen()) {ShowCursor(TRUE); //when custom cursor is available, move outside this for windowed mode use.}game_end();delete g_akengine;return (1);}[edit: source tags are your friend -SiCrane][Edited by - SiCrane on June 15, 2009 7:11:32 PM]
  does "MessageBox(g_hWnd, LPCSTR(windowRect.right - windowRect.left), "Width", MB_OK);" every display?If it does I'm assuming you Checkpoint 11 never displays? If so double check every parameter you're passing into CreateWindowEx is what you think it is.also what IDE are you using id VS have you try'd debugging?also does it fail in window mode and fullscreen?   ;  No it doesn't, forgot about that one. I took it out now I get to checkpoint 12 and get "Error initializing AK Engine!" after it. I'm currently checking the parameters for g_akengine->Init().I'm currently using VS 2010 Beta 1.It creates the window(but you can only see the menu) and after about a second or two, the "Error initializing AK Engine!" message pops up. Currently it's NOT in Full Screen mode and should be 800x600(Default and set).[Edited by - TempAnon on June 16, 2009 2:00:30 AM];switch(msg){case WM_CREATE:case WM_QUIT:case WM_CLOSE:case WM_DESTROY:gameend = true;break;default:return DefWindowProc(hWnd, msg, wParam, lParam);}Are you familiar with the "fall through" behavior of switch statements? The WM_CREATE message is sent to the WndProc during the call to CreateWindowEx. In your program, when that happens, execution falls through the switch statement to WM_DESTROY where upon "break" jumps over default to return 0. That shouldn't be a problem with WM_CREATE, but it could be a problem later on. WM_QUIT isn't handled by the WndProc. It's sent by PostQuitMessage and is typically handled by the main message loop as an indicator to exit the loop. ...case WM_DESTROY:   PostQuitMessage(0);......while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ){ if ( WM_QUIT == msg.message ) {   break; // exit message loop } // dispatch message to the window proc TranslateMessage(&msg); DispatchMessage(&msg);}...;  You should try calling GetLastError  after the CreateWindowEx   function, or check if it returns null. If the function call to CreateWindowEx   succeeded it should return a handle to the new window.If it returns null call GetLastError  and use that value to look up what happened.