Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Instanciate .NET Wrapper from native pointer

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
fhamel
467 Views, 2 Replies

Instanciate .NET Wrapper from native pointer

Context:

 

I've got a C++/CLI plugin which is used to create a new material plugin deriving from the Mtl class. The UI is built in C#.

 

Question:

 

How can I pass a Autodesk.Max.IMtl to my managed UI class from the native pointer?

 

I tried instanciating a Autodesk::Max::Wrappers::Mtl like so:

Autodesk::Max::Wrappers::Mtl^ mtlWrapper = gcnew Autodesk::Max::Wrappers::Mtl(static_cast<Mtl*>(this->pMaterial), false);

 

but I keep getting this compile error:

error C3767: 'Autodesk::Max::Wrappers::Mtl::Mtl': candidate function(s) not accessible

 

I tried making the Mtl class public in the same .cpp file

#pragma make_public(Mtl)

 

without success. Is there a way I can retrieve a managed object from a native pointer?

2 REPLIES 2
Message 2 of 3
kevinvandecar
in reply to: fhamel

I think you should instead create your material with a mixed-mode C++/CLI module. The SDK C++ side implementation can remain the same, but then you would create C++/CLI "wrappers" to access the portions you need from the managed UI. Then you can directly expose the material and access it in a managed way and have full control over it. Unless you specifically need the Autodesk.Max APIs, this would be the best way for you to control all the access. The Autodesk.Max API is not always very clean, so I do not think it will be easy for you to be able to cast it appropriately if the obvious methods you tried are not working.

Once you add C++/CLI/managed portion to your plugin, it will have to be loaded from the bin\asseblies folder. One other approach, if you want to keep you C++ plugin free of the managed wrappers, would be to create a seperate wrapper module, too. This is even more work to setup, and would require you to "export" the C++ Material functionality. Then a seperate mixed-mode assmbly could be made to provide the wrappers and effectively a "bridge" to you C++ plugin. This is actually how the Autodesk.Max assembly is working... simply wrapping the C++ SDK functionality for managed use.

Hope it helps,
Kevin


Kevin Vandecar
Developer Technical Services
Autodesk Developer Network



Message 3 of 3
fhamel
in reply to: kevinvandecar

That's basically what I did, I wrapped my custom Material in C++CLI and passed my wrapper to my managed UI. There is still one thing I would have liked to be able to get rid of, and it's the search for the managed wrapped IMtl corresponding to my native class as I would still like to be able to use the standard IMtl interface in my managed code without having to re-wrap it all.

 

That being said, your solution will do the job for now anyway,

 

thanks

 

 

 

 

 

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report