Mixed Mode C++ Problem

Q

quortex

Hey all,

I have been working on a project which consists of Native C++ code and
managed C# code. In order for the managed C# code to be able to access
the native layer I wrap some objects using Managed C++ Mixed Mode.

I also unit test the Native C++ code using Managed C++ using the VSTS
test tools.

Everything works fine apart from one niggly problem. With the mixed
mode libraries (Dlls) I have to put all of my implementation code into
the *header* otherwise I run into problems linking.

Then when I go to unit test using managed C++ if I use the normal
header and cpp combination everything compiles ok but when it links I
receive unresolved external token error messages.

I include the header files and add the managed references and include
the native static libraries that I am using so all should be well. I
have also tried the #using directive rather than adding references into
visual studio.

I cannot see what else I can do. If I inspect the outputted assembly
the types are definitely present so the linker shouldn't have a problem
binding to them.

So at the moment I still reference the managed c++ dll and include the
required headers as usual. But since I put all my implementation in the
headers the dll isn't really required - what I really want to do is put
my implementation code in the c++ files and then the linker should pick
the compiled managed c++ code from the assembly.

Does anyone have any ideas? This is really annoying. I can keep going
like this but it's not really ideal.

Hope that lot made sense!

Kind Regards,
Mark
 
Q

quortex

Actually just thought I cannot actually continue until I fix this. I
can unit test the code using managed c++ by including the header file
with full implementation. No problem and the tests pass.

Problem is I need to use this class from C#. So the code has to be
compiled into the assembly so I can add it as a reference to my C#
project.
 
Q

quortex

Final thing to add I have now given up. If I use the object viewer in
Visual Studio to look at the assembly (when compiled with c++ & .h) I
actually cannot see the namespace and class I am looking for.

However when I use Reflector everything is there.

I am making my Managed C++ class with:

ref class myClass{ blah }

That is all I need to do is it not?

Over to you lot, hope you know what I am doing wrong.

Mark
 
C

Carl Daniel [VC++ MVP]

quortex said:
Final thing to add I have now given up. If I use the object viewer in
Visual Studio to look at the assembly (when compiled with c++ & .h) I
actually cannot see the namespace and class I am looking for.

However when I use Reflector everything is there.

I am making my Managed C++ class with:

ref class myClass{ blah }

public ref class myClass { blah }

....so the class is visible outside the assembly...

-cd
 

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