在python中使用dll导出函数
最近在学习py,实践是:校验指定文件是否打上数字签名~python的标准库中没有提供这类函数,同时在网上搜了一下也没有找到第三方的包有提供,最后找到了可以使用Crypt32.dll的导出函数CryptQueryObject()。
首先我希望pywin32的包中最好已封装这样的api,结果发现没有-_-!。于是不得不自己动手~py中调用dll的导出函数方法比较简单:
from ctypes import *
CryptQueryObject=windll.LoadLibrary("Crypt32.dll").CryptQueryObject
可是接下来问题来了。。CryptQueryObject中的参数怎么处理。。
BOOL WINAPI CryptQueryObject(
__in DWORD dwObjectType,
__in const void* pvObject,
__in DWORD dwExpectedContentTypeFlags,
__in DWORD dwExpectedFormatTypeFlags,
__in DWORD dwFlags,
__out DWORD* pdwMsgAndCertEncodingType,
__out DWORD* pdwContentType,
__out DWORD* pdwFormatType,
__out HCERTSTORE* phCertStore,
__out HCRYPTMSG* phMsg,
__out const void** ppvContext
);
参数类型中有数字,指针,宏定义。py中对于参数没有这么丰富的定义,同时也没有宏定义,于是需要转换成py能认识的,这又要使用ctypes了,google到这张表,并将宏定义换成数值:结果如下
bResult=CryptQueryObject(1,\
c_wchar_p(path),\
1024,\
2,\
0,\
None,\
None,\
None,\
None,\
&n
相关文档:
0、字符串是不可变的。
1、基本字符串操作:索引、切片、复制、成员、长度、最大和最小。
2、字符串格式化:用格式化操作符百分号%实现,eg:>>> format = "Hello, %s. %s enough for ya?"
  ......
今天学习了一下Python的操作符重载,总结了几点比较神奇的东东:
------------------------------------------------------------------------------------------------------------
关于iter:
Technically, iteration contexts work by calling the iter built-in function to try to
find an _ _iter_ _ method, whi ......
1.1. 语法
1.1.1. if
>>> x=int(raw_input("please enter an integer:"))
please enter an integer:-8
>>> if x<0:
... print 'negative'
... elif x==0:
... print 'zero'
... else:
... print 'positive'
...
negative
这里有几个知识点需要提醒:
1。和 ......
看着网上抓取网页数据的文章直瞪眼
后来想到用字符串分割来提取相应部分的内容
程序简单,但数行数和下标费了很长时间
我知道这肯定不是最好的办法- -!!
但我实现了,哈哈
# -*- coding: cp936 -*-
from urllib import *
import re
def stockSearch():
baseurl="http://www.google.cn/financ ......
如果python调用外部程序,需要直接抓去命令行的输出,有什么好的办法呢?
这里我们需要用到 os.popen 这个管道,然后用 read、readline或者readlines来读取命令行输出
#需要执行的命令
strCommand = 'xxxxxxxxxxxxxxxxx'
#用popen来执行命令行
oStdout = os.popen(strCommand)
#假设输出的内容只有一行
strStdout = ......