Skip to main content
GameDev.net gamedev.net
🔒 Locked

GCC Dll's and GetProcAddress()

Started by CloudNine Aug 27, 2003 at 2:48 PM 4 replies 2.3k views
Original Post
CloudNine
CloudNine
Yo, I''ve been following the ''Striving for Graphics API Independence'' series of articles, and I''ve decided to implement a wrapper of my own, following the factory design. However, I''ve run into problems with calling GetProcAddress on GCC Dlls. I import a custom made .def file, containing two function names, CreateRenderInterface and DestroyRenderInterface into the project. The dll and lib compile well, but the test project doesn''t. Here''s the relavent code: Relevant source:
extern "C"
{

ZRESULT CreateRenderInterface(RenderInterface **pInterface)
{
 if (!*pInterface)
 {
  *pInterface=new OGLRenderer();
  return Z_OK;
 }
 return Z_FAIL; 
}

void DestroyRenderInterface(RenderInterface **pInterface)
{
 if (!*pInterface)
 {
  return;
 }
 delete *pInterface;
 *pInterface=NULL;
} 

}
The definiton''s of the functions in a header file
extern "C"
{
 ZRESULT CreateRenderInterface(RenderInterface** pInterface);
 typedef ZRESULT (*CREATERENDERINTERFACE)(RenderInterface** pInterface);
 
 void DestroyRenderInterface(RenderInterface** pInterface);
 typedef void (*DESTROYRENDERINTERFACE)(RenderInterface** pInterface);
}
 
and the code to load the DLL
ZRESULT RenderFactory::InitInterface(API a)
{
 if (a==ZIN_API_OGL)
 {
  //Load GL libary here

  mModule=LoadLibraryEx("GL/GLRenderer.dll",NULL,0);
  if (mModule==NULL)
  {
   MessageBox(NULL,"GL Dll could not be loaded","!",MB_OK | MB_ICONSTOP);
   return Z_FAIL;
  }
 }
 
 if (a==ZIN_API_D3D)
 {
  mModule=LoadLibraryEx("D3D/D3DRenderer.dll",NULL,0);
  if (mModule==NULL)
  {
   MessageBox(NULL,"D3D dll could not be loaded","!",MB_OK | MB_ICONSTOP);
   return Z_FAIL;
  }
 }
 
 CREATERENDERINTERFACE CreateInterface=NULL;
 CreateInterface=(CREATERENDERINTERFACE)GetProcAddress(mModule,"CreateRenderInterface");
 
 if (CreateInterface==NULL)
 {
  MessageBox(NULL,"Function address could not be retrieved","!",MB_OK | MB_ICONSTOP);
  return Z_FAIL;
 } 
 
 ZRESULT zr=CreateInterface(&mInterface);
 if (zr!=Z_OK)
 {
  MessageBox(NULL,"Render interface could not be created","!",MB_OK | MB_ICONSTOP);
  return Z_FAIL;
 } 
 return Z_OK;
}  

void RenderFactory::DestroyInterface()
{
 DESTROYRENDERINTERFACE DestroyInterface;
 DestroyInterface=(DESTROYRENDERINTERFACE)GetProcAddress(mModule,"DestroyRenderInterface");
 DestroyInterface(&mInterface);
}
Any ideas on why GetProcAddress fails? CloudNine
Stonicus
Stonicus
you need __declspec(dllexport) in front of any DLL func that GetProcAddress will try to find...

#define MYEXPORT extern "C" __declspec(dllexport)

MY_EXPORT bool QueryDoIKickAss() { return true; }

FrancoisSoft
FrancoisSoft
GetProcAddress() is pure beeshit!!! It never works and I don''t think any applications use it! I use Rundll32, heh heh! That''s the best way to load dlls - THROUGH WINDOWS!!! All you have to do is call rundll32 like this.

Rundll32 MyDll.dll, _MyFunc %s %i %f

this is the definition for _MyFunc:

void MyFunc(char* S, int I, float F);

if you want the return value of the function then you use WinExec() and set a variable of the return type equal to it. This is how you do it:

int I = WinExec("Rundll32 MyDll.dll, _MyFunc %s %i %f", SW_SHOW);

the new definition for _MyFunc in this case is:

int MyFunc(char* S, int I, float F);

I hope this helps because it sure does for me!!!
Like I said use windows to load dll''s - not your program. That''s what windows is for - to be a slave for your programs!


Hey, don''t forget to visit my page... by clicking here!
VolkerG
VolkerG
A good way to look at the exported symbols is to use Dependency Walker. And I wouldn''t listen to what FrancoisSoft is saying, I wonder what modern games/apps don''t use GetProcAddress (). I''d like to see a plugin system using rundll.
Sneftel
Sneftel
quote:
Original post by FrancoisSoft
I use Rundll32, heh heh!

Oh god. I really hope FrancoisSoft isn''t serious. You''re not serious, right?


How appropriate. You fight like a cow.
CloudNine
CloudNine
Seems that all it needed was the _declspec(dllexport). Thanks for the help

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.