baris.aydinoz baris.aydinoz - 3 months ago 27
C++ Question

About inconsistent dll linkage

How can I remove this link warning? You can see code segment that causes this warning.

static AFX_EXTENSION_MODULE GuiCtrlsDLL = { NULL, NULL };
//bla bla
// Exported DLL initialization is run in context of running application
extern "C" void WINAPI InitGuiCtrlsDLL()
{
// create a new CDynLinkLibrary for this app
new CDynLinkLibrary(GuiCtrlsDLL);
// nothing more to do
}


warning C4273: 'InitGuiCtrlsDLL' : inconsisten
t dll linkage

I have also export and import definitions, like:

#ifdef _GUICTRLS
#define GUI_CTRLS_EXPORT __declspec(dllexport)
#else
#define GUI_CTRLS_EXPORT __declspec(dllimport)
#endif

Answer

There are multiple possibilities:

1) static AFX_EXTENSION_MODULE GuiCtrlsDLL = { NULL, NULL };

You use AFX_EXTENSION_MODULE. This means that you are implementing an MFC extension DLL. For such extension dlls you have to define the preprocessor _AFXEXT. Set this in the C++ compiler settings of your Visual C++ project

see:

How To Use _declspec(dllexport) in an MFC Extension DLL: http://support.microsoft.com/kb/128199

(Currently I cannot post more than 1 link because my reputation is less than 10. I will add 2 more important links later. So if this is the solution, mark it as answer to speed-up the process ;) )

As promised, here are the two links:

AFX_EXTENSION_MODULE Structure: http://msdn.microsoft.com/en-us/library/sxfyk0zk.aspx

TN033: DLL Version of MFC: http://msdn.microsoft.com/en-us/library/hw85e4bb.aspx

2) It is likely that you have a duplicated definiton/declaration.