Trying to dynamically load a class at rutime from DLL
Hi,
I am new to coding with macros. I have this code and I am trying to run this by dynamically loading a class from a DLL.
Code:
#pragma once
#ifndef DLLEXPORTS_H
#define DLLEXPORTS_H
#ifdef _LoadPCDigDlls_h_
#define _LoadPCDigDlls_h_
#define CALLBACK __stdcall
#define IFC_IMP_DLL __declspec(dllimport)
#endif //_LoadPCDigDlls_h_
#define IFCAPI __stdcall
#define IFCCALL IFC_IMP_DLL IFCAPI
typedef enum {
IFC_CAP_MBOARD, // Image Capture motherboard, e.g., IC-PCI,PCVision
IFC_MNG_MBOARD, // Image Manager motherboard, e.g., IM-PCI
IFC_CMC_MBOARD, // Computational module motherboard, e.g., CMC-PCI
IFC_AM_DBOARD,
IFC_CM_DBOARD,
IFC_DM_DBOARD,
IFC_NUM_BOARD_KINDS
} IFC_BOARD_KIND;
#define IFC_ACTIVE_CAMERA_FLAG 0x8000
typedef unsigned char * pBYTE;
#define IFC_INFINITE_FRAMES -1
typedef void *HIFCGRAB;
class IFC_IMP_DLL CIobject
{
public:
// Object model (types, destruction, allocation)
virtual ~CIobject(); // virtual destructors are necessary
#ifdef new
#define _IFC_SAVE_NEW_
#undef new
#endif
void* IFCAPI operator new(size_t nSize);
void* IFCAPI operator new(size_t nSize,void* p);
void IFCAPI operator delete(void* p);
#if _MSC_VER >= 1200
void IFCAPI operator delete(void* p, void* pPlace);
#endif
// for file name/line number tracking using DEBUG_NEW
void* IFCAPI operator new(size_t nSize, LPCSTR lpszFileName, int nLine);
#if _MSC_VER >= 1200
void IFCAPI operator delete(void* p, LPCSTR lpszFileName, int nLine);
#endif
#if defined(_IFC_SAVE_NEW_) && defined(_DEBUG) && defined(DEBUG_NEW)
#define new DEBUG_NEW
#endif
#ifdef _IFC_SAVE_NEW_
#undef _IFC_SAVE_NEW_
#endif
// Disable the copy constructor and assignment by default so you will get
// compiler errors instead of unexpected behaviour if you pass objects
// by value or assign objects.
protected:
CIobject();
private:
CIobject(const CIobject& objectSrc); // no implementation
void operator=(const CIobject& objectSrc); // no implementation
};
class IFC_IMP_DLL CModule : public CIobject
{
public:
CModule();
virtual ~CModule();
};
class IFC_IMP_DLL CParentMod : public CModule
{
public:
CParentMod();
virtual ~CParentMod();
};
typedef CParentMod * PCParentMod;
typedef PCParentMod (CALLBACK* LPIfxCreateParentModule)(IFC_BOARD_KIND modKind, DWORD modSubkind, DWORD seqnum, char *cfgFile=NULL, BOOL inspectOnly=FALSE);
typedef PCParentMod (CALLBACK* LPIfxCreateCaptureModule)(char *modName,DWORD seqnum, char *cfgFile);
typedef void (IFC_IMP_DLL* LPProcessCameraFilesInDir)(const pSTRING szPath, BOOL bRecurse = FALSE);
typedef BOOL (IFC_IMP_DLL* LPEnableJitGrabMemLock)(void);
typedef CICamera (IFC_IMP_DLL* LPGetCam)(DWORD camPortNum=IFC_ACTIVE_CAMERA_FLAG);
typedef HIFCGRAB (IFC_IMP_DLL* LPGrab)(DWORD dwOptions,pBYTE dest, int ringNumFrames,int totalNumFrames=IFC_INFINITE_FRAMES, int x=0, int y=0, int dx=0, int dy=0);
typedef BOOL (IFC_IMP_DLL* LPFreeze)(CIFrame *frame);
typedef int (IFC_IMP_DLL* LPGrabWaitFrameEx)(HIFCGRAB grabID, BYTE **frameAddr=NULL, int FrameSeqNum=IFC_WAIT_NEWER_FRAME, DWORD milliseconds=IFC_WAIT_FOREVER, BOOL lock=TRUE,DWORD *acquiredDy=NULL, BOOL *VirtualFrameEnd=NULL, GRAB_EXT_ATTR *ExtendedAttr=NULL);
typedef void (IFC_IMP_DLL* LPGrabRelease)(HIFCGRAB grabID, int seqNum);
typedef void (IFC_IMP_DLL* LPGetAttr)(LPCAM_ATTR lpAttr, BOOL zoomCorrected=TRUE);
extern LPIfxCreateParentModule IfxCreateParentModule;
extern LPIfxCreateCaptureModule IfxCreateCaptureModule;
extern LPProcessCameraFilesInDir ProcessCameraFilesInDir;
extern LPEnableJitGrabMemLock EnableJitGrabMemLock;
extern LPGetCam GetCam;
extern LPGrab Grab;
extern LPFreeze Freeze;
extern LPGrabWaitFrameEx GrabWaitFrameEx;
extern LPGrabRelease GrabRelease;
extern LPGetAttr GetAttr;
extern int LoadPCDigDlls();
extern int FreePCDigDlls();
When I build the solution I am getting these errors
Code:
1>------ Build started: Project: sprayQC, Configuration: Debug Win32 ------
1>Compiling...
1>LoadPCDigDlls.cpp
1>c:\projects\sprayqc2601\loadpcdigdlls.h(92) : error C2383: 'LPIfxCreateParentModule' : default-arguments are not allowed on this symbol
1>c:\projects\sprayqc2601\loadpcdigdlls.h(94) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(95) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(96) : warning C4042: 'LPGetCam' : has bad storage class
1>c:\projects\sprayqc2601\loadpcdigdlls.h(96) : error C2091: function returns function
1>c:\projects\sprayqc2601\loadpcdigdlls.h(96) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(97) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(98) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(99) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(100) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(101) : error C2059: syntax error : '__declspec(dllimport)'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(105) : error C2146: syntax error : missing ';' before identifier 'ProcessCameraFilesInDir'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(105) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(105) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(106) : error C2146: syntax error : missing ';' before identifier 'EnableJitGrabMemLock'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(106) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(106) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(107) : error C2146: syntax error : missing ';' before identifier 'GetCam'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(107) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(107) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(108) : error C2146: syntax error : missing ';' before identifier 'Grab'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(108) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(108) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(109) : error C2146: syntax error : missing ';' before identifier 'Freeze'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(109) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(109) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(110) : error C2146: syntax error : missing ';' before identifier 'GrabWaitFrameEx'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(110) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(110) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(111) : error C2146: syntax error : missing ';' before identifier 'GrabRelease'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(111) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(111) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(112) : error C2146: syntax error : missing ';' before identifier 'GetAttr'
1>c:\projects\sprayqc2601\loadpcdigdlls.h(112) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(112) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\projects\sprayqc2601\loadpcdigdlls.h(116) : fatal error C1070: mismatched #if/#endif pair in file 'c:\projects\sprayqc2601\loadpcdigdlls.h'
1>Build log was saved at "file://c:\Projects\sprayQC2601\Debug\BuildLog.htm"
1>sprayQC - 35 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Somebody please help me.
Thanks in advance.
Re: Trying to dynamically load a class at rutime from DLL
For dynamical load use not classes but interfaces.