linking errors

This is a discussion on linking errors within the Windows Programming forums, part of the Platform Specific Boards category; Hi, i get the following linking errors... I have read the about the errors in MSDN, but i cannot find ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    19

    linking errors

    Hi,
    i get the following linking errors... I have read the about the errors in MSDN, but i cannot find anything useful... Can somebody help/guide me?

    Code:
    ------ Rebuild All started: Project: MifareRWReader, Configuration: Debug Win32 ------
    
    Deleting intermediate files and output files for project 'MifareRWReader', configuration 'Debug|Win32'.
    Compiling...
    StdAfx.cpp
     WINVER not defined. Defaulting to 0x0501 (Windows XP and Windows .NET Server)
    Reader.cpp
    c:\documents and settings\kostas\τα έγγραφά μου\visual studio projects\mifarerwreader\reader.cpp(153) : warning C4183: 'readAndBroadcastID': missing return type; assumed to be a member function returning 'int'
    Generating Code...
    Linking...
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in msvcprtd.lib(newop_s.obj)
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in MSVCRTD.lib(MSVCR71D.dll)
    nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
    nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
    nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
    nafxcwd.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
    nafxcwd.lib(viewedit.obj) : error LNK2019: unresolved external symbol __mbctype referenced in function "protected: long __thiscall CEditView::OnFindReplaceCmd(unsigned int,long)" (?OnFindReplaceCmd@CEditView@@IAEJIJ@Z)
    Debug/reader.exe : fatal error LNK1120: 3 unresolved externals
    
    Build log was saved at "file://c:\Documents and Settings\kostas\Τα έγγραφά μου\Visual Studio Projects\MifareRWReader\Debug\BuildLog.htm"
    MifareRWReader - 8 error(s), 1 warning(s)
    
    
    ---------------------- Done ----------------------
    
        Rebuild All: 0 succeeded, 1 failed, 0 skipped
    The following program checks for the existence of a smart card and reads from it...
    A thread handles all this procedure.

    Reader.cpp
    Code:
    #include "Thread.h"
    #include <atlstr.h>
    #include <iostream>
    
    #define MIFARE_KEYLEN 6
    #define MIFARE_KEYNR 0
    #define MIFARE_BLOCKNR 4
    #define MIFARE_BUFLEN 16
    
    #include <winscard.h>
    
    extern "C"{
    #include <ok.h>
    #include <scardcl.h>
    }
    
    using namespace std;
    
    // define a threadable object
    class CReader : public IRunnable 
    {
    	public:
    		CReader() 
    	{
    		_continue = true;
    		hSHandle = 0x00000000; //initialize card handle
    		hSContext = 0x00000000; //initialize reader context
    		CString cs="OMNIKEY CardMan 5x21-CL 0";
    		//set the name of the reader
    		sReaderState.szReader = strdup(cs); 
    		//current state of the reader as seen by the app
    		sReaderState.dwCurrentState = SCARD_STATE_EMPTY;
    		//current state of the reader as seen by the resource manager
    		sReaderState.dwEventState = SCARD_STATE_EMPTY;
    
    		if (SCARD_S_SUCCESS != SCardEstablishContext(SCARD_SCOPE_USER,NULL,NULL,&hSContext)) 
    		{
    			cerr << "failed to establish context to reader... exited" <<endl;
    			exit(-1);
    		}	
    	}//CReader
    
    
    	public:
    		unsigned long run() 
    	{
    		while (true)
    		{
    			Sleep(500);
    			//if the state of the card has changed
    			if (SCARD_S_SUCCESS==SCardGetStatusChange(hSContext,INFINITE,&sReaderState,1))
    			{
    				//and a card seems to be now present
    				if (sReaderState.dwEventState & SCARD_STATE_PRESENT)
    				{
    					//connect to card
    					//
    					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);
    					}
    
    
    					//and authenticate
    					//
    					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);
    					}
    
    					readAndBroadcastID();
    				}//is_card_present?
    				else
    				{
    
    					if (SCARD_S_SUCCESS != SCardDisconnect(hSHandle,SCARD_LEAVE_CARD))
    					{
    						cerr << "failed to diconnect card..." << endl;
    					}
    				}//is_card_absent
    
    			}//state_changed?
    		}//while(true)
    
    		return 0;
    	}
    
    	public:
    		void stop() 
    	{
    		_continue = false;
    	}
    	
    	protected:
    		bool _continue;		
    
    	private:
    		readAndBroadcastID()
    	{
    		LONG m_longBlockNr=MIFARE_BLOCKNR;
    		UCHAR ucMifareDataRead[16];
    		ULONG ulMifareNumOfDataRead;
    		BOOL everythingOK=true;
    
    		if (NO_ERROR!=SCardCLMifareStdRead(hSHandle,m_longBlockNr,
    			ucMifareDataRead,16,&ulMifareNumOfDataRead))
    		{
    			cerr <<"failed to read data from card... exited"<<endl;
    			exit(-1);
    		}
    
    		//char* str=new char[16];
    		//UcharToStr(ucMifareDataRead,MIFARE_BUFLEN,str);
    
    		//CNDKClient clientConnection=new CNDKClient();
    		//BOOL conSuccess;
    		//conSuccess=clientConnection.OpenConnection((CString)SERVER_IP,(long)PORT);
    		//if (conSuccess==FALSE) {
    		//	cerr << "Failed to open connection... retry or abort" << endl;
    		//	everythingOK=false;
    		//}
    
    
    		//CNDKMessage msg=new CNDKMessage();
    		//for (int i=0; i<16; i++) {
    		//	CNDKMessage.Add(ucMifareDataRead[i]);
    		//}
    
    		//BOOL msgSuccess;
    		//msgSuccess=clientConnection.SendMessageToServer(CNDKMessage& message);
    		//if (msgSuccess==FALSE) {
    		//	cerr << "Failed to send message... retry or abort" << endl;
    		//	everythingOK=false;
    		//}
    
    		//if (everythingOK=true) {
    		//	cerr <<"ID has been broadcasted successfully"<< endl;
    		//}
    	}//readAndBroadcastID
    
    	private:
    		SCARD_READERSTATE sReaderState; //structure storing readers and data being monitored
    		SCARDHANDLE hSHandle;
    		SCARDCONTEXT hSContext;
    
    	public:
    		~CReader()
    	{
    		if (SCARD_S_SUCCESS!= SCardReleaseContext(hSContext))
    		{
    			cerr << "failed to release context from reader... exited" << endl;
    			exit(-1);
    		}
    	}//~CReader
    };
    
    void main(int argc,char* argv[])
    {
    	CReader *obj=0;
    	Thread *thread=0;
    	try {
    		// create the threadable object first
    		obj = new CReader();
    
    		// create and start the thread the thread
    		thread = new Thread(obj);
    		thread->start();
    	} 
    	catch (ThreadException &e)
    	{
    		printf(e.Message.c_str());	
    	}
    
    	//delete obj;
    	//delete thread;
    }//main
    Thread.h
    Code:
    #ifndef __THREAD_H__
    #define __THREAD_H__
    /////////////////////////////////////////////////////////////////////////////////
    #include "Windows.h"
    #include <string>
    
    struct IRunnable {
    	virtual unsigned long run() = 0;
    	virtual void stop() = 0;
    };
    
    class ThreadException {
    public:
    	ThreadException(DWORD lastError) {
    		HLOCAL msgBuffer;
    		::FormatMessage(
    			FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
    			0, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    			(LPSTR)&msgBuffer, 0,	NULL);
    		Message = (LPSTR)msgBuffer;
    		::LocalFree(msgBuffer);
    	}
    
    	ThreadException(const std::string &msg) { Message = msg; }
    	std::string Message;
    };
    
    class Thread {
    public:
        Thread(IRunnable *ptr=0) {
    		_runnable = ptr;
    		_started = false;
    		_threadHandle = 0;
    	}
    
    	~Thread() {
    		if(_threadHandle != 0)
    			::CloseHandle(_threadHandle);
    	}
    
    	void start(IRunnable *ptr=0) {
    		if(_started)
    			throw ThreadException("Thread already started.");
    
    		if(!_started && _threadHandle != 0)
    			::CloseHandle(_threadHandle);
    
    		if(ptr != 0)
    			_runnable = ptr;
    
    		if(_runnable == 0)
    			throw ThreadException("An object implementing the IRunnable interface required.");
    
    
    		DWORD threadID=0;
    		_threadHandle = ::CreateThread(0, 0, ThreadProc, this, 0, &threadID);
    		if(_threadHandle == 0)
    			throw ThreadException(::GetLastError());
    
    		::Sleep(0);
    	}
    
    	void stop() {
    		checkAlive();
    		_runnable->stop();
    	}
    
        void suspend() {
    		checkAlive();
    		checkThreadHandle();
    		if(::SuspendThread(_threadHandle) == -1)
     		    throw ThreadException(::GetLastError());
        }
    
        void resume() {
    		checkAlive();
    		checkThreadHandle();
    		if(::ResumeThread(_threadHandle) == -1)
     		    throw ThreadException(::GetLastError());
        }
    
    	void join(unsigned long timeOut=INFINITE) {
    		checkThreadHandle();
    		if(isAlive()) {
    			DWORD waitResult = ::WaitForSingleObject(_threadHandle, timeOut);
    			if(waitResult == WAIT_FAILED)
    				throw ThreadException(::GetLastError());
    		}
    	}
    
        bool isAlive() { return _started; }
    
    protected:
    
    	bool _started;
    	HANDLE _threadHandle;
    	IRunnable *_runnable;
    
    	unsigned long run() {
    		_started = true;
            unsigned long threadExitCode = _runnable->run();
    		_started = false;
    		return threadExitCode;
    	}
    
    	void checkThreadHandle() {
    		if(_threadHandle == 0)
    			throw ThreadException("Thread not yet created, call the start() method.");
    	}
    	void checkAlive() {
    		if(!isAlive())
    			throw ThreadException("No Thread alive.");
    	}
    
    	static unsigned long __stdcall ThreadProc(void* ptr) {
    		return ((Thread *)ptr)->run();
    	}
    };
    
    ///////////////////////////////////////////////////////////////////////////////
    #endif // __THREAD_H__
    Last edited by nocturna_gr; 12-15-2007 at 07:15 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Here's one thing I found:
    http://support.microsoft.com/kb/85514
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking errors
    By Zeeshan in forum C++ Programming
    Replies: 1
    Last Post: 02-22-2009, 01:10 AM
  2. unresolved external symbols...linking errors in VC++
    By rammohan2b in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2009, 01:19 AM
  3. HELP!!Why and How to solve this linking errors.
    By huwan in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 06:30 AM
  4. Replies: 8
    Last Post: 04-27-2006, 10:39 AM
  5. Linking Errors
    By ForlornOdium in forum C++ Programming
    Replies: 1
    Last Post: 12-07-2003, 09:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21