.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   General Programming (http://forums.bots-united.com/forumdisplay.php?f=25)
-   -   (noob) calling a function in a DLL (http://forums.bots-united.com/showthread.php?t=689)

Pierre-Marie Baty 10-02-2004 18:17

(noob) calling a function in a DLL
 
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 ??? :'(

Pierre-Marie Baty 10-02-2004 19:39

Re: (noob) calling a function in a DLL
 
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... :P


All times are GMT +2. The time now is 03:40.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.