How to construct DLL files properly?
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
if understanding it made and born with time, then time, is understandings greatest enemy.....
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.
I haven''t tried to export a class (yet), but thought that was an issue COM addressed.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
November 25, 2000 05:33 AM
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
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
November 25, 2000 06:10 AM
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
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
November 25, 2000 06:14 AM
Fuck i made a mistake its
//---cut here ----------------------------------
class __declspec(dllexport)
{
public:
private:
};
//---cut here ----------------------------------
--> Violent1
//---cut here ----------------------------------
class __declspec(dllexport)
{
public:
private:
};
//---cut here ----------------------------------
--> Violent1
November 25, 2000 06:16 AM
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
you must of course add your classname after it...
Does anyone know how one can edit an anonymous post?
AARG!
--> Violent1
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
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
if understanding it made and born with time, then time, is understandings greatest enemy.....
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
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
if understanding it made and born with time, then time, is understandings greatest enemy.....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement