The Daily Click ::. Forums ::. Klik Coding Help ::. calldll and the cnc sdk
 

Post Reply  Post Oekaki 
 

Posted By Message

Danto



Registered
  17/11/2003
Points
  353
17th February, 2004 at 16:13:16 -

I am trying to create an extension for tgf and having a bit of trouble. How would I call a dll in the pluin code? If I have a separate dll and I want to use the functions from it inside a function for my extension how would I go about doing that? I've been reading through all the documentation and I don't see how to do that. I assume it can be done as that is what dmc2 is basically doing. I'm not sure if anyone can help.

I also tried using the calldll extension and running it directly though tgf with no luck either. I read the articles on calldll and couldn't even get it to work with bass.dll. Now I'm not sure what I'm doing wrong here as I followed the article exactly and understand the principles behind it. I tried the old bass.dll as well as the new one and nothing seems to work. I tried a mulitude of different ways of using the calldll and it doesn't seem to do anything. When I run the app with calldll I get no feedback at all. Anyone familiar with extension creation for tgf?

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
17th February, 2004 at 17:00:13 -

Calling a dll from an extension is the same as calling it from any other C++ app (AFAIK)

// 'template' for a farproc that takes an int and returns an int.
typedef int(*some_proc)(int);

HMODULE some_dll;
some_proc myprocedure;

some_dll = LoadLibrary("somedll.dll");

myprocedure = (some_proc)GetProcAddress(some_dll,"_myprocedure@4");

int result = myprocedure(500);

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Danto



Registered
  17/11/2003
Points
  353
17th February, 2004 at 18:16:34 -

Ok...I think I understand. Now the _myprocedure would be the function I want from the dll right? Ok so is

myprocedure = (some_proc)GetProcAddress(some_dll,"_myprocedure@4");

turning myprocedure in a function? I'm not sure I fully understand this line and how it's being used. I get the loading of the dll. That makes sense. The rest I'm a little fuzzy on. I did some research on pointers to functions and your example is done a bit differently then what I had found. The first link you had posted did a straight typedef void functype(int);

I'm not sure I understand the typedef int(*some_proc)(int). Is that another way of doing the same thing or is that being setup differently? Thanks for the quick response.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
17th February, 2004 at 19:15:18 -

ok...

GetProcAddress returns a FARPROC, which is the same as "int (__stdcall*)(void)". However myprocedure is an "int (__cdecl *)(int)", so to make them compatible you need to typecast it to that.

If you wanted you could do this:

// Declare a pointer to a function called myprocedure
int(*myprocedure)(int);
// Typecast the result of GetProcAddress to suit myprocedure
myprocedure = (int (__cdecl *)(int))GetProcAddress(some_dll,"_myprocedure@4");


using typedef is simply an easier method because it's shorter and easier to type (because you can use the same keyword in two places)

(sorry if this explanation isn't too good... i'm not very good at this myself, and most online tutorials are ugly. I suggest you just find your own way that works and stick with it)

Edit: remember that you're not converting to a function, you're only getting a pointer to its location in memory, then jumping to it

edit 2: I think "result = myprocedure(500);" should actually be "result = (*myprocedure)(500);"

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Danto



Registered
  17/11/2003
Points
  353
17th February, 2004 at 22:38:48 -

Hey...I got it. I found some articles on it and in conjunction with your stuff I figured it out. Thanks a bunch! I did it like this:

typedef ALboolean(*DLLDINIT_func)(void);


DLLDINIT_func DAMP_INIT;

damp_dll = LoadLibrary("damp.dll");



DAMP_INIT = (DLLDINIT_func)GetProcAddress(damp_dll,"_DAMP_INIT");

init_result = DAMP_INIT();


The declaration for damp_dll is done outside the function so I can use it multiple functions. But it all works. Thanks again for the help.

 
n/a

Danto



Registered
  17/11/2003
Points
  353
17th February, 2004 at 23:42:28 -

Alright...another question. I have a function to init my dll which works fine. It runs the functions it's suppose to and then I have a separate destroy function. The destroy function doesn't seem to be working when I end my application. I have an end game condition where I run the destroy function. It is not closing as it should. Is there separate function in the plugin code where I should add that code? Cause it does seem to close properly when I close out of tgf, but not my application. Any suggestions? Thanks again.

 
n/a

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
18th February, 2004 at 05:52:36 -

I've never actually made any TGF/MMF extensions (Can't stand that damn SDK) so you might be best asking someone like Marcello or Tigs. If you post some code though, I might be able to help



Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
18th February, 2004 at 14:35:14 -

Try freeing the DLLs in the Free() function (which runs when the extension is freed), if the external DLL is global to all instances of your object. (You would use Initialise() to initialise the DLL in this case.)

You might want to run a debugger over the DestroyRunObject function, because for me it runs when the application exits.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click