Skip to main content
GameDev.net gamedev.net
🔒 Locked

Win32 Project Immediately Closing

Started by load_bitmap_file Jan 7, 2004 at 8:27 PM 4 replies 250+ views
Original Post
load_bitmap_file
load_bitmap_file
Hi, my utterly basic Win32 project is immediately closing whenever I run it. Does anyone know how to prevent this? Here's the code: (pretty much copied directly from the Windows Game Programming for Dummies book) #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <windowsx.h> #include <stdio.h> #include <math.h> #define WINDOW_CLASS_NAME "WINCLASS1" HWND main_window_handle = NULL; LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); } break; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return(0); } break; case WM_DESTROY: { PostQuitMessage(0); return(0); } break; default: break; } return(DefWindowProc(hwnd, msg, wparam, lparam)); } int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { //create window and initalize WNDCLASS winclass; HWND hwnd; MSG msg; winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; if(!RegisterClass(&winclass)) return(0); if(!(hwnd = CreateWindow(WINDOW_CLASS_NAME, "Hi", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 300, 200, NULL, NULL, hinstance, NULL))) main_window_handle = hwnd; while(1) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(msg.message == WM_QUIT) {break;} TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); } return 1; } please respond [edited by - load_bitmap_file on January 7, 2004 9:29:00 PM]
UltimaX
UltimaX
Take the return(msg.wParam); out and replace the return 1; with it. You're returning on the first pass of the loop.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on January 7, 2004 9:34:44 PM]
load_bitmap_file
load_bitmap_file
you''re right. whoops, left that return in the wrong block. anyway thanks. by the way, when I yank the source code that came with the book it doesn''t compile correctly (those bums). the compiler returns a

error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup

do you know what that happens? is it a compiler setting or something? (using visual studio .net 2003)


UltimaX
UltimaX
That''s an error when you make a Win32 application and don''t include the main entry point for the application.

This:

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline,
int ncmdshow)
{
//--
}

function.

If you make a test Win32 application and try it, it should return the >>error LNK2001: unresolved external symbol _WinMain@16<< but as soon as you add a resource script, it will become >>error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup<<. So I''m guessing the sample application is using a resource script? In both cases just add the WinMain function and you should be fine.


-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"
UltimaX
UltimaX
You''re Welcome

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.