Hi,
i compile my program and get the following linker errors... As far as i can understand, they have to do with the outputstream -i have defined "iostream" OK i think. What's wrong?
Code:
------ Rebuild All started: Project: MifareRW4, Configuration: Debug Win32 ------
Deleting intermediate files and output files for project 'MifareRW4', configuration 'Debug|Win32'.
Compiling...
stdafx.cpp
WINVER not defined. Defaulting to 0x0501 (Windows XP and Windows .NET Server)
IDAdmin.cpp
WINVER not defined. Defaulting to 0x0501 (Windows XP and Windows .NET Server)
c:\documents and settings\kostas\τα έγγραφά μου\visual studio projects\cardmanager\libs\mysql++\include\exceptions.h(44) : warning C4275: non dll-interface class 'exception' used as base for dll-interface class 'mysqlpp::Exception'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\exception(39) : see declaration of 'exception'
c:\documents and settings\kostas\τα έγγραφά μου\visual studio projects\cardmanager\libs\mysql++\include\exceptions.h(43) : see declaration of 'mysqlpp::Exception'
c:\documents and settings\kostas\τα έγγραφά μου\visual studio projects\cardmanager\libs\mysql++\include\query.h(131) : warning C4275: non dll-interface class 'std::ios_base' used as base for dll-interface class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xiosbase(181) : see declaration of 'std::ios_base'
Generating Code...
c:\documents and settings\kostas\Ϊά ▌ήή±ά÷▄ ΉΎΫ\visual studio projects\cardmanager\idadmin.cpp(153) : warning C4715: 'CIDAdmin::UpdateDB' : not all control paths return a value
Compiling resources...
Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libcpmtd.lib(newop.obj)
IDAdmin.obj : warning LNK4217: locally defined symbol ?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z (public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)) imported in function __catch$??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z$0
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) referenced in function "public: __thiscall CIDAdmin::CIDAdmin(void)" (??0CIDAdmin@@QAE@XZ)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (__imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::put(char)" (__imp_?put@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@D@Z) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (__imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (__imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" (??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z)
IDAdmin.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" (??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ)
Debug/idadmin.exe : fatal error LNK1120: 7 unresolved externals
Build log was saved at "file://c:\Documents and Settings\kostas\Τα έγγραφά μου\Visual Studio Projects\CardManager\Debug\BuildLog.htm"
MifareRW4 - 9 error(s), 4 warning(s)
---------------------- Done ----------------------
Rebuild All: 0 succeeded, 1 failed, 0 skipped
stdafx.h
Code:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include <iostream>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
// TODO: reference additional headers your program requires here
IDAdmin.h
Code:
#define MIFARE_KEYLEN 6
#define MIFARE_KEYNR 0
#define MIFARE_BLOCKNR 4
#define MIFARE_BUFLEN 16
//#include <iostream>
#include <fstream>
#include <string>
#include <winscard.h>
#include "resource.h"
extern "C"{
#include <ok.h>
#include <scardcl.h>
}
#include "mysql++.h"
#include <iostream>
using namespace std;
class CIDAdmin
{
public:
CIDAdmin();
~CIDAdmin();
//writes the new id to card and the (id,full_name)
//tuple to a file
void enlistNew(char* cid, CString* surname,CString* name);
//reads the id, that already exists in the card;
//will be "000...0" if none has been assigned yet
void readExistingFromCard();
private:
SCARDHANDLE hSHandle;
SCARDCONTEXT hSContext;
////reads a (id,full_name) tuple directly from
////command-line
//string getNewEntryFromUser();
void CStrToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen);
//void StrToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen);
void UcharToStr(UCHAR *ucDataBuffer, ULONG ulDataBufLen, char *str);
bool UpdateDB(char* cid,CString* surname,CString* name);
//static void dprint(string s);
};
IDAdmin.cpp
Code:
#include "stdafx.h"
#include "IDAdmin.h"
CWinApp theApp;
using namespace std;
CIDAdmin::CIDAdmin()
{
hSHandle = 0x00000000;
hSContext = 0x00000000;
if (SCARD_S_SUCCESS != SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&hSContext))
{
cerr << "failed to establish context to reader... exited" <<endl;
exit(-1);
}
DWORD dwAP;
if (SCARD_S_SUCCESS != SCardConnect(hSContext, (LPCTSTR)"OMNIKEY CardMan 5x21-CL 0",
SCARD_SHARE_SHARED,SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
&hSHandle,&dwAP ))
{
cerr << "failed to connect to card..." << endl <<
"check the card has been detected by the CL interface! exited" <<endl;
exit(-1);
}
UCHAR ucMifareAuthMode=MIFARE_AUTHENT1A;
UCHAR ucMifareKey[6]={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
ULONG ulMifareKeyLen = MIFARE_KEYLEN;
UCHAR ucMifareAccessType=MIFARE_KEY_INPUT;
UCHAR ucMifareKeyNr=MIFARE_KEYNR;
LONG m_longBlockNr=MIFARE_BLOCKNR;
if (NO_ERROR != SCardCLMifareStdAuthent(hSHandle,m_longBlockNr,ucMifareAuthMode,
ucMifareAccessType,ucMifareKeyNr,ucMifareKey, ulMifareKeyLen))
{
cerr << "failed to authenticate... exited" << endl;
exit(-1);
}
}//CIDAdmin
void CIDAdmin::readExistingFromCard()
{
LONG m_longBlockNr=MIFARE_BLOCKNR;
UCHAR ucMifareDataRead[16];
ULONG ulMifareNumOfDataRead;
if (NO_ERROR!=SCardCLMifareStdRead(hSHandle,m_longBlockNr,
ucMifareDataRead,16,&ulMifareNumOfDataRead))
{
cerr <<"failed to read data from card... exited"<<endl;
exit(-1);
}
for (int i=0; i<MIFARE_BUFLEN; i++)
{
if (ucMifareDataRead[i]!=0)
cout <<ucMifareDataRead[i];
}
cout << endl;
}//readExistingFromCard
void CIDAdmin::enlistNew(char* cid, CString* surname,CString* name)
{
UCHAR ucDataToWrite[MIFARE_BUFLEN];
ULONG ulBufferLen = MIFARE_BUFLEN;
for (int i=0; i<MIFARE_BUFLEN; i++)
{
ucDataToWrite[i]=(UCHAR)cid[i];
}
if (NO_ERROR!=SCardCLMifareStdWrite(hSHandle,(LONG)MIFARE_BLOCKNR,ucDataToWrite,ulBufferLen))
{
cerr << "failed to write to card" << endl;
}
else //if successful update of ID in card, update db
{
UpdateDB(cid,surname,name);
}
cout << "ID has been written successfully" << endl;
}//enlistNew
CIDAdmin::~CIDAdmin()
{
if (SCARD_S_SUCCESS != SCardDisconnect(hSHandle,SCARD_LEAVE_CARD))
{
cerr << "failed to diconnect card..." << endl;
}
if (SCARD_S_SUCCESS!= SCardReleaseContext(hSContext))
{
cerr << "failed to release context from reader... exited" << endl;
exit(-1);
}
}//~CIDAdmin
bool CIDAdmin::UpdateDB(char* cid,CString* surname,CString* name)
{
bool bCon;
CString m_errorInfo;
mysqlpp::Connection m_Connection;
try
{
bCon = m_Connection.connect("humabio","localhost","root","123",3306);
if(bCon)
{
//cout <<"Succesfully connected to the database" << endl;
mysqlpp::Query query = m_Connection.query();
CString sUpdate="INSERT INTO persons (";
sUpdate.Append(cid);
sUpdate.Append(",\"");
sUpdate.Append(*surname);
sUpdate.Append("\"\,\"");
sUpdate.Append(*name);
sUpdate.Append("\"\)");
query << sUpdate;
return true;
}
return false;
}
catch(mysqlpp::ConnectionFailed cf)
{
m_errorInfo = cf.what();
cerr << "Connection to the database failed" << endl;
//TRACE("%s \n",cf.what());
cerr << cf.what() << endl;
}
catch(mysqlpp::Exception ex)
{
m_errorInfo = ex.what();
cerr << "Generic exception in Mysql Database" << endl;
//TRACE("%s \n",ex.what());
cerr << ex.what() << endl;
}
}//UpdateDB
////////////////////////////////HELPERS/////////////////////////////////////
void CIDAdmin::UcharToStr(UCHAR *ucDataBuffer, ULONG ulDataBufLen, char *str)
{
ULONG i = 0;
char bytetochar[3] ="";
char Temp[1024] ="";
for (i=0;i<ulDataBufLen;i++)
{
_itoa(ucDataBuffer[i],bytetochar,16);
if (ucDataBuffer[i]<=0x0F)strcat(Temp,"0");
strcat(Temp,bytetochar);
}
memcpy(str,Temp,ulDataBufLen*2);
str[ulDataBufLen*2] = 0;
}//UcharToStr
//void CIDAdmin::dprint(string s)
//{
// cerr << s << endl;
//}//dprint
////////////////////////////////HELPERS/////////////////////////////////////
//void main(int argc,char* argv[])
//{
// string sUsage="Usage: idadmin read\n or\n iadmin write value";
// string param;
// param=argv[1];
//
// if (param.compare("write")==0)
// {
// if (argc!=5) {
// cerr << sUsage << endl;
// }
//
// CIDAdmin* admin=new CIDAdmin();
// char* id=argv[2];
// CString surname=argv[3];
// CString name=argv[4];
// admin->enlistNew(id,&surname,&name);
// }
// else if (param.compare("read")==0)
// {
// CIDAdmin* admin=new CIDAdmin();
// admin->readExistingFromCard();
// }
// else
// {
// cerr<< sUsage << endl;
// }
//}//main
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
CString sUsage="Usage: idadmin read\n or\n iadmin write value";
CString param;
param=argv[1];
if (param.Compare("write")==0)
{
if (argc!=5) {
cerr << sUsage << endl;
}
CIDAdmin* admin=new CIDAdmin();
char* id=argv[2];
CString surname=argv[3];
CString name=argv[4];
admin->enlistNew(id,&surname,&name);
}
else if (param.Compare("read")==0)
{
CIDAdmin* admin=new CIDAdmin();
admin->readExistingFromCard();
}
else
{
cerr<< sUsage << endl;
}
}
return nRetCode;
}