Development for Microsoft Windows

Development Environment

Visual Studio is the only supported IDE and compiler for producing Cinema 4D plugins for Windows. See Development Environments for an overview of supported Visual Studio Versions for different versions of Cinema 4D.

The SDK includes Natvis files for several data types. The files are:

  • frameworks\core.framework\project\typeviewer\msvc\maxon.natvis
  • frameworks\cinema.framework\project\typeviewer\msvc\c4dapi.natvis

The files can simply be copied to the local "Documents\\Visual Studio 2019\\Visualizers" folder.

Alternatively, it is possible to include the Natvis files in a solution using AdditionalSolutionFiles:

// Configuration of a custom solution in the projectdefinition.txt file
// support Windows and macOS
Platform=Win64;OSX
// this is a solution
Type=Solution
// included plugin projects
Solution=\
plugins/pluginA;\
plugins/pluginB
// include natvis files in Visual Studio solution file
AdditionalSolutionFiles=\
..\..\frameworks\core.framework\project\typeviewer\msvc\maxon.natvis;\
..\..\frameworks\cinema.framework\project\typeviewer\msvc\c4dapi.natvis
OSX
OS X.
Definition: ge_prepass.h:1

Best Practice

Windows Specific Code

Windows specific code can be guarded with the macro MAXON_TARGET_WINDOWS:

#ifdef MAXON_TARGET_WINDOWS
#endif

Windows Includes

If a source code file includes Windows header files it must also include undef_win_macros.h to un-define certain macros.

#ifdef MAXON_TARGET_WINDOWS
#include <wtypes.h>
#endif
Note
An addtional #undef COMPONENT may be needed, depending on the Windows header files involved. This will be added to the undef_win_macros.h header in a later release.

Running Plugins

It is possible to start Cinema 4D from Visual Studio to run and debug a plugin:

  • Mark one plugin project in the solution as "Startup Project".
  • In this project's properties set "Debugging" -> "Command" to the location of a compatible Cinema 4D executable.

The Cinema 4D executable must find the compiled plugins. The plugin location can be set with the g_additionalModulePath command line argument. One can also use "$(ProjectDir)..\.." instead of the absolute path.

Additional command line arguments can be set (e.g. to run unit tests). See Unit Tests Manual and Configuration Variables.

Debugging

The Output console displays messages printed with DiagnosticOutput(). See Debug and Output Functions.

For general information on debugging see Debugging.

Automating Processes

The execution of the Project Tool can easily be automated using Windows batch files.

This batch file executes the Project Tool on the given location of the SDK and starts Visual Studio to open the solution file:

REM Build SDK
CD /D C:\development\project_tool
kernel_app_64bit.exe g_updateproject=C:/development/sdk_extracted
CD /D C:\programs\vs17\Common7\IDE
devenv.exe C:\development\sdk_extracted\plugins\project\plugins.sln
D
Quality D.
Definition: macros.h:4
C
Quality C.
Definition: macros.h:3

This batch file starts Cinema 4D with the location of the plugins:

REM run C4D
CD /D C:\programs\cinema_4d
"CINEMA 4D.exe" g_additionalModulePath=C:\development\sdk_extracted\plugins
C4D
Definition: lib_net.h:1

Additionally one can set the command line argument g_runUnitTests to automatically execute custom unit tests.

Cinema 4D can be informed on the type of license model to use - which can be helpful in certain automated tasks - by using:

  • g_licenseServerRLM="[servername]:[port]" to specify the RLM license server, or
  • g_licenseServerURL="[http(s)://[ip address]:[port]" to specify the Maxon license server, or
  • g_licenseUsername and g_licensePassword to specify the authentication credentials on https://id.maxon.net.

DLLs

DLLs needed by a plugin can be placed in myplugin\res\libs\win64.

Deployment

The final plugin build for deployment should be created using the "Release" build target.

Note
Make sure your plugin includes all needed dependecies including Microsoft Visual C++ redistributables. Redistributables installed with Cinema 4D change with every release.

Further Reading