Jump to content

LE Commands from .dll


Gandi
 Share

Recommended Posts

Hi!

 

Is it possible to use LE-commands from a selfmade .dll file?

I tried is today, but always got errors, as the dll seems to load in its own thread.

 

Or is there any other way of doing it? i want to use this dll in some of my projects and maybe share it with the community, but i dont want to recompile/include/share the whole source code..

Link to comment
Share on other sites

Yes, it's possible using the LoadFuncs() function of the C headers in your dll header (not in your dll, your dll uses the normal Initialize()/Terminate() and also a function to return le_hlib to your program). Make a similar function like Initialize() in your dll header, but instead of loading the engine.dll, only pass the le_hlib handle from your dll to it. You can make your own dll, which loads the engine.dll and then both your dll and a game has access to the LE functions. The game only needs to load your dll, not the engine.dll, but of course both your dll and the engine.dll is needed to run the game.

 

Your dll should look like this:

// gemini.cpp : Defines the exported functions for the DLL application.
//

#include "engine.h"
#include <string>
using namespace std;
#pragma warning(disable:4996)
#define DLLEXPORT(s) __declspec(dllexport) ##s _stdcall 

extern "C"
{
DLLEXPORT(int) GeminiLEInitialize(void)
{
	return Initialize();
};

DLLEXPORT(HMODULE) GetLEHandle(void)
{
	return le_hlib;
};

DLLEXPORT(int) GeminiLETerminate(void)
{
	return Terminate();
};

// Your own other functions here, which can also use LE commands.
// You don't need to wrap any other LE functions as they can be loaded
// using the LoadFuncs() macro in your dll header, so that they become accessible
// to the game source.

};

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

let's see if i got it right :D

 

1) i have to load the LE functions in my dll (the Initialize() function of engine.h, if im right)

2) i have to link the LE functions from my own dll to the main programm ( so i link to my dll which links to the LE dll???) (writing my own engine.cpp, right?)

 

I'm sry, but i just haven't done a lot with dll's and linking so far ..

Link to comment
Share on other sites

1) Yes

2) No, you don't have to care about the LE functions in your dll, but only in your dll header. You only write your own additional functions in your dll, and let your dll header use LoadFuncs() in your OwnInitialize() function, so the game can see both your own dll functions and LE functions. There is no overlapping, wrapping or duplicate functions needed.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

ok.. thats what i got now:

 

#define DLLEXPORT(s) __declspec(dllexport) ##s _stdcall 

extern "C"
{
	DLLEXPORT(int) initializeGui(int debug)
       {
               return Initialize(debug);
       };

       DLLEXPORT(HMODULE) getLEHandle(void)
       {
               return le_hlib;
       };

	DLLEXPORT(int) terminateGui(void)
       {
               return Terminate();
       };

};

in my .dll header

 

and then i copied the engine.cpp renamed it and included it into my project instead of the engine.cpp

 

here are the changes i made in the "engine.cpp"

 

i added:

typedef	int		(__stdcall *TGuiInitialize)			(int);
typedef	HMODULE	(__stdcall *TGuiGetHandle)			(void);
typedef	int		(__stdcall *TGuiTerminate)			(void);

leDeclareFunc(GuiInitialize);
leDeclareFunc(GuiGetHandle);
leDeclareFunc(GuiTerminate);

 

and edited the Initialize()-function:

inline int Initialize(int allowenginedebug)
{
LPCSTR dllfilename;
if(1==allowenginedebug)
{
#ifdef DEBUG
	dllfilename = (LPCSTR) "CWGui.dll";
#else
	dllfilename = (LPCSTR) "CWGui.dll";
#endif
}
else
	if(2==allowenginedebug)
		dllfilename = (LPCSTR) "CWGui.dll";
	else
		dllfilename = (LPCSTR) "CWGui.dll";
gui_hlib = LoadLibraryA(dllfilename);
(leGuiInitialize) = (TGuiInitialize) GetProcAddress(gui_hlib,"initializeGui");
(leGuiTerminate) = (TGuiTerminate) GetProcAddress(gui_hlib,"terminateGui");
(leGuiGetHandle) = (TGuiGetHandle) GetProcAddress(gui_hlib,"getLEHandle");
leGuiInitialize(allowenginedebug);
le_hlib = leGuiGetHandle();
if (le_hlib != 0)
{	/*printf("%s loaded.\n", dllfilename)*/;
	leLoadFuncs();\
}\
else\
	printf("%s failed to load.\n", dllfilename);
return NULL!=le_hlib;
}

 

and the Terminate():

inline int Terminate(void)
{
   return leGuiTerminate();
}

 

but it seems like im doin something wrong..

 

everything compiles fine, but when i try to run it i recently get an error message before even anything is written into the log

Link to comment
Share on other sites

Ok, I know know where the error occures..

 

seems like he cant find my functions..

 

if(leGuiInitialize==NULL)
		printf("Error: GuiInitialize=NULL\n");
	(leGuiTerminate) = (TGuiTerminate) GetProcAddress(gui_hlib,"terminateGui");
	if(leGuiTerminate==NULL)
		printf("Error: leGuiTerminate=NULL\n");
	(leGuiGetHandle) = (TGuiGetHandle) GetProcAddress(gui_hlib,"getLEHandle");
	if(leGuiGetHandle==NULL)
		printf("Error: leGuiGetHandle=NULL\n");

 

all three are null....

Link to comment
Share on other sites

in my .dll header

That's your dll source code, not your dll header. The dll header should be similar to engine.h and engine.cpp, but of course only declaring and loading and your own functions.

 

You don't need to make any changes to engine.h and engine.cpp, that's what the LoadFuncs() function is for, that you don't need to change them.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...