Sign in to follow this  
DrEvil

Dll loading help!

Recommended Posts

DrEvil    1148
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.

Share this post


Link to post
Share on other sites
nts    968
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

Share this post


Link to post
Share on other sites
DrEvil    1148
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.

Share this post


Link to post
Share on other sites
nts    968
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.

Share this post


Link to post
Share on other sites
DrEvil    1148
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?

Share this post


Link to post
Share on other sites
antareus    576
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this