I have a third-party library written in C. It exports all its functions to a DLL.
I have a .h file and I'm trying to load a DLL from my C ++ program.
The first thing I tried was the environment of those parts where I # included a third-party library in
#ifdef __cplusplus extern "C" { #endif
and in the end
#ifdef __cplusplus }
But the problem was that all the functions related to the DLL files looked like this in their header files:
a_function = (void *)GetProcAddress(dll, "a_function");
In fact, a_function was of type int (*a_function) (int *) . Apparently, the MSVC ++ compiler does not like this, while the MSVC compiler does not seem to mind.
So, I went through (brutal torture) and recorded them all on the model
typedef int (*_x_a_function) (int *);
Then, to associate it with the DLL code, in main ():
a_function = (_x_a_function)GetProcAddress(dll, "a_function");
This is SEEMS to make the MUCH compiler, MUCH happier, but STILL complains about this final set of 143 errors, each of which says for every attempt to make a DLL link:
error LNK2005: _x_a_function already defined in main.obj main.obj
Errors detecting multiple characters .. sounds like work for extern ! So, I went and made ALL declarations of function pointers as follows:
function_pointers.h
typedef int (* _x_a_function) (int *);
extern _x_a_function a_function;
And in the cpp file:
function_pointers.cpp
#include "function_pointers.h"
_x_a_function a_function;
ALL are small and dandy .. besides linker errors now form:
error LNK2001: unresolved external symbol _a_function main.obj
Main.cpp includes "function_pointers.h", so it needs to know where to find each of the functions.
I am bewitched. Does anyone have any pointers to make me function? (Sorry, pun.)