OPOS SO LineDisplay CreateWindow problem

Jun 04, 2008 7 Replies

Hi,



How can I solve this problem: MS VisualStudio C++ thinks that CreateWindow is a macro and tries to expand it.



It seems that this is a well-known problem, however I have not found any applicable solution.


-Esko


Correct, this is a macro defined to CreateWindowA or CreateWindowW

Why is this bad?

This clip from

formatting link
it better than I can: CLIP1 -->

Remark 2: For the OPOS line display class, it is necessary to rename the methods: DestroyWindow -> xDestroyWindow CreateWindow -> xCreateWindow in the wrapper class (*.h and *.cpp file). Also, the access to these methods in the application should be done with these names. Otherwise the C++ - compiler will generate many syntax errors like "Create Window: illegal number of arguments in CreateWindowA" 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. CLIP1 virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CreateWindow( LONG LViewportRow, LONG LViewportColumn, LONG LViewportHeight, LONG LViewportWidth, LONG LWindowHeight, LONG LWindowWidth) = 0; CLIP2

Do you work with MSVC++ 6.0 or a major release of VC? and also.. why you don't create a class for your driver? This can help the compiler to solve correctly the resolution of names... from local scope to global scope...

cod

Microsoft Visual Studio 2005 Professional Edition - ENU Service Pack 1

It is already a class (I think, I am not comfortably accustomed to COM objects), here is how CreateWindow is implemented in my LineDisplay01.cpp:

CLIP LineDisplay01.cpp -->

STDMETHODIMP CLineDisplay01::CreateWindow0(LONG LViewportRow, LONG LViewportColumn, LONG LViewportHeight, LONG LViewportWidth, LONG LWindowHeight, LONG LWindowWidth) { // TODO: Add your implementation code here

// return S_OK; return OPOS_E_ILLEGAL; } CLIP LineDisplay01.cpp STDMETHOD(CreateWindow0)(LONG LViewportRow, LONG LViewportColumn, LONG LViewportHeight, LONG LViewportWidth, LONG LWindowHeight, LONG LWindowWidth); CLIP LineDisplay01.h

Sorry, namespacing is not applicable, interface must adhere to OPOS standards.

-Esko

Problem solved!

Solution: In translation unit that #includes compiler generated header which has CreateWindow hassle:

-#include windows.h

-#undef CreateWindow

-#include compiler generated header The compiler generated header file that #included windows.h

br Esko

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required