Josh Posted August 31, 2010 Share Posted August 31, 2010 #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 givenc:\program files (x86)\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/../../../../include/winuser.h:4328: error: 'CreateWindowA' declared as a 'virtual' field Quote 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 More sharing options...
Rick Posted August 31, 2010 Share Posted August 31, 2010 In C, CreateWindow is a macro that calls CreateWindowA (or CreateWindowW). CreateWindowA is a macro that calls the CreateWindowExA WinAPI function. Quote Link to comment Share on other sites More sharing options...
Josh Posted August 31, 2010 Author Share Posted August 31, 2010 Right, but does that mean you can never have a class function called CreateWindow??? Quote 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 More sharing options...
Azazel226 Posted August 31, 2010 Share Posted August 31, 2010 Right, but does that mean you can never have a class function called CreateWindow??? 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 Quote Link to comment Share on other sites More sharing options...
Rick Posted August 31, 2010 Share Posted August 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
Josh Posted August 31, 2010 Author Share Posted August 31, 2010 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); }; } Quote 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 More sharing options...
Recommended Posts
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.