Jump to content
  • Advertisement

Archived

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

Kosh

How to construct DLL files properly?

This topic is 6593 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

hi everyone, I would like to know, if you have an object that you would like to put into a dll, so you can load it dynamically this technique is being used a lot in games where you support directx and opengl, by suppling different dll''s with a similar base class to both object. So when the user selects opengl, you load theopengl dll file, use GetProcAddress to get a function to construct an object of the type you want (either opengl or dx) or a class defintion, where you can use the constructor directly how do you construct your dll files? I really would like to know, cause I''m getting some stupid errors, about a pointer, being passed into a constructor, the pointer is valid, but when I try to use it, Access Violation (usually bad pointer) so I would like to ask you how you do it, if you have example code, please a url, that would be great thanks

Share this post


Link to post
Share on other sites
Advertisement
MSVC has a dll wizard built-in, suggest you create a couple of exported functions first, and maybe a value or two.

I haven''t tried to export a class (yet), but thought that was an issue COM addressed.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
COM -- Bah!

Gaz of Void fame has written a nice little tutorial on this subject; you can see it at http://www.thepeel.com/void/

I think a better solution is to have one DLL for rendering, and simply choosing the rendering system based upon registry setting / internal variable storage. It makes the integration simpler, but then you have to rebuild the DLL for each modification.

An even better solution would be to drop DirectX completly . But that''s just my opinion! (Aussie''s can''t give their two cents, because the government removed them from our currency )

Simon Wilson,
XEOS Digital Development

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I''m not sure if this is what you''re looking for so dont flame me
if its not....

Here''s a normal dll proc. Its neccessary to create a dll file.

//-----cut here----------------------------------------------
#include
#include

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
break;

case DLL_PROCESS_DETACH:
break;

}

return 1;
}
//-----cut here----------------------------------------------

So this should set you up to create a dll file.
Now to modify the class you want to export the following way...

//-----cut here----------------------------------------------
class __declspec(dllexport)
{
public:

private:
};
//-----cut here----------------------------------------------

as you can see that all you must do is add the _declspec(export)
in between. (it''s like this for MSVC++, dont know what you''re
using).

As usual, when exporting functions in a program an extra lib
file is created. you must include this one in the program
that imports the class (project settings).
You must also include the header file you defined the class
in.

This code was taken from something im coding on at the time...

//-----cut here----------------------------------------------class __declspec(dllexport) GLCONTXT
{
public:
HDC hdc;
HWND hwnd;
HGLRC glrc;
int width, height; //Window size (Must have valid aspect ratio)
BYTE bpp; //Bits per pixel (16/32)
BYTE depth; //Screen depth

int Apply(HWND, BYTE bpp, BYTE depth);
void Remove(void);
void Blit(void);

private:
int SetupPixels(void);
};
//-----cut here----------------------------------------------

This is the code from my renGL.dll file. All calls made to it
are similar in the directX version. the vertex, texture
data is handed to both renderers in another class just the same way.
I think this its really great to reuse code this way.
Speeds development and you can play around with it lots

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Fuck i made a mistake its


//---cut here ----------------------------------
class __declspec(dllexport)
{
public:

private:
};
//---cut here ----------------------------------

--> Violent1

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry UBB cuts away the part after __decl(export).
you must of course add your classname after it...

Does anyone know how one can edit an anonymous post?
AARG!

--> Violent1

Share this post


Link to post
Share on other sites
hi everyone

ok, I was looking around the net and well, I found very little helping me on how to do dll files and well, I was looking around the other day and you know when you can''t find something, but it''s right in front of you? well this was too. If you wanna read the tutorials at The Void engine website, this is at

The Void Tutorials

then you''ll find some interesting tutorials on how to do stuff, also, how to do dll files, just in case someone is reading this and wants to know more or perhaps learn something new...

thanks for your help guys, you''ve dont me a treat

kosh

Share this post


Link to post
Share on other sites
hi everyone

ok, I was looking around the net and well, I found very little helping me on how to do dll files and well, I was looking around the other day and you know when you can''t find something, but it''s right in front of you? well this was too. If you wanna read the tutorials at The Void engine website, this is at

The Void Tutorials

then you''ll find some interesting tutorials on how to do stuff, also, how to do dll files, just in case someone is reading this and wants to know more or perhaps learn something new...

thanks for your help guys, you''ve dont me a treat

kosh

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!