Jump to content

CreateWindow() class function conflicts with CreateWindowA()?


Josh
 Share

Recommended Posts

#pragma once

#include "../../../le3.h"
#include <windows.h>

namespace le3
{

class WindowsWindow;

class WindowsWindowDriver : public WindowDriver
{
	LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
	int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow );
	public:
	virtual WindowsWindow* CreateWindow(const int& width,const int& height);
};

}

 

The compiler is complaining:

C:\Engine\engine\Drivers\Graphics\../../Drivers/Window/Windows/WindowsWindowDriver.h:16:73: error: macro "CreateWindowA" requires 11 arguments, but only 2 given

c:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/winuser.h:4328: error: 'CreateWindowA' declared as a 'virtual' field

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Right, but does that mean you can never have a class function called CreateWindow??? :D

 

 

Greetings,

 

This appears to be a common issue. Here's a quote from http://www.winvistatips.com/opos-so-linedisplay-createwindow-problem-t194728.html

 

The reason is a "misunderstanding" between the Class Wizard and the MSVC system headers. In the system headers the name CreateWindow and DestroyWindow are used as macro definitions and they are mapped to DestroyWindowA and CreateWindowA in the ANSI version. Microsoft uses this macro-replacing -mechanism to allow ANSI and UNICODE compiling. However, if you have C++ classes with a method using a "reserved" word the compiler will generate errors. In general: you should not use method names which are already used in the Window API. This is not a restriction of the language C++ but of the MSVC compiler.

 

Later on in the thread the author got around this problem by doing a #undef on the CreateWindow macro.

 

Problem solved!

 

In translation unit that #includes compiler generated header which

has

CreateWindow hassle (#included windows.h):

-#include windows.h

-#undef CreateWindow

-#include compiler generated header

 

 

 

Oh yeah, first post, and hello :)

Link to comment
Share on other sites

Right, but does that mean you can never have a class function called CreateWindow???

 

Unless you undefine the macro, like posted above. Since macros can be used anywhere, it's seeing that as a Macro. It doesn't know if you mean to use the macro or not. Given how macros work, how could it?

 

This is just 1 of the reasons macros are evil. It sucks that Win 32 API is loaded with them. It servers as a good warning to all library creators though.

Link to comment
Share on other sites

Here's what I did:

#pragma once

#include "../../../le3.h"
#include <windows.h>

#undef CreateWindow

namespace le3
{

class WindowsWindow;

class WindowsWindowDriver : public WindowDriver
{
	LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam );
	public:
	virtual WindowsWindow* CreateWindow(const int& width,const int& height);
};

}

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...