本文整理匯總了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)