Dll loading help!

Started by
8 comments, last by DrEvil 19 years, 6 months ago
Ok, say I have a game dll for any game doesn't matter. What I want to do is have this dll load another dll and give this 2nd dll the ability to call a bunch of functions from the first dll. In addition I want the first dll to be able to call functions in the 2nd dll as well. I'm making a bot for a q3 mod, and the mod is written entirely in C, however my bot code is C++, so I'm thinking what I'm going to need to do, and please correct me if I'm wrong. From the game.dll, call LoadLibrary to load the bot.dll Use getprocaddress to get the setup function from the bot.dll Call the setup function from the game.dll and pass a struct, full of all the function pointers I want the bot.dll to be able to access from the game.dll Use getprocaddress again to get the functions from the bot.dll that the game.dll should call regularly, update(), init()... Am I on the right track here? Is this the proper/easiest way for a dll to give a 2nd dll the ability to call its functions? By passing the 2nd dll a struct with all the function pointers for the first dll? Basically what I'm doing is writing a generic bot framework that can be used in different game engines. I just need my interface layer dll to do the engine specific stuff and have the bot.dll call the generically named functions, so it can in theory work on multiple engines and games so long as the interface layer translates the game events and messages into the generic messages the bot uses. Any help appreciated.
Advertisement
that should work, passing a struct of function pointers across dlls. This is the way quake2 engine talks to the renderer (dll), passing an import structur of function pointers and getting an export structure of function pointers.

Quake 3 if you look at the game source uses a messaging system, where the dll has 2 entry points (init and vm/msg). So the engine calls the message function with a parameter like GC_INIT, GC_UPDATE, etc. Might wanna take a look at that system too, the function pointers would work better probably in your case.

Hope that helped
Too kludgy. You can mix C and C++ in the same DLL without the outside world knowing about it.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
How do you mix c and c++ ? Is there some compiler option I need to set?

I tried adding a bare bones class to one of the header files of the Enemy Territory SDK and it won't compile. Same when I try to include a header with a class in it. Taking out the class and it works fine.

Quote:Original post by DrEvil
How do you mix c and c++ ? Is there some compiler option I need to set?

I tried adding a bare bones class to one of the header files of the Enemy Territory SDK and it won't compile. Same when I try to include a header with a class in it. Taking out the class and it works fine.


you can just write c code in cpp files, as normal. I am mixing c and c++ in my project, working fine.

I haven't worked with the SDK but are you sure you didn't forget a semicolon at the end of the class or something silly like that.
If you couldn't mix C and C++ your C++ code wouldn't work...
Let me clarify, the entire Enemy territory SDK is in straight C. If I try to define a class or include a header with a class defined, it won't compile. I'm well aware you can use C in C++, but in this case it seems to be fixed in C mode and doesn't like classes. Anyone know how to get it to use them both? It doesn't seem to be as simple as typing in some C++ code.

Even under C/C++ project settings it is set to "Compile As" C++ code. So I don't understand why it isn't letting me use classes.

Anyone?
You don't include C++ code where it might be seen by C code.

If it is unavoidable that C code will hit C++ code, then surround the C++ with #ifdef __cplusplus/#endif.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
uhh, so you can mix c with c++, but you can't mix c++ with c ?
bump, can someone clarify this stuff please?

thanks.

This topic is closed to new replies.

Advertisement