Sign in to follow this  
The_Grand_User

[.net] Managed C++/CLR DLLs sharing native C++ structs

Recommended Posts

The_Grand_User    139
Hello, I'm wondering if it's possible for two C++/CLR Dlls to share/pass native structs (like a D3DXVECTOR3). I've got something similar to the fllowing (where the second DLL has the first as a refernce):
// DLL1.h/cpp
namespace DLL1
{
  public class class1
  {
     public: static float Foo(D3DXVECTOR3 vec) { ... }
  } 
}

// DLL2.h/cpp
namespace DLL2
{
  public class class2
  {
     public: void Bar()
     {
        D3DXVECTOR3 avec = ...
        ...
        float result = DLL1::class1::Foo(avec);
        ...
     }
  } 
}

However, I'm getting a "error C3767: 'DLL1::class1::Foo': candidate function(s) not accessible" So is it just not possible to do this or am I missing something? And if it's not possible, what's the recomended way around it? Thanks.

Share this post


Link to post
Share on other sites
jpetrie    13103
By default, native types do not have public accessibility any longer. This means that while your function Foo is public, it depends on an internal type D3DXVECTOR3 and is thus not accessible.

You can use the make_public pragma to force the D3DXVECTOR3 type to be public, or you can have the assemblies in question friend eachother via the InternalsVisibleTo attribute. Neither of these are terribly elegant, unfortunately.

A better option might be to wrap the native structure in question so that it is more cleanly exposed beyond your assembly.

(Also, it's C++/CLI, technically, not C++/CLR.)

Share this post


Link to post
Share on other sites
The_Grand_User    139
Thanks, it's working nicely now :)

I'm going to try to avoid wrapping the stucts for now, until I can check the performance differences at least.

(@C++/Cli ... I knew that, just thinking of other things I guess)

Again, thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this