Sign in to follow this  
ac3

inherit class with virtual members from static library

Recommended Posts

I have just started with my first attempt at a game engine and I have a problem. I was looking for the best way to separate the engine from the game code and decided to use a static library (.lib file) and that works great except one thing.. I don't seem to be able to make a class in my game project inherit a class with virtual members in my engine project. The game project is linked to the engine project correctly and I can use it for everything except inheriting a class with virtual members. The specific thing I'm doing now is a win32 window wrapper class which is a base class in the engine that each real window in the game will inherit. The virtual method is the wndproc that needs to be different for each window. > error LNK2001: unresolved external symbol "public: virtual long __stdcall WndMain::wndproc(struct HWND__ *,unsigned int,unsigned int,long)" (?wndproc@WndMain@@UAGJPAUHWND__@@IIJ@Z) > fatal error LNK1120: 1 unresolved externals I get this ^^^^^^ note that there are two wndproc methods (stwndproc which is static and is no problem and then there wndproc which is virtual) basewindow.h (part of engine static library)
class BaseWindow
{
private:
	HINSTANCE inst;
	HWND wnd;
	WNDCLASSEX wc;
	char cn[256], t[256];
protected:
	BaseWindow(HINSTANCE hInstance);
	~BaseWindow();
public:
	static LRESULT CALLBACK stwndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	virtual LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	void create();
	void destroy();
// etc
};
basewindow.cpp (part of engine static library)
BaseWindow::BaseWindow(HINSTANCE hInstance)
{
	inst = hInstance;
	strcpy(cn, "default");
	strcpy(t, "untitled");

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = BaseWindow::stwndproc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = inst;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName = 0;
	wc.lpszClassName = cn;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
}

BaseWindow::~BaseWindow()
{
}

LRESULT CALLBACK BaseWindow::stwndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// irrelevant
}

LRESULT CALLBACK BaseWindow::wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

void Window::create()
{
// irrelevant
}

void Window::destroy()
{
// irrelevant
}
wndmain.h (part of game code)
class WndMain : public BaseWindow
{
public:
	WndMain(HINSTANCE hInstance);
	~WndMain();
	LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
wndmain.cpp (part of game code)
WndMain::WndMain(HINSTANCE hInstance) : BaseWindow(hInstance)
{
// irrelevant
}

WndMain::~WndMain()
{
// irrelevant
}

LRESULT CALLBACK wndproc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// irrelevant
}
Does anyone know why this is? I have never used a static library before so maybe the limitation is there?

Share this post


Link to post
Share on other sites
2 days of headache trying to figure it out testing different things... what was needed was new eyes looking at it. thank you very much!

Share this post


Link to post
Share on other sites

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