-
Overloaded functions and Dll(with Explicit Linking)
Hi,
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)
{
return i*i;
}
double MySquareFunction(double i)
{
return i*i;
}
code of the client is:
#include <iostream.h>
#include <windows.h>
int main(void)
{
int i ,ii;
double d,dd;
typedef int (*FPTR1)(int);
typedef double (*FPTR2)(double);
HINSTANCE hInstance;
FPTR1 fp1;
FPTR2 fp2;
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: ";
cin>>i;
ii = (*fp1)(i);
cout<<"\nSquare of "<<i<<" is: "<<ii;
}
else
{
cout<<"\nThe address of int MySquareFunction(int) function could not be located.";
}
fp2 = (FPTR2) GetProcAddress(hInstance,"MySquareFunction");
if(fp2 != NULL )
{
cout<<"\nEnter a double: ";
cin>>d;
dd = (*fp2)(d);
cout<<"\nSquare of "<<d<<" is: "<<dd;
}
else
{
cout<<"\nThe address of double MySquareFunction(double) function could not be located.\n";
}
FreeLibrary(hInstance);
}
else
{
cout<<"\nThe LoadLibrary() function failed.\n";
}
return 0;
}
Popular pages
Recent additions