.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Developer's Farm > General Programming
General Programming Help others and get yourself helped here!

Reply
 
Thread Tools
(noob) calling a function in a DLL
Old
  (#1)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default (noob) calling a function in a DLL - 10-02-2004

jeez this is really driving me nuts

Not two DLL tutorials on the net say the same thing, wtf? I need for my work to build a DLL in MSVC that exports a function and an executable in MSVC too that will call this function in the DLL.

I have made a simple DLL that has 2 functions and looks like this:
Code:
int WINAPI DllMain (HINSTANCE hinstDLL, unsigned long fdwReason, void *lpvReserved)
{
   return (TRUE);
}

void InputPluginAPI (char *input_pathname, block_t *output_blocks)
{
   // this function reads and translate the data from a CSV file into block structures.
 
   // [snip] code follows...
}
I have made a .def file for this DLL
Code:
LIBRARY in_cms
EXPORTS
   InputPluginAPI
SECTIONS
   .data READ WRITE
It builds okay. Normally the in_cms.dll should be exporting the InputPluginAPI function, right ?

Now when I try to load it and call it in my main project executable... (here's the WinMain function of this executable)
Code:
typedef void (*IN_PLUGINAPI) (char *input_pathname, block_t *output_blocks);
IN_PLUGINAPI ImportedFunction;
 
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpCmdLine, int nCmdShow)
{
   // program entrypoint
 
   // load the input DLL
   hInputDll = LoadLibrary ("in_cms.dll" );
   if (hInputDll == NULL)
	  TerminateOnError ("WinMain(): unable to load input DLL\n"); // bomb out on error
 
   // get a pointer to the input plugin API
   ImportedFunction = (IN_PLUGINAPI) GetProcAddress (hInputDll, "InputPluginAPI");
   if (!ImportedFunction)
	  TerminateOnError ("WinMain(): unable to get input plugin API\n"); // bomb out on error
 
   // rest of function follows...
}
it fails to GetProcAddress() for the function I want to call in my DLL!

What am I doing wrong ??? :'(



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Re: (noob) calling a function in a DLL
Old
  (#2)
Pierre-Marie Baty
Roi de France
 
Pierre-Marie Baty's Avatar
 
Status: Offline
Posts: 5,049
Join Date: Nov 2003
Location: 46°43'60N 0°43'0W 0.187A
Default Re: (noob) calling a function in a DLL - 10-02-2004

meh, I think I've found it

I must export the function this way instead:
Code:
#define DLLEXPORT extern "C" __declspec (dllexport)
 
DLLEXPORT void InputPluginAPI (char *input_pathname, block_t *output_blocks)
{
   // this function reads and translate the data from a CSV file into block structures.
 
   // [snip] code follows...
}
silly me...



RACC home - Bots-United: beer, babies & bots (especially the latter)
"Learn to think by yourself, else others will do it for you."
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com