2013-01-04 126 views
1

大家好我正在編寫一個python腳本來訪問winscard.dll的windows。訪問winscard.dll的python腳本

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

上述返回一個錯誤值如下

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 

在這種情況下的誤差值表示所述參數是錯誤的。但我不知道還有什麼可以作爲輸入來使它工作,我嘗試了幾種輸入組合。

謝謝大家。

+0

我不知道這個原因。但[本](http://stackoverflow.com/questions/1458813/python-ctypes-and-not-enough-arguments-4-bytes-missing)和[this](http://stackoverflow.com/questions/ 5267434/python-ctypes-argument-errors)可能對你有些用處。希望能幫助到你。 –

+0

非常希望看到這個工作... –

回答

0

您正在使用錯誤的調用約定的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 

附:確保Smart Card服務已啓動。否則,你會得到一個神祕的錯誤代碼。