tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

"tinyxml2.h" and windows.h

Open BugIsComing opened this issue 9 years ago • 9 comments

Hello Leethomason. when i use the tinyxml2, a error happens if i add the "tinyxml2.h" and windows.h in a cpp.Could you tell me why it happens please?

BugIsComing avatar May 08 '15 09:05 BugIsComing

I guess more details of which error happens would be useful.

Dmitry-Me avatar May 08 '15 14:05 Dmitry-Me

The error is "XMLDocument is redefinition". I check the error, find that there is a definition of "class XMLDocument" in msxml.h. The requirement is that i must add "tinyxml2.h" and windows.h in a same cpp,how can i deal with it?thank you!

BugIsComing avatar May 10 '15 14:05 BugIsComing

Do you have using namespace tinyxml in your code?

Dmitry-Me avatar May 16 '15 17:05 Dmitry-Me

yes, i do.

BugIsComing avatar May 17 '15 07:05 BugIsComing

Then you should not

kleuter avatar May 17 '15 07:05 kleuter

ok,i'll think some other solutions.

BugIsComing avatar May 18 '15 03:05 BugIsComing

IMO the obvious solution is to drop using namespace tinyxml.

Dmitry-Me avatar May 18 '15 06:05 Dmitry-Me

Just so others will know, does it work if you drop the using namespace tinyxml2. It should....but it would be good to confirm there isn't something more sinister going on.

leethomason avatar May 18 '15 23:05 leethomason

It's old issue, but I think it can be helpful.

It works:

#include "tinyxml2.h"
#include <Windows.h>
using namespace tinyxml2;

It does not work;

#include "tinyxml2.h"
using namespace tinyxml2;
#include <Windows.h>

In my case, these also work:

#include "tinyxml2.h"

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

using namespace tinyxml2;
#include <Windows.h>
#include "tinyxml2.h"

#ifndef __MSXML_LIBRARY_DEFINED__
#define __MSXML_LIBRARY_DEFINED__
#endif

using namespace tinyxml2;
#include <Windows.h>

But this can be a problem when the project also use msxml.

junmocklee avatar May 29 '17 02:05 junmocklee