1

Hi all i am writing a python script to access the winscard.dll of windows.

lib = cdll.LoadLibrary('winscard.dll')
hSC = c_long(0)
lRetval = lib.SCardEstablishContext(0,None,None,pointer(hSC))

the above returns a value error as below

Traceback (most recent call last):
  File "C:\Documents and Settings\sbritto\Desktop\OpenSSL\python\test.py", 
  line 17, in <module>
    lRetval = lib.SCardEstablishContext(0,None,None,pointer(hSC))
ValueError: Procedure called with not enough arguments (16 bytes missing) or 
wrong calling convention

The value error in this case denotes the arguments are wrong. but i don't know what else to give as input to make it work, I tried several input combinations.

Thank you all.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
Britto
  • 501
  • 1
  • 9
  • 22
  • I don't have a clue as to the cause of this. But [this](http://stackoverflow.com/questions/1458813/python-ctypes-and-not-enough-arguments-4-bytes-missing) and [this](http://stackoverflow.com/questions/5267434/python-ctypes-argument-errors) maybe of some use to you. Hope it helps. – Shyam K Jan 04 '13 at 09:58
  • would very much like to see this working... – Dima Tisnek Mar 18 '13 at 13:56

1 Answers1

0

You are using wrong calling conventions for the DLL:

lib = ctypes.WinDLL("winscard")
handle = ctypes.c_voidp()
lib.SCardEstablishConnection(0, None, None, ctypes.pointer(handle))
# returns 0, all is good
handle
# c_void_p(some address), handle got created

P.S. make sure Smart Card service is started. Otherwise you get a cryptic error code.

Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120