0

I tried to write a console application to read smart card in C ,

#include <stdio.h>
#include <winscard.h>
#include <SCardErr.h>

#ifndef SCARD_E_NO_READERS_AVAILABLE
#define SCARD_E_NO_READERS_AVAILABLE ((DWORD)0x8010002E)
#endif

SCARD_IO_REQUEST pciT0 = {1, 8};

int main(void)
{
        SCARDCONTEXT hSC;
        SCARDHANDLE hCard;
        char RxBuffer[256];
        char TxBuffer[64];
        char ReaderName[64];
        int retval, dCount, i, dProtocol, dLength, FileNum;
        int split_offset, split_length;
        FILE *outfile, *out2file;

        retval = SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, &hSC);
        if (retval == SCARD_E_NO_SERVICE) {
                printf("Smart card service not started\n");
                goto _Quit;
        }
        else if (retval != 0) {
                printf("SCardEstablishContext Error: %x\n", retval);
                goto _Quit;
        }

_Quit:
        printf("Press enter to exit the program\n");
        getchar();

        return 0;
}

But when I try to run/Local Windows Debugger in Visual Studio Express 2012 I got this error

Error 1 error LNK2019: unresolved external symbol _SCardEstablishContext@16 referenced in function _main

clover1234
  • 140
  • 2
  • 13
  • 5
    Are you linking with `Winscard.lib`, as suggested by [the fine manual](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379479.aspx)? – Igor Tandetnik Sep 20 '15 at 15:15
  • 1
    Seems you forgot to update the linker additional input libraries (Project properties->Linker->Input) or Additional Library Directories (Project Props->Linker->General) – Anorflame Sep 20 '15 at 15:39
  • the visual studio needs to be told to include the Winscard.lib and/or Winscard.dll files in the link – user3629249 Sep 20 '15 at 15:55
  • BTW: the second and third parameters to the SCardEstablishContext() should be NULL, not 0 – user3629249 Sep 20 '15 at 15:57
  • 3
    possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Captain Obvlious Sep 20 '15 at 17:02

0 Answers0