473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems with afxdb.h

Tim
Hi,
I am writing a console app in C++ that is going to be
communicating with an MS SQL Server Database. I was going
to use ODBC to do this and read that I need to include the
afxdb.h header. When I do this, I get the following
linker errors:

nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl
operator new(unsigned int)" (??2@YAPAXI@Z) already defined
in libcpd.lib(newop.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
LIBCD.lib(dbgdel.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete[](void *)" (??_V@YAXPAX@Z) already defined
in LIBCD.lib(delete2.obj)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __endthreadex referenced in function "void
__stdcall AfxEndThread(unsigned int,int)" (?
AfxEndThread@@YGXIH@Z)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __beginthreadex referenced in
function "public: int __thiscall CWinThread::CreateThread
(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES
*)" (?
CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIB UTES@@@Z)

Currently that is the only library being included, am I
supposed to include anything else? Or is there something
better to use than ODBC?

Thanks,
Tim
Nov 16 '05 #1
2 5019
Nevermind, I found that I had not set the application up
to support MFC.
-----Original Message-----
Hi,
I am writing a console app in C++ that is going to be
communicating with an MS SQL Server Database. I was goingto use ODBC to do this and read that I need to include theafxdb.h header. When I do this, I get the following
linker errors:

nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl
operator new(unsigned int)" (??2@YAPAXI@Z) already definedin libcpd.lib(newop.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined inLIBCD.lib(dbgdel.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete[](void *)" (??_V@YAXPAX@Z) already definedin LIBCD.lib(delete2.obj)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __endthreadex referenced in function "void__stdcall AfxEndThread(unsigned int,int)" (?
AfxEndThread@@YGXIH@Z)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __beginthreadex referenced in
function "public: int __thiscall CWinThread::CreateThread
(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES
*)" (?
CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRI BUTES@@@Z )
Currently that is the only library being included, am I
supposed to include anything else? Or is there something
better to use than ODBC?

Thanks,
Tim
.

Nov 16 '05 #2
Tim,

to use the MFC ODBC classes in a console app, you must first initialize
MFC -- that means instantiating a CWinApp object, then calling AfxWinInit...
For that, you will need quite a bit more than just afxdb.h. Here is a code
hack - the stdafx.h and minimal console app with MFC support to instantiate
the CDatabase and CRecordset objects.

/*
** stdafx.h : include file for standard system include files.
*/

#pragma once
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <iostream>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#include <afx.h>
#include <afxwin.h>
#include <afxext.h>
#include <afxdb.h>

/*
** console.cpp : Defines the entry point for the console application.
*/

#include "stdafx.h"
#include "console.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using namespace std;
/* The one and only application object */
CWinApp theApp;
CString strDSN("DSN=OraDevl;UID=RLFINE;PWD=EIEIO;");
DWORD dbOpenFlags = CDatabase::openReadOnly|CDatabase::noOdbcDialog;
CDatabase *oraODBC_DB;

/* ************************************************** ** */
/* ************************************************** ** */
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
oraODBC_DB = new CDatabase;
oraODBC_DB->OpenEx(strDSN,dbOpenFlags);
{
CRecordset rs(oraODBC_DB);
/* .... */
/* .... */
rs.Close();
}
delete oraODBC_DB;
return 0;
}
/* ********* end o-hack ************ */

For the second part of your post, you could use ADO instead of the MFC ODBC
classes -- my personal preference is ADO because I don't like the hassles of
maintaining the ODBC Data Source. Instead of afxdb, you would use the
#import compiler directive to construct a set of helper classes from the ADO
typelib. Here is a link to get you started:
http://msdn.microsoft.com/library/de...us/ado270/htm/
pg_ado_programming_8.asp
regards
roy fine
"Tim" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
Hi,
I am writing a console app in C++ that is going to be
communicating with an MS SQL Server Database. I was going
to use ODBC to do this and read that I need to include the
afxdb.h header. When I do this, I get the following
linker errors:

nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl
operator new(unsigned int)" (??2@YAPAXI@Z) already defined
in libcpd.lib(newop.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete(void *)" (??3@YAXPAX@Z) already defined in
LIBCD.lib(dbgdel.obj)
nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl
operator delete[](void *)" (??_V@YAXPAX@Z) already defined
in LIBCD.lib(delete2.obj)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __endthreadex referenced in function "void
__stdcall AfxEndThread(unsigned int,int)" (?
AfxEndThread@@YGXIH@Z)
nafxcwd.lib(thrdcore.obj) : error LNK2019: unresolved
external symbol __beginthreadex referenced in
function "public: int __thiscall CWinThread::CreateThread
(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES
*)" (?
CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIB UTES@@@Z)

Currently that is the only library being included, am I
supposed to include anything else? Or is there something
better to use than ODBC?

Thanks,
Tim

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jerome Lefebvre | last post by:
Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ ....
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
2
by: Ellen Graves | last post by:
I am having a lot of problems with DB2 8.3.1 on RH Linux AS2.1. Installing and running stored procedures is problematic. Stored procedures I have used for years on V7 on WinNT are now failing...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.