Sign in to follow this  

Strange errors when creating a boilerplate func

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

/* ================================================================================================== CreateWindow.cpp Purpose: Implements a boilerplate function to create a standard windows window. ================================================================================================== */ #include <windows.h> #include "WinMain.cpp" // Function header int CreateWindowFunc(UINT message, HWND hWnd, WPARAM wParam, LPARAM lParam, HINSTANCE hInstance, int nCmdShow); int CreateWindowFunc(UINT message, HWND hWnd, WPARAM wParam, LPARAM lParam, HINSTANCE hInstance, int nCmdShow) { PAINTSTRUCT ps; HDC hdc; char szTitle[] = "Moonlight Engine"; char szWindowClass[] = "Moonlight Engine"; HINSTANCE hInst; hInst = hInstance; hWnd = CreateWindow( szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 20, 20, 640, 480, NULL, NULL, hInstance, NULL); if (!hWnd) { return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); switch (message) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } Can anyone please tell me why this function generates these two errors when I try to call it from WinMain? c:\projects\test\createwindow.cpp(14) : warning C4182: #include nesting level is 362 deep; possible infinite recursion c:\projects\test\createwindow.cpp(14) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit WinMain.cpp c:\projects\test\winmain.cpp(1) : warning C4182: #include nesting level is 362 deep; possible infinite recursion c:\projects\test\winmain.cpp(1) : fatal error C1076: compiler limit : internal heap limit reached; use /Zm to specify a higher limit Error executing cl.exe.

Share this post


Link to post
Share on other sites
You #included WinMain.cpp. Don't #include .cpp files.

That said, your function will not behave as you expect. You can't have one function both create a window and process its message queue. Message queues are threaded constructs, meaning that the messages are posted to a separate thread, which need to be handled by a window procedure - which is passed in via the WNDCLASS[EX] structure, which you haven't employed.

Back to the drawing board.

Share this post


Link to post
Share on other sites
So basically my WinMain function should be in the same file as the CreateWindow func? Bah... isn't there a better way? :\ I want a completely independent function.

Share this post


Link to post
Share on other sites

This topic is 4817 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this