Rhino SDK and P/Invoke

Using functions defined in rhinoSdkUtilities.h works great when building a Rhino C++ plugin rhp.
However, when trying to place common functionality between Grasshopper and Rhino into a dll that the gha assembly can P/Invoke into, and the rhp can dynamically link with, so that both the gha and the rhp can call that common functionality, one compiles the plugin to a different dll. In that case, it seems very hard to include that header. I am not trying to call into extra functionality outside of Rhino. I am just trying to call that dll from Grasshopper. Just including rhinoSdkUtilities.h or other sdk headers and linking with opennurbs.lib/dll in the SDK folder results in tons of errors, even though it is the plus build of opennurbs.dll. From the file rhinoSdk.h :

#if !defined(RHINO_SDK_CLASS)

// When the core Rhino executable is being compiled, RHINO_SDK_CLASS
// is defined in Rhino's stdafx.h as __declspec(dllexport).  
// If RHINO_SDK_CLASS is not defined, then it means a Rhino plug-in
// is being compiled.

which implies that if RHINO_PLUGIN_COMPILE is not to be defined, RHINO_SDK_CLASS is expected to be defined, which seems to be a preprocessor variable that plugin developers are not supposed to define, and even if one just defines it as __declspec(dllexport) rhinoSdk.h still won’t include.
To make it short: It seems very difficult to use rhinoSdkUtilitites.h and/or rhinoSdk.h unless one is compiling the plugin itself. I tried to place all common functionality into the rhp but that led to a bunch of other problems, by requiring Grasshopper to load the Rhino plugin first. I might, of course, be missing something, in which case it’d be great to learn what.

Hi @mathias.fuchs,

Most of the utility functions available in rhinoSdkUtilities.h are exposed to RhinoCommon. Thus, no need to p/invoke.

If you want to call Rhino SDK functions from a DLL, best to create a Rhino-dependent DLL.

My Moose project demonstrates this.

– Dale

I see, thanks for letting me know. That means RHINO_PLUGIN_COMPILE is just going to be defined, even though one isn’t. Still curious about how the SDK functions get actually linked, but I understand it just works.