Quote: "yeah, I know that, but you can't use DBP code in those DLLs. I want to use DBP CODE IN MY DLLS!!"
I have to step in here. Although this is not the correct thread to go into great detail on this matter, I can assure you that any function can be called from Visual Studio in your C/C++ applications without too much trouble.
First of all, in order to know which function(s) you are going to use, you must obtain their mangled names, either by using a Resource DLL hacker, or by using the DUMPBIN tool that comes with Visual Studio to produce an export list for the relavent DBPro DLLs.
Now your next task is to determine what the function arguments and return type is. Again, using a tool accompanied with Visual Studio, is called UNDNAME.EXE using the -f option. Passing in the mangled name of the function, this will tell you exactly how the function prototype has been declared in the DBP DLL.
Right, you now have the name(s) of the function(s) and the argument types. Now in your C/C++ source code, you need to declare a function pointer, based on the argument arrangement of the function. For this example, we'll use MAKE OBJECT CUBE. Now using
DUMPBIN /EXPORTS DBProBasic3DDebug.dll, we determine that the mangled name for this function, is '?MakeCube@@YAXHM@Z'.
Now using
UNDNAME -f ?MakeCube@@YAXHM@Z gives us
void __cdecl MakeCube(int,float)
So, we now declare our function pointer type to be used to hold the address of our function:
typedef void (*FN_MAKEOBJECTCUBE)( int, float );
This declares a new function pointer type that we can later use to assign an address, in this case, the address of the DLL function in DBProBasic3DDebug.dll. With respect to other functions that you wish to call, you would declare separate typedefs with their own unique name for each of the functions you plan to use in your code.
Now in our main code, i.e. your DLL function that's called from DBPro application, you would declare a variable of type FN_MAKEOBJECTCUBE:
int CalledFromDBProSource( void )
{
HINSTANCE hdll;
FN_MAKEOBJECTCUBE pfnFunc;
// First load into memory, the DBPro 3D DLL
hdll = LoadLibrary( "DBProBasic3DDebug.dll" );
if( !hdll ) return 0; // Error
pfnFunc = (FN_MAKEOBJECTCUBE)GetProcAddress( hdll, "?MakeCube@@YAXHM@Z" );
if( !pfnFunc ) return 0; // Error
// Now call the Make Object cube function
(*pfnFunc)( 1, 1000 );
return 1;
}
Now technically, you would have this function inside a DLL that is used as a TCP for DBPro. You would need to correctly define the string table in order to allow your above function to be called from your DBPro source code. This is just a basic example of how it is done.
Lastly, and this is the most important rule. If you plan to use a DLL such as the DBProBasic3DDebug.dll from your C/C++ plugin/dll or whatever, it has to be compiled into your DBPro EXE. This is normally done for you if your DBPro program uses any of the functions exported from these DLLs.
I normally force inclusion of such DLLs by placing these lines of code at the end of your main DBPro application's main.dba file.
They don't actually get called, but it forces the DBP compiler to include those DLLs that your plugin will eventually use to call functions directly. If you fail to include the DBP main DLLs that your plugin will call, you will experience memory exception errors.
End
Remstart
We force inclusion of a DBPro library by using a command from that library.
Just comment out the ones that you don't want from this list to reduce the size
of your executable.
Remend
load object "",1 : ` Basic3D
delete memblock 1 : ` Memblock
load bitmap "",1 : ` Bitmap
cls : ` Core
autocam off : ` Camera
hide mouse : ` Input
load image "",1 : ` Image
delete light 1 : ` Light
disable systemkeys : ` System
text 0,0,"" : ` Text
close file 1 : ` File
delete animation 1 : ` Animation
dot 0,0 : ` Basic2D
load bitmap "",1 : ` Bitmap
ftp connect "","","" : ` FTP
delete terrain 1 : ` LODTerrain
delete matrix 1 : ` Matrix
free net game : ` Multiplayer
delete music 1 : ` Music
delete particles 1 : ` Particle
show window : ` Setup
delete sound 1 : ` Sound
sprite 1,0,0,1 : ` Sprite
normalize vector2 1,1 : ` Vector
delete bsp : ` World3D
There are other useful things I know. Including how to get DBPro to call your ReceiveCoreDataPtr function if it has been compiled under the GNU GCC compiler, such as Dev-C++ or MinGW. But this is a long long story, for another time.
Paul.
Home of the Cartography Shop - DarkBASIC Professional map importer