2013-01-04 80 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服务已启动。否则,你会得到一个神秘的错误代码。