访问winscard.dll的python脚本

时间:2013-01-04 06:02:41

标签: python pointers ctypes loadlibrary winscard

大家好我正在写一个python脚本来访问windows的winscard.dll。

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

这种情况下的值错误表示参数错误。但我不知道还有什么可以作为输入来使它工作,我尝试了几种输入组合。

谢谢大家。

1 个答案:

答案 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

P.S。确保Smart Card服务已启动。否则你会得到一个神秘的错误代码。

相关问题