2012-07-10 7 views
1

나는 데이터베이스에 연결하기 위해 * dll을 C++로 작성하고있다. 내 콘솔 응용 프로그램에서 afxdb.h 사용하여 시도하고 잘 작동합니다. 자, 내 * dll에서 같은 코드를 사용하고 싶다. 그래서, STDAFX.H에 AFXDB.H 추가 내가 컴파일 할 때 어떤 도움afxdb.h 오류가 발생 했습니까?

#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_) 

감사처럼 나에게

mfcs42d.lib(dllmodul.obj) : error LNK2005: [email protected] already defined in JunkDLL.obj 
mfcs42d.lib(dllmodul.obj) : warning LNK4006: [email protected] 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 

내 stdafx.h를 보이는이 오류를했다.

답변

1

귀하의 DLL은 statically linked to MFC입니다. 이 상황에서 MFC는 자신의 DllMain() 진입 점을 제공하고 DLL은이를 제공해서는 안됩니다.

CWinApp- 부분 단독 또는 dynamically link your DLL to MFCInitInstance() 메서드에서 초기화를 수행 할 수 있습니다.

+0

그래서 BOOL APIENTRY DllMain (...)을 JunkDLL.cpp에서 주석 처리하고 오류없이 컴파일했습니다. 이것을하는 것이 올바른 방법일까요? 저는 C++을 처음 접했습니다 (VC 6). – bMathew

+0

'DllMain()'이 초기화 또는 종료 작업 (즉, 비어있는 경우)에 대한 책임이 없다면, 실제로하는 것이 옳은 일입니다. (개인적인 취향에 따라, 코멘트에서 죽은 코드는 모듈이 이해하고 유지 보수하는 것을 어렵게하는 잡음을 발생시키기 때문에 주석 처리하는 대신 함수를 제거하는 것이 좋습니다.) –

+0

* .dll은 데이터 액세스 레이어 여러 스레드가 액세스합니다. 이 경우 DLLMain()이 필요한지 확실하지 않습니다. – bMathew

관련 문제