Quote: "No. Read the code in the link again - there's an array named Dependencies and two functions called GetNumDependencies and GetDependencyID that do that."
Ah, yes, that was a pretty dumb mistake on my part, I thought there was a shortcut to loading the libraries using Core->g_Bitmap (I realised it didn't work just after I posted). Just out of curiosity, how do you access a DBPro main plugin without using LoadLibrary? I can't quite understand your comment in the exmaple:
// NOTE, this particular library is also available via Core->g_Basic3D
// If you use that instead, then you don't need to unload the DLL later.
// However, since this is a general example that you can use to load any
// DLL, I'll stick with LoadLibrary.
Thanks for the link, it explained everything brilliantly - it was maddeningly simple once I figured it out, but I'd never have worked it out on my own. I have just one final query, connected with how I grant multiple .cpp files access to the DBP commands. Currently, I use the following for my project:
DarkGUI.h (header for main project file)
#ifndef DARKGUIH
#define DARKGUIH
typedef void (__cdecl *MakeBitmap_t) (int, int, int);
extern MakeBitmap_t MakeBitmap;
typedef int (__cdecl *BitmapExist_t) (int);
extern BitmapExist_t BitmapExist;
#endif
DarkGUI.cpp (Main source file)
// DarkGUI.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "globstruct.h"
#include "DarkGUI.h"
#include "Form.h"
#define EXPORT __declspec(dllexport)
// =====================
// DarkGUI Required DLLs
// =====================
GlobStruct* Core = 0;
// Requires five bitmap modules
HMODULE Bitmap = 0;
// ==========================
// Access DBP commands in C++
// ==========================
// DBP Command names from function pointers
MakeBitmap_t MakeBitmap = 0;
BitmapExist_t BitmapExist = 0;
const char* Dependencies[] =
{
"DBProBitmapDebug.dll",
};
EXPORT int GetNumDependencies( void )
{ return sizeof(Dependencies) / sizeof(const char*); }
EXPORT char const* GetDependencyID(int ID)
{ return Dependencies[ID]; }
// Acquire Core Data pointer, initialise external DLLs
EXPORT void ReceiveCoreDataPtr(LPVOID CorePtr)
{
Core = (GlobStruct*)CorePtr;
// Load required DLLs
Bitmap = LoadLibrary( Dependencies[0] );
// Populate function pointers for these DLL's
MakeBitmap = (MakeBitmap_t) GetProcAddress(Bitmap, "?CreateBitmap@@YAXHHH@Z");
BitmapExist = (BitmapExist_t)GetProcAddress(Bitmap, "?BitmapExist@@YAHH@Z");
}
// =====================
// DarkGUI Core Commands
// =====================
EXPORT void Start(int bmp)
{
MakeBitmap(bmp, 1024, 768);
}
Form.h (header for second file that uses DBP commands)
#ifndef FORMH
#define FORMH
#include <vector>
struct FormStruct
{
int iFormID ;
int iFormType ;
int iX ;
int iY ;
int iWidth ;
int iHeight ;
int iTitlebarHeight ;
int iMinWidthVis ;
int iMinHeightVis ;
int iNormalImage ;
int iDisabledImage ;
int iFirstCompIndex ;
int iNumberOfComponents ;
bool bVisible ;
bool bEnabled ;
bool bTransparent ;
};
// This struct is a vector, accessible in DarkGUI.cpp
extern std::vector <FormStruct> Form;
#endif
Form.cpp
#include "stdafx.h"
#include "DarkGUI.h"
#include "Form.h"
#include <vector>
#define EXPORT __declspec(dllexport)
std::vector <FormStruct> Form;
// Create and insert a new Form into the Form Vector
EXPORT void FormTest(int FormID)
{
MakeBitmap(5, 1024, 768);
}
The code compiles without any error and I'm fairly certain this is the correct method of sharing the function pointers, but I was just wondering if I was right in this approach, or is there a better way? Am I also correct in thinking that "void ReceiveCoreDataPtr(LPVOID CorePtr)" is called before any other DLL command can be accessed, so there is no possibility of the function pointers being null/undefined?
We spend our lives chasing dreams. Dark Basic lets us catch some of them.