Overloaded functions and Dll(with Explicit Linking)
I wish to export two overloaded function from a dll and then use them in a client program which access the dll through explicit linking. The GetProcAddress() function fails! I understand that it is because when Dll is built , the names of exported functions are changed. If I use extern "C" while exporting then I can't overload the functions.
code of the dll written in a .cpp file is:
#define DLLEXPORT __declspec(dllexport)
DLLEXPORT int MySquareFunction(int);
DLLEXPORT double MySquareFunction(double);
int MySquareFunction(int i)
double MySquareFunction(double i)
code of the client is:
int i ,ii;
typedef int (*FPTR1)(int);
typedef double (*FPTR2)(double);
hInstance = LoadLibrary("F:\\nishant\\My Code\\StudyofDlls\\cpp\\ExpLink\\ExpCppDllProj\\De bug\\ExpCppDllProj.dll");
if(hInstance != NULL)
fp1 = (FPTR1) GetProcAddress(hInstance,"MySquareFunction");
if(fp1 != NULL )
cout<<"\nEnter an integer: ";
ii = (*fp1)(i);
cout<<"\nSquare of "<<i<<" is: "<<ii;
cout<<"\nThe address of int MySquareFunction(int) function could not be located.";
fp2 = (FPTR2) GetProcAddress(hInstance,"MySquareFunction");
if(fp2 != NULL )
cout<<"\nEnter a double: ";
dd = (*fp2)(d);
cout<<"\nSquare of "<<d<<" is: "<<dd;
cout<<"\nThe address of double MySquareFunction(double) function could not be located.\n";
cout<<"\nThe LoadLibrary() function failed.\n";
&TH of undefined behavior
You cant do it.....GetProcAddress expects C linkage...no name decoration...therefore no overloading.......either use 2 function names or link via a lib file
Thanx for clarification, but that means i can't export classes and then import them explicitlv with GetProcAdress().
Yes you can export objects, but it's not straight forward.
Normally, you export a function to create an instance of your object and return a pointer to it. You also need to export a function to destroy it.
In addition, if you want compatability between compilers, and/or between different versions of your DLL, you need to use pure virtual base classes and export pointers to these.
Here's some info: