To enable interoperability between managed .NET code and native unmanaged C++ code, Microsoft created the C++/CLI language as a superset of native C++. The C++/CLI compiler is available in Visual Studio 2008, and is enabled by using the command-line option /clr. The C++/CLI Language Specification is published by ECMA International as Standard ECMA-372 and is available for download at the following link:
http://www.ecma-international.org/publications/standards/Ecma-372.htm.
Section 8. Language Overview (of ECMA specification) provides a useful introduction to the language. The remainder of the specification is useful as a reference.
Developers must use C++/CLI to make calls into the native 3ds Max SDK from a managed project. Developers can also use C++/CLI to wrap native types in managed objects and export these managed wrapper classes outside their assembly. Such exported types may be called from any .NET language: C#, C++/CLI, Visual Basic, etc.
The .NET Framework classes can be used from C++/CLI similarly to how they are used in C#. Developers familiar with native C++ and C# will find that their C# experience carries over easily to C++/CLI. Any good documentation on the .NET platform will be useful for C++/CLI work.
Creating a C++ / CLI plug-in to be loaded by 3ds Max
Currently, the 3ds Max plug-in loader can only load native DLLs as plug-ins. To create a C++/CLI plug-in, we follow the same procedure as for a native plug-in documented elsewhere in the SDK documentation. The major difference is that the CLR language extensions must be turned on in the project settings using the /clr option.
Additionally to refer to the .NET 3ds Max SDK components, a #using reference path must be configured in the project settings. These components are in the maxsdk\assemblies and maxsdk\x64\assemblies folders. The sample C++ / CLI project is set as:
- Resolve #using References: ..\..\assemblies - General - C / C++ Configuration Properties
The 3ds Max SDK installation includes a sample how-to plug-in demonstrating some of the fundamental issues involved in creating a .NET plug-in for 3ds Max. The plug-in project file and code is in howto\SceneExplorerExtension under your 3ds Max SDK installation folder. This sample plug-in is loaded as a General Utility plug-in through the native plug-in mechanism, then makes calls into managed code to add a new "Hit Points" property column to the Scene Explorer.
The code in dllmain.cpp, plus the SceneExplorerExtensionClassDesc and SceneExplorerExtensionGup classes use unmanaged code to fulfil the requirements for this module to be loaded as a General Utility plug-in. HitPointsProperty is a managed "ref" class. It derives from a managed class in the SceneExplorer assembly and interacts with both native and managed objects.