native/managed

D

dragonslayer008

I recently added some new code files to a C++/CLI project. The added
code is all native. I simply added the code to the project and built
it. It compiled fine but I am getting the linker error:

LNK2022: metadata operation failed (8013118D) : Inconsistent layout
information in duplicated types (IDirect3DDevice9): (0x0200015b)

I get this in three .obj files. Each file has a different class, but
each class holds a member to an IDirect3DDevice9 pointer. But I'm not
sure why this throws a LNK2022 error, which seems to have to do with
defining classes of the same name.
 
D

dragonslayer008

I seem to have found the situation that may be causing these.

As said, the native classes have IDirect3DDevice9* data members. A
managed ref class also has an IDirect3DDevice9* data member. It seems
the compiler does not like this, because if I remove the
IDirect3DDevice9* data member from the managed class, the linker
errors go away. On the other hand, this worked fine before I added
the native classes. So can you not have instances of the same type in
a managed class and native class?
 
D

dragonslayer008

Okay, I got it to work (it compiles and links) if I comment out
#include <d3dx9.h> at the top of the .h file that houses the managed
class

//#include <d3dx9.h> // works now
#include "Box.h" // Box.h #includes <d3dx9.h> too
#include <fstream>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

.... managed class definition

Can anyone explain this?
 
B

Ben Voigt [C++ MVP]

Okay, I got it to work (it compiles and links) if I comment out
#include <d3dx9.h> at the top of the .h file that houses the managed
class

//#include <d3dx9.h> // works now
#include "Box.h" // Box.h #includes <d3dx9.h> too
#include <fstream>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

... managed class definition

Can anyone explain this?

Apparently "Box.h" is making some #define changes that affect the windows
header files. That's why the compiler complained, because the #define
values used for IDirect3DWhatever were different in different source files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top