More mixed class library questions

A

ajtaylor

I have a large amount of C++ unmanaged code that I am attempting to use
in a managed project.

Amongst this code is a large number of classes and structs that I would
like to be able to use in several projects in the solution.

(my logic is that I am making my solution a more component based
approach and using managed code where its best and keeping the
unmanaged code at the back end)

I tried to create a class library project that contains all these
common structs/classes and that works fine.

When I include it in another project using #using I cant see any of
these structs/classes - I am assuming that is because this code is
unamanged C++.

So do I simply have to share the relevant .h/.cpp files amongst the
projects or is there a way or using these types in an assembly and
using that?

I apologise if this is a silly question but there is a definite lack of
documentation out there on C++/CLI IMHO.
 
B

Bruno van Dooren [MVP VC++]

I tried to create a class library project that contains all these
common structs/classes and that works fine.

When I include it in another project using #using I cant see any of
these structs/classes - I am assuming that is because this code is
unamanged C++.

Yes, they don't show up with the #using directive.
So do I simply have to share the relevant .h/.cpp files amongst the
projects or is there a way or using these types in an assembly and
using that?

Only the .h files. Be sure to separate managed and unmanaged stuff in
different .h files, because
otherwise you can get problems when managed stuff is seen by the compiler in
both the .h file and in the assembly that you are #using

You also have to use __declspec(dllexport) on the unmanaged classes /
structs that you want to export.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

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