本文整理匯總了Python中ctypes.wintypes.LPSTR屬性的典型用法代碼示例。如果您正苦於以下問題:Python wintypes.LPSTR屬性的具體用法?Python wintypes.LPSTR怎麽用?Python wintypes.LPSTR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類ctypes.wintypes
的用法示例。
在下文中一共展示了wintypes.LPSTR屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wide2utf8
# 需要導入模塊: from ctypes import wintypes [as 別名]
# 或者: from ctypes.wintypes import LPSTR [as 別名]
def wide2utf8(self, fn):
"""Take a unicode file name string and encode it to a multibyte string
that Windows can use to represent file names (CP65001, UTF-8)
http://msdn.microsoft.com/en-us/library/windows/desktop/dd374130"""
from ctypes import wintypes
_CP_UTF8 = 65001
_CP_ACP = 0 # ANSI
_LPBOOL = POINTER(c_long)
_wideCharToMultiByte = windll.kernel32.WideCharToMultiByte
_wideCharToMultiByte.restype = c_int
_wideCharToMultiByte.argtypes = [wintypes.UINT, wintypes.DWORD,
wintypes.LPCWSTR, c_int,
wintypes.LPSTR, c_int,
wintypes.LPCSTR, _LPBOOL]
codePage = _CP_UTF8
dwFlags = 0
lpWideCharStr = fn
cchWideChar = len(fn)
lpMultiByteStr = None
cbMultiByte = 0 # zero requests size
lpDefaultChar = None
lpUsedDefaultChar = None
# get size
mbcssize = _wideCharToMultiByte(
codePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr,
cbMultiByte, lpDefaultChar, lpUsedDefaultChar)
if mbcssize <= 0:
raise WinError(mbcssize)
lpMultiByteStr = create_string_buffer(mbcssize)
# convert
retcode = _wideCharToMultiByte(
codePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr,
mbcssize, lpDefaultChar, lpUsedDefaultChar)
if retcode <= 0:
raise WinError(retcode)
return lpMultiByteStr.value
示例2: get_system_wow_64_dir_a
# 需要導入模塊: from ctypes import wintypes [as 別名]
# 或者: from ctypes.wintypes import LPSTR [as 別名]
def get_system_wow_64_dir_a(string_buffer: wintypes.LPSTR, size: wintypes.UINT) -> wintypes.UINT:
pass
示例3: __str_to_winastr__
# 需要導入模塊: from ctypes import wintypes [as 別名]
# 或者: from ctypes.wintypes import LPSTR [as 別名]
def __str_to_winastr__(self, in_str_u):
"""
In: Python unicode string
Out: ANSI_STRING
"""
in_str_a = in_str_u.encode('utf-8')
in_astr = ANSI_STRING()
in_astr.Length = len(in_str_a)
in_astr.MaximumLength = len(in_str_a) + 2
in_astr.Buffer = wintypes.LPSTR(in_str_a)
return in_astr