DLLs + Classes?

Started by
3 comments, last by Rainmaker 23 years, 5 months ago
I have created a complete sound system for a project (StarCraft 3d) and want to turn it into a DLL. I have some limited knowledge over DLLs, including you need to EXPORT your functions into the .lib. That is all great, except for the fact that all of my functions are in a class! Is it possible to have classes in a DLL? If so, HOW!? Thanks
Advertisement
Absolutely. Have a function in the dll that returns a pointer to the class itself and export this function alone. But with this approach you might end up with a lot of problems of aliasing across files. I had a lot of problems specially when loading/linking them dynamically. For load time linking , this approach worked okay. But instead what I ended up doing was export each of the functions from the class interface,(this is the more common way of doing it). On the receiving end though you would sort of have to write a wrapper for the class in the dll, but you already know all that.

Absolutely. Have a function in the dll that returns a pointer to the class itself and export this function alone. But with this approach you might end up with a lot of problems of aliasing across files. I had a lot of problems specially when loading/linking them dynamically. For load time linking , this approach worked okay. But instead what I ended up doing was export each of the functions from the class interface,(this is the more common way of doing it). On the receiving end though you would sort of have to write a wrapper for the class in the dll, but you already know all that.

Hi. This is about the way I do it but I have a different technique to define HOW things are done. I read all about it on www.codeguru.com. Heres the link to the article.
http://codeguru.earthweb.com/dll/expclass.shtml
The way I do it was shown by Eugen Pavel in the replys secion here. http://codeguru.earthweb.com/mfc/comments/1156.shtml

Personally I think his way of wrapping up the LoadLibrary call and use of a "Mini COM" way of doing things is really neat.

Pete
It depends on if you want 1) link the DLL at loadtime (it''ll always be loaded when the program is loaded) or 2) link the DLL at runtime (you decide when and if to load it).

The loadtime linking sort of spoils the whole beuty of DLLs, they''ll be loaded no matter what and since you have to link a .lib with the program you''ll have to recompile the program if you change the DLL.
Anyways, to do this you just add __declspec(dllexport) or __declspec(dllimport) in the class declration, this is MS specific though, and link the .lib produced when you compile the DLL with the exe file.

Runtime linking is a bit more complicated...someone already gave a link to a document about this I think, there''s also an article about using interfaces with DLL''s here on gamedev. Just look under "previously featured articles" on the mainpage and then "Using interfaces with DLL''s".

"Paranoia is the belief in a hidden order behind the visible." - Anonymous

This topic is closed to new replies.

Advertisement