Apparently there are three custom functions you can implement and export from your dll that will be called automatically by DBPro;
// Function pointer prototype; this will be used to call the MAKE OBJECT CUBE function.
typedef void (__cdecl *fpMakeObjectCube)(int iID, float fSize);
// This is a global function pointer of the type we just declared. We will use it just as
// dbMakeObjectCube() from DarkGDK.
fpMakeObjectCube dbMakeObjectCube = NULL;
__declspec ( dllexport ) void Constructor() {
// This is called when your dll is loaded. Use it to allocate dynamic memory
// or any other kind of setup your plugin requires.
}
__declspec ( dllexport ) void Destructor() {
// As you would've guessed, this is called just before unloading your plugin.
// Free dynamic memory and otherwise release resources / clean up after your dll.
}
__declspec ( dllexport ) void ReceiveCoreDataPtr ( void *pCore ) {
// This is the function I was talking about; the pCore parameter is a pointer to
// an instance of the GlobStruct struct (include "globstruct.h" from DarkGDK / DarkSDK
// to use it). You have to cast it from void to a pointer to the struct like so:
GlobStruct *pGlob = (GlobStruct*)pCore;
// You should obviously have a global variable pGlob instead so you can access it from elsewhere
// in your plugin.
// The GlobStruct contains HINSTANCE's of the dlls loaded by DBPro (as well as flags denoting
// whether they have indeed been loaded or not).
// You can define a function pointer prototype that matches the desired function and then
// use GetProcAddress to convert a pointer to the dll function to your own prototype for later
// access.
// As you saw, we set up a function pointer matching the dbMakeObjectCube function at the top
// of this snippet. Now that we have access to the GlobStruct, we can use it to access this
// function from the dll, provided said dll has been loaded by the DBPro runtime.
if(pGlob->g_Basic3Dmade)
dbMakeObjectCube = (fpMakeObjectCube)GetProcAddress(pGlob->g_Basic3D, "?MakeCube@@YAXHM@Z");
// If the Basic3D dll had indeed been loaded, dbMakeObjectCube now points to the function with
// the mangled name "?MakeCube@@YAXHM@Z" in DBProBasic3DDebug.dll.
// You can find these names by opening the dll files in notepad and browsing around, searching
// for appropriate strings. You can also use more advanced dll inspecting software.
}
// Custom function for your plugin that creates a unit cube for the given object ID.
__declspec ( dllexport ) void MakeUnitCube ( int iID ) {
// The ReceiveDataPtr is called at dll initialization, so it has already been run before the first
// possible call here.
// dbMakeObjectCube is thus setup and will be pointing to the appropriate function in the core DBP
// dll, alternatively it will be NULL if that dll wasn't loaded at runtime, due to no function from
// it being used in the compiled DBPro program.
if(dbMakeObjectCube)
dbMakeObjectCube(iID, 1.0f);
else
// Display error message here if wanted
}
I just wrote that code up so it isn't tested, but that should be the gist of it.
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)