Create a DLL with database classes (ODBC)
Dip. Ing. Fabio Saponaro - C.S.G. -- fabio@csg.it
Thursday, January 23, 1997
Enviroment: MSVC++ 1.52, Win 3.1
Hi,
I have a problem with use of ODBC class, incapsulated in a DLL.
I am creating a DLL that use database classes (ODBC) to connect with my
database, building with MS Access 2.0.
With Class Wizard I create the classes for connection with database.
The source file of this class (.h and .cpp) I removed from DLL project files.
I had seen example DLLTRACE, contained in MSVC++ 1.52, for setting compiler
e linker option and building my DLL.
Without including files of database classes, DLL works fine.
When I introduce database classes (including files .h) and use it, the
compiler give 0 errors, but linker says that was found an 'unresolved
external' errors.
This error occours for each database class that I use.
So, the question is:
How can I insert my database classe without problem ? And there's particular
settings for compiler and linker before building a DLL with MFC class ?
Thnks in advantage !!
Here's a part of code that produce a link error:
//
//
//
#include
#include
#include
#include "dblistco.h"
#include "dblistit.h"
#include "dblistle.h"
#include "dblistqu.h"
#include "dblistse.h"
#include "dblistte.h"
#include "CMentore.h"
#include "agmentsa.h"
// Public C interface
//
extern "C" BOOL FAR PASCAL __export GetCourseware(LPCSTR PathScriptDB,
CDBCourseware& Courseware)
{
......
}
extern "C" BOOL FAR PASCAL __export GetStringCourseware(LPCSTR PathScriptDB,
LPSTR StringCourseware)
{
//Only for example .....
CDatabase* m_database=NULL;
CDBListCourseware* OneDBCourseware(m_database); <-- THIS DECLARATION
PRODUCE A LINK ERROR
WHEN I REMOVE
THIS ROW, NO
ERROR
OCCOURS WITH LINKER
...
}
...
where class CDBListCourseware is:
// dblistco.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDBListCourseware recordset
class CDBListCourseware : public CRecordset
{
public:
CDBListCourseware(CDatabase* pDatabase = NULL);
// Field/Param Data
//{{AFX_FIELD(CDBListCourseware, CRecordset)
CString m_Courseware_Name;
CString m_Password;
CString m_Title;
CString m_Language;
int m_TotLessons;
int m_TotLessonsEnable;
int m_TotSection;
int m_TotSectionEnable;
double m_Trigger;
//}}AFX_FIELD
// Implementation
protected:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
DECLARE_DYNAMIC(CDBListCourseware)
};
// dblistco.cpp : implementation file
//
//#include "stdafx.h"
#include "dblistco.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDBListCourseware
IMPLEMENT_DYNAMIC(CDBListCourseware, CRecordset)
CDBListCourseware::CDBListCourseware(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CDBListCourseware)
m_Courseware_Name = "";
m_Password = "";
m_Title = "";
m_Language = "";
m_TotLessons = 0;
m_TotLessonsEnable = 0;
m_TotSection = 0;
m_TotSectionEnable = 0;
m_Trigger = 0;
m_nFields = 9;
//}}AFX_FIELD_INIT
}
CString CDBListCourseware::GetDefaultConnect()
{
return "ODBC;DSN=Script;";
}
CString CDBListCourseware::GetDefaultSQL()
{
return "ListCourseware";
}
void CDBListCourseware::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CDBListCourseware)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, "Courseware_Name", m_Courseware_Name);
RFX_Text(pFX, "Password", m_Password);
RFX_Text(pFX, "Title", m_Title);
RFX_Text(pFX, "Language", m_Language);
RFX_Int(pFX, "TotLessons", m_TotLessons);
RFX_Int(pFX, "TotLessonsEnable", m_TotLessonsEnable);
RFX_Int(pFX, "TotSection", m_TotSection);
RFX_Int(pFX, "TotSectionEnable", m_TotSectionEnable);
RFX_Double(pFX, "Trigger", m_Trigger);
//}}AFX_FIELD_MAP
}
Dip. Ing. Fabio Saponaro
Email: fabio@csg.it
Context Systems Group - Italian branch:
P.za Liberazione 25
20013 Magenta (MI)
Italia
Tel. ++39-2-97298145
Fax. ++39-2-97298225
Kenneth A. Argo -- argo@rias.COM
Friday, January 24, 1997
Change your include to use:
#include
Removing the other DB class includes at the same time.
There are a number of libraries which are required which is why you are =
getting the unresolved. This header properly adds the .LIBs to the link =
process while including the ODBC class headers.
Ken
----------
From: Dip. Ing. Fabio Saponaro - C.S.G.[SMTP:fabio@csg.it]
Sent: Thursday, January 23, 1997 12:06 PM
To: mfc-l@netcom.com
Subject: Create a DLL with database classes (ODBC)
Enviroment: MSVC++ 1.52, Win 3.1
Hi,
I have a problem with use of ODBC class, incapsulated in a DLL.
I am creating a DLL that use database classes (ODBC) to connect with my
database, building with MS Access 2.0.
With Class Wizard I create the classes for connection with database.
The source file of this class (.h and .cpp) I removed from DLL project =
files.
I had seen example DLLTRACE, contained in MSVC++ 1.52, for setting =
compiler
e linker option and building my DLL.
Without including files of database classes, DLL works fine.
When I introduce database classes (including files .h) and use it, the
compiler give 0 errors, but linker says that was found an 'unresolved
external' errors.
This error occours for each database class that I use.
So, the question is:
How can I insert my database classe without problem ? And there's =
particular
settings for compiler and linker before building a DLL with MFC class ?
Thnks in advantage !!
Here's a part of code that produce a link error:
//
//
//
#include
#include
#include
#include "dblistco.h"
#include "dblistit.h"
#include "dblistle.h"
#include "dblistqu.h"
#include "dblistse.h"
#include "dblistte.h"
#include "CMentore.h"
#include "agmentsa.h"
// Public C interface
//
extern "C" BOOL FAR PASCAL __export GetCourseware(LPCSTR PathScriptDB,
CDBCourseware& Courseware)
{
...... =20
}
extern "C" BOOL FAR PASCAL __export GetStringCourseware(LPCSTR =
PathScriptDB,
LPSTR StringCourseware)
{
//Only for example .....
CDatabase* m_database=3DNULL;
CDBListCourseware* OneDBCourseware(m_database); <-- THIS DECLARATION
PRODUCE A LINK ERROR
WHEN I =
REMOVE
THIS ROW, =
NO
ERROR
OCCOURS WITH LINKER =20
...
}
..
where class CDBListCourseware is:
// dblistco.h : header file
//
/////////////////////////////////////////////////////////////////////////=
////
// CDBListCourseware recordset
class CDBListCourseware : public CRecordset
{
public:
CDBListCourseware(CDatabase* pDatabase =3D NULL);
// Field/Param Data
//{{AFX_FIELD(CDBListCourseware, CRecordset)
CString m_Courseware_Name;
CString m_Password;
CString m_Title;
CString m_Language;
int m_TotLessons;
int m_TotLessonsEnable;
int m_TotSection;
int m_TotSectionEnable;
double m_Trigger;
//}}AFX_FIELD
// Implementation
protected:
virtual CString GetDefaultConnect(); // Default connection string
virtual CString GetDefaultSQL(); // Default SQL for Recordset
virtual void DoFieldExchange(CFieldExchange* pFX); // RFX support
DECLARE_DYNAMIC(CDBListCourseware)
};
// dblistco.cpp : implementation file
//
//#include "stdafx.h"
#include "dblistco.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] =3D __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////=
////
// CDBListCourseware
IMPLEMENT_DYNAMIC(CDBListCourseware, CRecordset)
CDBListCourseware::CDBListCourseware(CDatabase* pdb)
: CRecordset(pdb)
{
//{{AFX_FIELD_INIT(CDBListCourseware)
m_Courseware_Name =3D "";
m_Password =3D "";
m_Title =3D "";
m_Language =3D "";
m_TotLessons =3D 0;
m_TotLessonsEnable =3D 0;
m_TotSection =3D 0;
m_TotSectionEnable =3D 0;
m_Trigger =3D 0;
m_nFields =3D 9;
//}}AFX_FIELD_INIT
}
CString CDBListCourseware::GetDefaultConnect()
{
return "ODBC;DSN=3DScript;";
}
CString CDBListCourseware::GetDefaultSQL()
{
return "ListCourseware";
}
void CDBListCourseware::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CDBListCourseware)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, "Courseware_Name", m_Courseware_Name);
RFX_Text(pFX, "Password", m_Password);
RFX_Text(pFX, "Title", m_Title);
RFX_Text(pFX, "Language", m_Language);
RFX_Int(pFX, "TotLessons", m_TotLessons);
RFX_Int(pFX, "TotLessonsEnable", m_TotLessonsEnable);
RFX_Int(pFX, "TotSection", m_TotSection);
RFX_Int(pFX, "TotSectionEnable", m_TotSectionEnable);
RFX_Double(pFX, "Trigger", m_Trigger);
//}}AFX_FIELD_MAP
}
Dip. Ing. Fabio Saponaro
Email: fabio@csg.it
Context Systems Group - Italian branch:
P.za Liberazione 25
20013 Magenta (MI)
Italia
Tel. ++39-2-97298145
Fax. ++39-2-97298225
Ian Pepper -- Ian@flexicom.ie
Monday, January 27, 1997
Hi Fabio,
If I understand you correctly it appears that you are not including the
.cpp files as part of the DLL project.
Ian
ian@flexicom.ie
>
| Вернуться в корень Архива
|