本文整理汇总了Python中ctypes.wintypes.BYTE属性的典型用法代码示例。如果您正苦于以下问题:Python wintypes.BYTE属性的具体用法?Python wintypes.BYTE怎么用?Python wintypes.BYTE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ctypes.wintypes
的用法示例。
在下文中一共展示了wintypes.BYTE属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_printer_names
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def get_printer_names():
names = []
info = ctypes.POINTER(BYTE)()
pcbNeeded = DWORD(0)
pcReturned = DWORD(0)
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, NAME, 1, ctypes.byref(info),
0, ctypes.byref(pcbNeeded), ctypes.byref(pcReturned))
bufsize = pcbNeeded.value
if bufsize:
buff = msvcrt.malloc(bufsize)
winspool.EnumPrintersW(PRINTER_ENUM_LOCAL, NAME, 1, buff, bufsize,
ctypes.byref(pcbNeeded),
ctypes.byref(pcReturned))
info = ctypes.cast(buff, ctypes.POINTER(PRINTER_INFO_1))
for i in range(pcReturned.value):
names.append(info[i].pName)
msvcrt.free(buff)
return names
示例2: is_color_printer
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def is_color_printer(prtname):
ret = False
if not prtname:
prtname = get_default_printer()
hptr = open_printer(prtname)
info = ctypes.POINTER(BYTE)()
cbBuf = DWORD(0)
pcbNeeded = DWORD(0)
winspool.GetPrinterA(hptr, 2, ctypes.byref(info),
cbBuf, ctypes.byref(pcbNeeded))
bufsize = pcbNeeded.value
if bufsize:
buff = msvcrt.malloc(bufsize)
winspool.GetPrinterA(hptr, 2, buff, bufsize, ctypes.byref(pcbNeeded))
info = ctypes.cast(buff, ctypes.POINTER(PRINTER_INFO_2))
ret = info.contents.pDevMode.contents.dmColor == 2
msvcrt.free(buff)
close_printer(hptr)
return ret
示例3: encrypt
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def encrypt(data, non_interactive=0):
blobin = DATA_BLOB(
cbData=len(data), pbData=cast(c_char_p(data), POINTER(wintypes.BYTE))
)
blobout = DATA_BLOB()
if not CryptProtectData(
byref(blobin),
'python-keyring-lib.win32crypto',
None,
None,
None,
CRYPTPROTECT_UI_FORBIDDEN,
byref(blobout),
):
raise OSError("Can't encrypt")
encrypted = create_string_buffer(blobout.cbData)
memmove(encrypted, blobout.pbData, blobout.cbData)
windll.kernel32.LocalFree(blobout.pbData)
return encrypted.raw
示例4: decrypt
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def decrypt(encrypted, non_interactive=0):
blobin = DATA_BLOB(
cbData=len(encrypted), pbData=cast(c_char_p(encrypted), POINTER(wintypes.BYTE))
)
blobout = DATA_BLOB()
if not CryptUnprotectData(
byref(blobin),
'python-keyring-lib.win32crypto',
None,
None,
None,
CRYPTPROTECT_UI_FORBIDDEN,
byref(blobout),
):
raise OSError("Can't decrypt")
data = create_string_buffer(blobout.cbData)
memmove(data, blobout.pbData, blobout.cbData)
windll.kernel32.LocalFree(blobout.pbData)
return data.raw
示例5: _get_thumbprint_buffer
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def _get_thumbprint_buffer(thumbprint_str):
thumbprint_bytes = encoding.hex_to_bytes(thumbprint_str)
return ctypes.cast(
ctypes.create_string_buffer(thumbprint_bytes),
ctypes.POINTER(wintypes.BYTE *
len(thumbprint_bytes))).contents
示例6: byte_buffer
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def byte_buffer(length):
"""Get a buffer for a string"""
return (BYTE*length)()
示例7: send_vcp_code
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def send_vcp_code(self, code: int, value: int) -> bool:
"""
send vcp code to monitor.
https://msdn.microsoft.com/en-us/library/dd692979(v=vs.85).aspx
BOOL SetVCPFeature(
_In_ HANDLE hMonitor,
_In_ BYTE bVCPCode,
_In_ DWORD dwNewValue
);
:param code: VCP Code
:param value: Data
:return: Win32 API return
"""
if code is None:
_LOGGER.error('vcp code to send is None. ignored.')
return False
api_call = ctypes.windll.Dxva2.SetVCPFeature
code = wintypes.BYTE(code)
new_value = wintypes.DWORD(value)
api_call.restype = ctypes.c_bool
ret_ = api_call(self._phy_monitor_handle, code, new_value)
if not ret_:
_LOGGER.error('send vcp command failed: ' + hex(code))
_LOGGER.error(ctypes.WinError())
return ret_
示例8: read_vcp_code
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def read_vcp_code(self, code: int) -> Tuple[int, int]:
"""
send vcp code to monitor, get current value and max value.
https://msdn.microsoft.com/en-us/library/dd692953(v=vs.85).aspx
BOOL GetVCPFeatureAndVCPFeatureReply(
_In_ HANDLE hMonitor,
_In_ BYTE bVCPCode,
_Out_ LPMC_VCP_CODE_TYPE pvct,
_Out_ LPDWORD pdwCurrentValue,
_Out_ LPDWORD pdwMaximumValue
);
:param code: VCP Code
:return: current_value, max_value
"""
if code is None:
_LOGGER.error('vcp code to send is None. ignored.')
return 0, 0
api_call = ctypes.windll.Dxva2.GetVCPFeatureAndVCPFeatureReply
api_in_vcp_code = wintypes.BYTE(code)
api_out_current_value = wintypes.DWORD()
api_out_max_value = wintypes.DWORD()
if not api_call(self._phy_monitor_handle, api_in_vcp_code, None,
ctypes.byref(api_out_current_value), ctypes.byref(api_out_max_value)):
_LOGGER.error('get vcp command failed: ' + hex(code))
_LOGGER.error(ctypes.WinError())
return api_out_current_value.value, api_out_max_value.value
示例9: import_pfx_certificate
# 需要导入模块: from ctypes import wintypes [as 别名]
# 或者: from ctypes.wintypes import BYTE [as 别名]
def import_pfx_certificate(self, pfx_data, pfx_password=None,
machine_keyset=True, store_name=STORE_NAME_MY):
cert_context_p = None
import_store_handle = None
store_handle = None
try:
pfx_blob = cryptoapi.CRYPTOAPI_BLOB()
pfx_blob.cbData = len(pfx_data)
pfx_blob.pbData = ctypes.cast(
pfx_data, ctypes.POINTER(wintypes.BYTE))
import_store_handle = cryptoapi.PFXImportCertStore(
ctypes.pointer(pfx_blob), pfx_password, 0)
if not import_store_handle:
raise cryptoapi.CryptoAPIException()
cert_context_p = cryptoapi.CertFindCertificateInStore(
import_store_handle,
cryptoapi.X509_ASN_ENCODING | cryptoapi.PKCS_7_ASN_ENCODING,
0, cryptoapi.CERT_FIND_ANY, None, None)
if not cert_context_p:
raise cryptoapi.CryptoAPIException()
if machine_keyset:
flags = cryptoapi.CERT_SYSTEM_STORE_LOCAL_MACHINE
else:
flags = cryptoapi.CERT_SYSTEM_STORE_CURRENT_USER
store_handle = cryptoapi.CertOpenStore(
cryptoapi.CERT_STORE_PROV_SYSTEM, 0, 0, flags,
six.text_type(store_name))
if not store_handle:
raise cryptoapi.CryptoAPIException()
if not cryptoapi.CertAddCertificateContextToStore(
store_handle, cert_context_p,
cryptoapi.CERT_STORE_ADD_REPLACE_EXISTING, None):
raise cryptoapi.CryptoAPIException()
finally:
if import_store_handle:
cryptoapi.CertCloseStore(import_store_handle, 0)
if cert_context_p:
cryptoapi.CertFreeCertificateContext(cert_context_p)
if store_handle:
cryptoapi.CertCloseStore(store_handle, 0)