Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neurokaotix

Question to any who understands creating c++ dlls, and using the one you make.

This topic is 5589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My engine, and the tech demo I''m creating with it, have always been in the same project. However, I would now like to make the engine a separate DLL file. That has been going kinda of well until now because I can''t figure out how to get a specific part of it to work... In my CCamera.cpp (as well as several other .cpps) which are a part of the engine .dll, there are several variables which they try to access (like height and width and other things which are a part of the other project, the tech demo). Is there some way that the I can have the dll call those variables (or perhaps some kind of virtual variable of some kind) that let it work? Because I''m really not sure as to how this is supposed to work lol Any input would be greatly apprectiated, thanks

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by neurokaotix
My engine, and the tech demo I''m creating with it, have always been in the same project. However, I would now like to make the engine a separate DLL file. That has been going kinda of well until now because I can''t figure out how to get a specific part of it to work...

In my CCamera.cpp (as well as several other .cpps) which are a part of the engine .dll, there are several variables which they try to access (like height and width and other things which are a part of the other project, the tech demo). Is there some way that the I can have the dll call those variables (or perhaps some kind of virtual variable of some kind) that let it work? Because I''m really not sure as to how this is supposed to work lol

Any input would be greatly apprectiated, thanks


ever thought of using the variable as one of the params of the function using pointers ? or a function that returns a pointer of that type ?

be more psecific.. what kinds variable do you want ? some code should help

Share this post


Link to post
Share on other sites
The global variables can simply be declared extern in a header file used by everyone except the .cpp which actually allocates the space for them ... then when you build your project pieces, make sure they have the .lib file for the .dll project which owns the veriables (when building a .dll project you get a .dll and .lib file output ... the .lib (from project a) contains the information needed to inject the correct .dll run-time linking (for connecting to project a) into the .lib or .exe file you are building (project b).

I didn''t do the greatest job explaining ... but all I''m really trying to say is that using a global variable which happens to be located inside a dynamically loadable object file should not be any problem ... as long as you access it correctly ...

the 2 ways to access it correctly are to A) have a .lib file from the project which owns the variable, and use this, plus the extern keyword in a header file, and Visual C++ will automatically perform the hookups for you ... invisibly. Or B) use the normal .dll load / lookup functions to import symbols at runtime ... and your variable will be one of those symbols (obviously you need to export it as a symbol in the .dll project which owns the variable for this to work).

If you can''t or don''t want to do it this way .. then do this ... provide access / modification functions for the variable ... and export those functions ... then everyone in every language can lookup those function and call them ... without needing to (or being allowed to) access your variable directly (this is basically a nice, protected, object-oriented global variable then - aka a singleton).

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!