@Anonymous wrote:
Here is what I do and it works:
(for example)
BOOL BringUpPainterOptions()
{
ReferenceTarget *painterRef = (ReferenceTarget*)GetCOREInterface()->CreateInstance(REF_TARGET_CLASS_ID, PAINTERINTERFACE_CLASS_ID);
if (painterRef)
{
//set it to the correct verion
IPainterInterface_V5* pPainter = (IPainterInterface_V5*)painterRef->GetInterface(PAINTERINTERFACE_V5);
return pPainter->BringUpOptions();
}
return FALSE;
}
according to the documentation
class IPainterInterface_V5: public MaxHeapOperators
{
this interface doesn't derive from BaseInterface, so the casting to it doesn't make sense
Indeed there are two differents methods for GetInterface from IAnimatable, one returns an IBaseInterface, the other an object (same as "void *"). The last one needs an InterfaceID enumerator as parameter, but here is the list of enumerators given by 3dsMax :
public enum InterfaceID
{
Control = 4112,
Ikcontrol = 4128,
Ikchaincontrol = 4144,
Wirecontrol = 4160,
Scriptcontrol = 4176,
Master = 4192,
Easelist = 4208,
Multlist = 4224,
Baseobject = 4240,
Wsmobject = 4256,
Derivedobject = 4272,
Object = 4288,
Particleobj = 4304,
Lightobj = 4320,
Simpleparticleobj = 4336,
Keycontrol = 4352,
Keycontrol2 = 4368,
Setkeycontrol = 4384,
SystemXref = 4400,
Textobject = 4416,
Wavesound = 4432,
Newpartpod = 4464,
Newpartsource = 4480,
Newpartoperator = 4496,
Newparttest = 4512,
Meshselect = 4528,
Meshselectdata = 4544,
Maxscriptplugin = 4560,
Meshdeltauser = 4576,
Meshdeltauserdata = 4592,
Splineselect = 4608,
Splineselectdata = 4624,
Splineops = 4640,
Patchselect = 4656,
Patchselectdata = 4672,
Patchops = 4688,
Submap = 4704,
Mitranslator = 4720,
Mentalray = 4736,
Newmtlinterface = 4752,
Component = 4768,
Refarray = 4784,
Linktmctrl = 4800,
Subtargetctrl = 4816,
Reagent = 4832,
Geomimp = 4848,
Aggregation = 4864,
Valence = 4880,
Guest = 4896,
Host = 4912,
Sceneobject = 4928,
Multitangent = 4944,
Softselect = 4960,
Unreplaceablectl = 4976,
Eulerctrl = 4992,
Locked = 5008,
LockedClient = 5024,
ObjectsuperclassNotObjectclass = 5040,
Compositesubmtlapi = 5056,
Mtlidset = 5072,
Userinterface = 65535
}
In C++ we use PAINTERINTERFACE_V5 (0x78ffe181), so i also tried to cast this unsigned integer as InterfaceID...
The object returned is an NativeObject instance (from unmanaged memory) and it can't be cast directly too, so i used Marshal module to get the interface from the native object.
IReferenceTarget painterRef = (IReferenceTarget)Ip.CreateInstance(PAINTERINTERFACE_SUPERCLASS_ID, PAINTERINTERFACE_CLASS_ID);
if (painterRef != null)
{
InterfaceID PainterInterfaceID = (InterfaceID)PAINTERINTERFACE_V5;
Autodesk.Max.Wrappers.NativeObject obj = painterRef.GetInterface(PainterInterfaceID) as Autodesk.Max.Wrappers.NativeObject;
IIPainterInterface_V5 pi = Global.IPainterInterface_V5.Marshal(obj.NativePointer);
return pi;
}
It seems to work this way,
thank you !