locked
LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup RRS feed

  • Question

  • Hi,

    i am getting this error while linking. I am a newbie, so the only thing i know is that the function of a library points to WinMain. My program is CLI based and i do not want to use any GUI (WinMain)....

    Any advice?

    Thanks

     

    [code]

    ------ Rebuild All started: Project: MifareRW5, Configuration: Debug Win32 ------

    Deleting intermediate and output files for project 'MifareRW5', configuration 'Debug|Win32'

    Compiling...

    StdAfx.cpp

    Main.cpp

    IDAdministrator.cpp

    Generating Code...

    Compiling manifest to resources...

    Linking...

    LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

    C:\Documents and Settings\kostas\Τα έγγραφά μου\Visual Studio 2005\Projects\MifareRW5\Debug\MifareRW5.exe : fatal error LNK1120: 1 unresolved externals

    Build log was saved at "file://c:\Documents and Settings\kostas\Τα έγγραφά μου\Visual Studio 2005\Projects\MifareRW5\MifareRW5\Debug\BuildLog.htm"

    MifareRW5 - 2 error(s), 0 warning(s)

    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

    [/code]
    Saturday, December 1, 2007 5:38 PM

Answers

  • Just change "Project | Properties | Configuration Properties | Linker | System | Subsystem" from "Windows (/SUBSYSTEM:WINDOWS)" to "Console (/SUBSYSTEM:CONSOLE)", and switch off /clr from "Project | Properties | Configuration Properties | General | Common Language Support", since I don't see any managed code in your project, so you don't need it.

     

    hope it helps

    rico

    Thursday, December 6, 2007 10:17 AM

All replies

  • Please provide the source codes of your "Main.cpp" file for further investigation.

     

    Sunday, December 2, 2007 8:11 AM
  •  

    I am newcomer in VC++, so my code may be difficult to read. Thanks for the help

     

     

     

    Main.cpp

    Code Block

    #include "stdafx.h"

    #include "IDAdministrator.h"

    #include

    using namespace std;

    void main(int argc,char* argv[])

    {

    cout << "Launching the utility\n";

    CIDAdministrator* idadmin=new CIDAdministrator();

    //UCHAR* car;

    //int UIDsize=10;

    //idadmin->getUID(car,UIDsize);

    //cout<<"Card UID: "<< car << endl;

    //idadmin->writeID();

    }

     

     

     

     

    StdAfx.h

    Code Block

    #if _MSC_VER > 1000

    #pragma once

    #define _CRT_SECURE_NO_DEPRECATE 1 //override CRT security warnings

    #define _CRT_NONSTDC_NO_DEPRECATE 1 //override CRT security warnings

    #endif // _MSC_VER > 1000

    #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers

    //#include // MFC core and standard components

    //#include // MFC extensions

    //#include // MFC support for Internet Explorer 4 Common Controls

    //#ifndef _AFX_NO_AFXCMN_SUPPORT

    //template class __declspec(dllimport) CStringT>>;

    //template class __declspec(dllimport) CSimpleStringT;

    //#include // MFC support for Windows Common Controls

    //#endif // _AFX_NO_AFXCMN_SUPPORT

    //{{AFX_INSERT_LOCATION}}

    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.

    #include

    extern "C"{

    //#include "C:\Omnikey\Include\ok.h"

    //#include "C:\Omnikey\Include\scardcl.h"

    #include

    #include

    }

     

     

     

     

    StdAfx.cpp

    Code Block
    #include
    "stdafx.h"

     

     

     

     

    IDAdministrator.h:

    Code Block

    #if _MSC_VER > 1000

    #pragma once

    #endif // _MSC_VER > 1000

    #include "winscard.h"

    #include "scarderr.h"

    #include "atlstr.h" //for CSstring; can be used for non_MFC projects

    #include

     

    class CIDAdministrator

    {

    public:

    CIDAdministrator();

    ~CIDAdministrator();

    static UINT StartCardThread(LPVOID param); //controlling function header

    typedef struct THREADSTRUCT //structure for passing to the controlling function

    {

    CIDAdministrator* _this;

    } THREADSTRUCT;

    private:

    SCARDCONTEXT hContext;

    SCARDHANDLE hCard ;

    BOOLEAN fCM5x21Selected;

    BOOLEAN fCardConnected;

    CString m_strReaderName;

    long m_longBlockNr;

    ULONG ulUIDBufLen;

    CString m_strAuthentKey;

    int m_intAuthentMode;

    int m_intAccessOption;

    UCHAR ucATR[64];

    ULONG ulATRLen;

    CString m_strMifAuthentKeyNr;

    CString m_strDataRead;

    CString m_strDataToWrite;

    CString m_strIncrementValue;

    CString m_strDecrementValue;

    CString m_strOutPutList;

    DWORD m_dwNByteSend;

    CString m_strByteSend;

    CString m_strByteReceive;

    DWORD m_dwNByteReceive;;

    int m_intMifKeyEnOption;

    CString m_strMifKeyNrToWrite;

    CString m_strMifKeyToWrite;

    CString m_strMifEnKeyNr;

    DWORD SCard_Status;

    DWORD dwControlFlags;

    LONG lErr;

    public:

    BOOLEAN init();

    void authenticate();

    void emulOn();

    void CStringToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen);

    };

     

     

     

    IDAdministrator.cpp

    Code Block

    #include "stdafx.h"

    #include "IDAdministrator.h"

    #define CM_IOCTL_SET_RFID_CONTROL_FLAGS SCARD_CTL_CODE(3213)

    #define Card_Absent 0x00

    #define Card_Present 0x01

    #define Card_Changed 0x02

    using namespace std;

    CIDAdministrator::CIDAdministrator()

    {

    cerr << "Application started..." << endl;

    m_strReaderName = _T("");

    m_longBlockNr = 0;

    m_strAuthentKey = _T("");

    m_intAuthentMode = -1;

    m_intAccessOption = -1;

    m_strMifAuthentKeyNr = _T("");

    m_strDataRead = _T("");

    m_strDataToWrite = _T("");

    m_strIncrementValue = _T("");

    m_strDecrementValue = _T("");

    m_strOutPutList = _T("");

    m_dwNByteSend = 0;

    m_strByteSend = _T("");

    m_strByteReceive = _T("");

    m_dwNByteReceive = 0;

    m_intMifKeyEnOption = -1;

    m_strMifKeyNrToWrite = _T("");

    m_strMifKeyToWrite = _T("");

    m_strMifEnKeyNr = _T("");

    init(); //must be called first; before turning emul on

    emulOn();

    //establishContext();

    //getReaderList();

    //connect();

    //turnMifareEmuOn();

    //UCHAR ucKey=0x121212;

    //LoadKey(UCHAR ucKeyNr,UCHAR *ucKey,UCHAR ucKeyLength)

    //LoadKey(0x1A,&ucKey,sizeof(ucKey));

    //Authenticate(UCHAR BlockNr,UCHAR ucKeyNr,UCHAR ucKeyType)

    //Authenticate(0x04,0x02,0x60);

    //authenticate block-4 by using keynum-2(keyA) and keytype-A

    }//CIDAdministrator

     

     

    BOOLEAN CIDAdministrator::init()

    {

    DWORD i = 0, z = 0, j =0;

    CHAR mszReaders [1024]; //string list of the available readers

    DWORD dwLength = sizeof(mszReaders); //length

    CHAR szReader [10] [100]; //

    hCard = 0x00000000; //

    hContext = 0x00000000; //card

    fCM5x21Selected = FALSE;

    char str[80] = "";

    ulUIDBufLen = 12;

    fCardConnected = FALSE;

    memset(ucATR,sizeof(ucATR),0);

    ulATRLen = sizeof(ucATR);

    SCard_Status = SCardEstablishContext(

    SCARD_SCOPE_USER,

    NULL,

    NULL,

    &hContext);

    if ( SCard_Status == SCARD_S_SUCCESS)

    {

    for (i=0;i<10;i++)

    {

    memset(&szReader[i][0],0x00,sizeof(&szReader[i][0]));

    }

    SCard_Status = SCardListReaders(hContext,

    NULL,

    mszReaders,

    &dwLength);

    if ( SCard_Status == SCARD_S_SUCCESS)

    {

    if (dwLength > 2) // \0\0

    {

    z=0;

    j=0;

    for (i=0;i<DWLENGTH;I++)< P>

    {

    if (mszReaders[i] == '\0')

    {

    szReader [j] [z] = mszReaders[i];

    z=0;

    j++;

    }

    else

    {

    szReader [j] [z] = mszReaders[i];

    z++;

    }

    }//for the bytes of data returned

    }//if data>2

    //for all reader places

    for (j=0;j < 10;j++)

    {

    if (szReader[j] [0] != 0x00)

    {

    //if you can find the OMNIKEY Reader; select it

    if (strcmp( szReader[j],"OMNIKEY CardMan 5x21-CL 0")==0)

    {

    m_strReaderName = "OMNIKEY CardMan 5x21-CL 0";

    fCM5x21Selected = TRUE;

    }

    }

    }//for

    }

    else

    {

    printf("\nFailed to list readers, error code=0x%04X\n",SCardStatus);

    }

    }

    else

    {

    printf("\nFailed to establish context, error code=0x%04X\n",SCardStatus);

    }

    m_strMifKeyNrToWrite = "00";

    m_intAuthentMode = 0; //mode: use keyA or keyB

    m_intAccessOption = 0;

    m_intMifKeyEnOption = 1;

    m_strMifEnKeyNr = "80";

    //TrackCard();

    return TRUE; // return TRUE unless you set the focus to a control

    }//init

     

    //void IDAdministrator::TrackCard()

    //{

    // THREADSTRUCT *_param = new THREADSTRUCT;

    // _param->_this = this;

    // AfxBeginThread (StartCardThread, _param);

    //}

    /*

    void CIDAdministrator::authenticate()

    {

    UCHAR ucMifareAuthMode=MIFARE_AUTHENT1A;

    //UCHAR ucMifareKey[6] = {0};

    UCHAR ucMifareKey[6] = 0xFFFFFFFFFFFF;

    ULONG ulMifareKeyLen = 6;

    UCHAR ucMifareAccessType=MIFARE_KEY_INPUT;

    UCHAR ucMifareKeyNr;

    DWORD lErr;

    CStringToUchar(m_strAuthentKey,ucMifareKey,&ulMifareKeyLen);

    lErr = SCardCLMifareStdAuthent(hCard,m_longBlockNr,ucMifareAuthMode,

    ucMifareAccessType,ucMifareKeyNr,ucMifareKey, ulMifareKeyLen);

    if (lErr==NO_ERROR)

    {

    ulAuthenticatedBlockNr= m_longBlockNr;

    ShowTimeRequired();

    }

    else

    {

    m_ctrOutput.AddString("Error in Authentication, may be the key is not correct");

    ShowErrorMessage(lErr);

    }

    }//authenticate

    */

     

    /** first call enables; second disables; third enables, etc

    */

    void CIDAdministrator::emulOn()

    {

    BYTE InBuffer[16];

    BYTE OutBuffer[16];

    DWORD dwControlCode = CM_IOCTL_SET_RFID_CONTROL_FLAGS;

    DWORD dwInBufferSize = 8;

    DWORD dwOutBufferSize = 0;

    DWORD dwBytesReturned = 0;

    DWORD *Mask = (DWORD *)InBuffer;

    DWORD *Value = (DWORD *)InBuffer+1;

    CString strButtonTitle;

    CString strDriverState;

    memset(InBuffer, 0x00, sizeof(InBuffer));

    memset(OutBuffer, 0x00, sizeof(OutBuffer));

    dwControlFlags = ~dwControlFlags;

    *Mask = 0x00000004;

    *Value = dwControlFlags & *Mask;

    lErr = SCardControl(hCard,

    dwControlCode,

    (LPCVOID)InBuffer,

    dwInBufferSize,

    (LPVOID)OutBuffer, // The reply from IFD -> driver -> res.manager

    dwOutBufferSize,

    &dwBytesReturned);

    if (lErr == SCARD_S_SUCCESS)

    {

    if (*Value == 0)

    {

    cerr << "Mifare emulation is OFF now" <<ENDL;< P>

    }

    else

    {

    cerr << "Mifare emulation is ON now" <<ENDL;< P>

    }

    }

    else

    {

    cerr << "failed to change the state of the Mifare Emulation" << endl;

    }

    }

    ////////////////////////////////////////////////////////////////////////////////

    //HELPERS///////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////

    void CIDAdministrator::CStringToUchar(CString str, UCHAR *ucBuffer, ULONG *ulBufferLen)

    {

    int Length = 0;

    int DataLength = 0;

    char cstr[] ="";

    char strcstring[512] ="";

    byte hexval=0x00;

    int i = 0;

    Length = str.GetLength();

    for (i = 0; i

    strcstring[i] = str.GetAt(i);

    DataLength = Length / 2;

    for (i = 0; i

    {

    cstr[0] = strcstring[2*i];

    cstr[1] = strcstring[2*i+1];

    sscanf( cstr, "%02x", &hexval );

    ucBuffer[i]=hexval;

    }

    *ulBufferLen = DataLength;

    }//CStringToUchar

     

     

     

     

     

    Sunday, December 2, 2007 10:50 AM
  • When I create a new "CLR Console Application", the generated "main" codes differ from yours...

     

    // 2492036.cpp : main project file.

    #include "stdafx.h"

    using namespace System;

    int main(array<System:Tongue Tiedtring ^> ^args)
    {
        Console::WriteLine(L"Hello World");
        return 0;
    }

    Sunday, December 2, 2007 11:02 AM
  • I do use CLR.... What do you mean?

     

    Sunday, December 2, 2007 12:52 PM
  • Can that -without knowing exactly what- caused by some differenet configuration in out projects/solution?

     

    Sunday, December 2, 2007 12:53 PM
  • ... Please try some different configurations.., then you can verify whether configuration is the cause of the linker error.

     

    BTW, using CLR means that you write managed codes... The signature of the "main" method differs from its unmanaged counterpart. Do you compare the method signature of my "main" with your "main" ?

     

     

    -Jeremy

    Sunday, December 2, 2007 1:05 PM
  • Just change "Project | Properties | Configuration Properties | Linker | System | Subsystem" from "Windows (/SUBSYSTEM:WINDOWS)" to "Console (/SUBSYSTEM:CONSOLE)", and switch off /clr from "Project | Properties | Configuration Properties | General | Common Language Support", since I don't see any managed code in your project, so you don't need it.

     

    hope it helps

    rico

    Thursday, December 6, 2007 10:17 AM
  • brillant !!, that work.

    Thanks

    Just commenting for other ppl that might be facing the same issue
    Monday, November 23, 2009 2:49 PM