"Unresolved external _WinMain @ 16" if I transfer WndProc to another cpp file

For a Windows application, I am trying to get CreateWindow()and WndProc()(or my versions of them) as part of a singleton class created at the beginning _tWinMain(), but since I am trying to shift functions GameHandler.hand GameHandler.cppI continue to get the "unresolved external symbol _WinMain @ 16". Originally they were global functions in main.cpp, and everything was well compiled, then I decided to move them to GameHandler, and since all that I get is unresolved external, even if I try to move them back to main.cpp.

I do this in VS2010, the project was created as a Windows application, and there are no specific entry points in the properties (I checked twice how all the solutions that I have found so far say that this is because this is a console application - it is not So).

The code I currently have is shown below. The actual project has several thousand lines of other code that I forgot, because I do not think it is relevant (but it will be joyfully mistaken. Although the actual code for creating the window is connected, I do not think the code itself (except for what I left) , this is the location of GameWindowProc () & / or CreateGameWindow () or the way they call. The actual window creation code is taken from the NeHe Tutorial . Trying to compile the following code gives only the aforementioned unresolved external.

main.cpp:

#include <Windows.h>
#include "GameManager.h"

#ifndef USEGMGR
bool CreateGameWindow(char* title, int width, int height, int bits, bool fullScreenFlag);
LRESULT CALLBACK GameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif

int APIENTRY _tWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, 
                        LPTSTR lpCmdLine, int nCmdShow)
{
    GameManager::Startup();
    GameManager* GMgr = GameManager::GetInstance();

    GMgr->SetProgramState(GAME_MODE);
    while(GMgr->GetProgramState() != GAME_MODE) // Normally this would be if (State != GAME_QUIT)
    { /* do game related stuff */ }

    GameManager::Shutdown();
    return 0;
}

#ifndef USEGMGR
bool CreateGameWindow(char* title, int width, int height, int bits, bool fullScreenFlag)
{
    // Fairly complex but flexible creation code, taken from NeHe tutorials. Of relevant interest is:
    WNDCLASS        wc;                             // Windows Class Structure
    wc.lpfnWndProc  = (WNDPROC) GameWindowProc;  // WndProc Handles Messages
    if (!RegisterClass(&wc))                         // Attempt To Register The Window Class
    {
        MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return false;
    }
    return true;
}

LRESULT CALLBACK GameWindowProc(HWND    hWnd,            // Handle For This Window
    UINT    uMsg,            // Message For This Window
    WPARAM    wParam,            // Additional Message Information
    LPARAM    lParam)            // Additional Message Information
{
    // various custom message handling, if not processed:
    return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
#endif

in GameManager.h:

#ifndef GAMEMANAGER_H
#define GAMEMANAGER_H
#define USEGMGR // makes CreateGameWindow() and GameWindowProc() methods in GameManager instead of global

#include <Windows.h>

enum ProgramState
{
    GAME_MODE,
    GAME_QUIT,
};

class GameManager
{
public:
    static void             Startup();
    static void             Shutdown();
    static GameManager*     GetInstance();
    void                    Update(); // code not shown, check quit key etc
#ifdef USEGMGR
    const bool              CreateGameWindow(char* title, int width, int height, int bits, bool fullScreenFlag);
    static LRESULT CALLBACK GameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif
    void                    KillGameWindow(void);
    const int                GetProgramState() const;
    void                    SetProgramState(const int& newMode);
private:
    GameManager();
    ~GameManager();
    GameManager(const GameManager&);
    GameManager& operator=(const GameManager&);
    HINSTANCE                m_hInstance;
    HWND                    m_hWnd;        
    HDC                        m_hDC;        
    static GameManager*        s_instance;
    int                        m_programState; // uses ProgramState enum
};
#endif

in GameManager.cpp:

#include "GameManager.h"
#include <Windows.h>
#include <assert.h>

#ifndef USEGMGR
extern bool CreateGameWindow(char* title, int width, int height, int bits, bool fullScreenFlag);
#endif
GameManager*        GameManager::s_instance    = NULL;
GameManager::GameManager(){}
GameManager::~GameManager(){}


void GameManager::Startup()
{
    assert(s_instance == NULL);
    s_instance = new GameManager;
#ifdef USEGMGR
    if (! (s_instance->CreateGameWindow("Game Window", 800, 600, 32, true )) )
#else
    if (! (CreateGameWindow("Game Window", 800, 600, 32, true )) )
#endif
        assert("CreateGameWindow failed! Need an error here"); // Quit If Window Was Not Created - clean this up later    
}

void GameManager::Shutdown()
{
    assert(s_instance != NULL);
    delete s_instance;
    s_instance = NULL;
}

GameManager* GameManager::GetInstance(){return s_instance;}

void GameManager::Update(){/* msg handling, watch for quit key, etc */}
const int GameManager::GetProgramState() const{return s_instance->m_programState;}
void GameManager::SetProgramState(const int& newState){s_instance->m_programState = newState;}

#ifdef USEGMGR
const bool GameManager::CreateGameWindow(char* title, int width, int height, int bits, bool fullScreenFlag)
{
    // Fairly complex but flexible creation code, taken from NeHe tutorials. Of relevant interest is:
    WNDCLASS        wc;                             // Windows Class Structure
    wc.lpfnWndProc  = (WNDPROC) GameManager::GameWindowProc;  // WndProc Handles Messages
    if (!RegisterClass(&wc))                         // Attempt To Register The Window Class
    {
        MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return false;
    }
    return true;
}

LRESULT CALLBACK GameManager::GameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    // various custom message handling, if not processed:
    return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
#endif    

, , main.cpp GameManager. #define USEGMGR GameManager.h, func main.cpp.

-, , , ?

: , .

+3
2

#include <tchar.h>

main.cpp, _tWinMain .

, , _tWinMain() ( ?_tWinMain@@YGHPAUHINSTANCE__@@0PADH@Z()), WinMain() wWinMain(). .

<tchar.h> , _tWinMain() , , . -, , (, ) - .

WinMain wWinMain ( , , UNICODE ). , LPTSTR , .

+2

WinMain - , "singleton".

" " , main, ++, .

Unresolved external _WinMain@16 - , WinMain ( ).

+5

All Articles