I’m writing a *dll in c++ to connect to database. I tried using afxdb.h in my console application and it works fine. Now, I want to use the same code in my *dll. So, I added afxdb.h to stdafx.h and when I compiled gave me this error
mfcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in JunkDLL.obj
mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in JunkDLL.obj; second definition ignored
Creating library Debug/JunkDLL.lib and object Debug/JunkDLL.exp
Debug/JunkDLL.dll : fatal error LNK1169: one or more multiply defined symbols found
my stdafx.h looks like
#if !defined(AFX_STDAFX_H__123__INCLUDED_)
#define AFX_STDAFX_H__123__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "afxwin.h"
#include "afxext.h"
#include "afxdb.h"
// Insert your headers here
#define WIN32_LEAN_AND_MEAN// Exclude rarely-used stuff from Windows headers
#include "windows.h"
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__123__INCLUDED_)
Thanks for any help.
Your DLL is statically linked to MFC. In this situation, MFC provides its own
DllMain()entry point, and your DLL should not provide one.You can either perform initialization in the
InitInstance()method of a CWinApp-derived singleton, or dynamically link your DLL to MFC.