I wasn’t sure how to pass the userNode from python, but the following worked:
C++ side
MStatus SpaceHWDeformerNode::initialize()
{
MStatus stat = MS::kSuccess;
MFnNumericAttribute cpointerAttr;
mCPointerAttr = cpointerAttr.create("CPointer" ,"CPointer", MFnNumericData::kInt64, 0, &stat);
CHECK_MSTATUS(addAttribute(mCPointerAttr));
}
MStatus SpaceHWDeformerNode::compute(const MPlug& outputPlug, MDataBlock& dataBlock)
{
MStatus stat = MS::kSuccess;
MDataHandle handle = dataBlock.outputValue(mCPointerAttr, &stat);
handle.setInt64((long long)this);
}
void SpaceHWDeformerNode::hello()
{
Log.println("Hi from SpaceHWDeformerNode");
Log << mHarmonicConvex.mIsP2P << endl;
}
extern "C" __declspec(dllexport) void hello()
{
Log.println("Hello");
}
extern "C" __declspec(dllexport) void hello2(void *node)
{
Log.println("pointer %d", (int)node);
SpaceHWDeformerNode *hw = (SpaceHWDeformerNode *)node;
hw->hello();
}
Python side
import pymel.core as pm
import ctypes
# get shader
hw = pm.ls(type='SpaceHWDeformer', fl=1)
if len(hw) != 1:
print "There are %d SpaceHWDeformer nodes" % len(hw)
node = pm.PyNode(hw[0])
cpointer = node.getAttr('CPointer')
# load library
libh = ctypes.cdll.LoadLibrary('SpaceDeformation2D.mll')
lib = ctypes.WinDLL(None, handle=libh)
# run static function
libh.hello()
# run function with a plugin object as parameter
#dep = om.MFnDependencyNode(node.__apimobject__())
#cobj = dep.userNode()
libh.hello2(ctypes.c_void_p(cpointer))
# release library
del lib
ctypes.windll.kernel32.FreeLibrary(ctypes.c_int(libh._handle))