[vtkusers] VTK-Win32 problem only : including vtk includes windows.h
REGAT-BARREL Aurélien
arbvtk at yahoo.fr
Tue May 11 12:44:58 EDT 2004
While VTK could probably hack its way around these problems, very quickly we would run into users code that does
#include <windows.h>
#include <vtkFoo.h>
But it is what we actually have.
By including <vtkFoo.h>, <windows.h> is also included.
The difference is by explicitly including <windows.h> you know that it is included, and you may know this macros definitions problem since you may have Win32 programming knowledge (by including <windows.h>)
So you just have to swap the 2 lines to resolve the problem.
Using vtk makes you to include <windows.h>, without knowing that.
This shocks me since that's the cause of my problem today (the code works under Linux, and not under Windows only for this reason).
IMO, this is also a big abstraction problem. VTK should use Windows.h, opengl or something else without letting us to know it, and especially without any impact on our code. When I include <stdio.h>, I do not include <windows.h> however fopen uses CreateFile.
The best solution is to avoid using any names that are #defined by common libraries such as X and windows. (which is why we have ColorWindow and ColorLevel instead of Window/Level in many classes) unfortunately we caught onto this too late and are stuck with it.
It is impossible to avoid using that names, since you must know very well the entire Win32 & X apis.
In my case, the guy who wrote the code choose its class names without wondering about Win32 from Linux.
I think this is how it should be. Moreover it is a name that all VTK classes use.
How can we say not to do something that we are doing.
For example, this code should behave the same under Linux & Windows:
#include <vtkObjectBase.h>
#include <stdio.h>
class MyEmptyObject : public vtkObjectBase
{
public:
virtual const char * GetClassName()
{
return "MyEmptyObject";
}
};
int main()
{
vtkObjectBase * o = new MyEmptyObject;
printf( "%s\n", o->GetClassName() );
}
But under Windows I get "vtkObjectBase", and because <windows.h> is included in <vtkObjectBase.h> before declaring vtkObjectBase::GetClassName, I don't know how to solve it.
How to make the above code to work under Win32 ?
As Ive done more windows development Ive found that life is generally much easier if you bite the bullet and include windows.h. Not just because of this issue but there are other issues you can bump into as well.
Does it solve more problems than it creates new ones ?
Aurélien REGAT-BARREL
---------------------------------
Yahoo! Mail : votre e-mail personnel et gratuit qui vous suit partout !
Créez votre Yahoo! Mail
Dialoguez en direct avec vos amis grâce à Yahoo! Messenger !
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040511/b3448aee/attachment.htm>
More information about the vtkusers
mailing list