How to import class from a dll?
-
Hi, I want to import a class from a dll dynamiclly by using LoadLibrary(DLLFile) and not by using Project->Settings->Link.... Is it the same as loading regular function from a dll(By getting a pointer to that function)? for example,if in my dll the function looks like this: in my dll.h file:
#define TCPDLL_API __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endifTCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server,int num_of_radars);
#ifdef __cplusplus
}
#endifand in my dll.cpp file:
TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server , int num_of_radars)
{
//Do something
}now,when i want to use the function : in my app.h:
typedef ERROR_CODES (*FLRInitializeConnections_PROC )(IPStruct*,int);
HINSTANCE hLib;
// imported functions handles
FLRInitializeConnections_PROC FLRInitializeConnections;and in my app.cpp:
hLib = LoadLibrary(DLL name);
FLRInitializeConnections = (FLRInitializeConnections_PROC)GetProcAddress(hLib,"FLRInitializeConnections");
Now i can call the function from the dll. My question is - in order to use a class from a dll , what should i do? Do i need to get a pointer to that class or can i load the dll and make instance of that class in the regular way? With best regards, Eli
-
Hi, I want to import a class from a dll dynamiclly by using LoadLibrary(DLLFile) and not by using Project->Settings->Link.... Is it the same as loading regular function from a dll(By getting a pointer to that function)? for example,if in my dll the function looks like this: in my dll.h file:
#define TCPDLL_API __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endifTCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server,int num_of_radars);
#ifdef __cplusplus
}
#endifand in my dll.cpp file:
TCPDLL_API ERROR_CODES FLRInitializeConnections(IPStruct *Server , int num_of_radars)
{
//Do something
}now,when i want to use the function : in my app.h:
typedef ERROR_CODES (*FLRInitializeConnections_PROC )(IPStruct*,int);
HINSTANCE hLib;
// imported functions handles
FLRInitializeConnections_PROC FLRInitializeConnections;and in my app.cpp:
hLib = LoadLibrary(DLL name);
FLRInitializeConnections = (FLRInitializeConnections_PROC)GetProcAddress(hLib,"FLRInitializeConnections");
Now i can call the function from the dll. My question is - in order to use a class from a dll , what should i do? Do i need to get a pointer to that class or can i load the dll and make instance of that class in the regular way? With best regards, Eli
View this link http://www.codeproject.com/dll/classesexportedusingLL.asp[^]
-
View this link http://www.codeproject.com/dll/classesexportedusingLL.asp[^]
thanks:->