THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/12/2012 at 09:43, xxxxxxxx wrote:
Now, InitValues() for a GeDialog is different than the Init() in plugins (which is declared in the NodeData class so that it exists for a good portion of plugin types). InitValues() is for configuring the values of the GUI elements of the GeDialog. It is called every time the dialog is opened.
Depending on the plugin, you may actually want to initialize the hardware in PluginStart() in main.cpp - if you only need to initialize it once. If you need to be able to do it whenever the user 'connects' it, then you will need something that polls for it. In the former case, you can get a pointer to your plugin data from the RegisterMyPlugin() method and call your own method to do the initialization.
// + Main.cpp
MyPlugin* RegisterMyPlugin();
static MyPlugin* mp = NULL;
//*---------------------------------------------------------------------------*
Bool PluginStart()
//*---------------------------------------------------------------------------*
{
// register hooks and return
mp = RegisterMyPlugin();
if (!mp) return FALSE;
return mp->InitHardware();
}
// - Main.cpp
// + MyPlugin.cpp
// Initialize Hardware
// Note: must be declared public: to be called from other places
//*---------------------------------------------------------------------------*
Bool MyPlugin::InitHardware()
//*---------------------------------------------------------------------------*
{
// Do your hardware initilization
// ...
return TRUE; // on success
return FALSE; // on failure
}
// Global Registrant Method for MyPlugin
//*---------------------------------------------------------------------------*
MyPlugin* RegisterMyPlugin()
//*---------------------------------------------------------------------------*
{
// Allocate an instance here
// - this is only good for single instance plugins like a CommandData
MyPlugin* mp = gNew MyPlugin();
if (!mp) return NULL;
// Call the C4D Plugin Registration method
if (RegisterCommandDataPlugin(blah, blah, ..., blah, mp)) return mp;
return NULL;
}
// - MyPlugin.cpp
Even if you are using another type of plugin, it may be wise to create a dummy CommandData plugin just to do the hardware initialization. You can always have it do nothing when selected from the Plugins menu - but registration and hardware initialization will always occur during startup of Cinema 4D.