python类LPWSTR的实例源码

win.py 文件源码 项目:aws-ec2rescue-linux 作者: awslabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
windows_cmdline.py 文件源码 项目:kapsel 作者: conda 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def windows_split_command_line(command):
    from ctypes import windll, c_int, POINTER, byref
    from ctypes.wintypes import LPCWSTR, LPWSTR, HLOCAL

    CommandLineToArgvW = windll.shell32.CommandLineToArgvW
    CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
    CommandLineToArgvW.restype = POINTER(LPWSTR)

    LocalFree = windll.kernel32.LocalFree
    LocalFree.argtypes = [HLOCAL]
    LocalFree.restype = HLOCAL

    argc = c_int(0)
    argv = CommandLineToArgvW(command, byref(argc))
    if not argv:
        # The docs say CommandLineToArgvW returns NULL on error, but they
        # don't describe any possible errors, so who knows when/if this happens.
        # Maybe only on low memory or something?
        raise WindowsCommandLineException("Windows could not parse command line: " + str(command))
    try:
        result = []
        i = 0
        while i < argc.value:
            try:
                result.append(str(argv[i]))
            except UnicodeEncodeError as e:
                message = (
                    "Windows cannot represent this command line in its character encoding: " + command + ": " + str(e))
                raise WindowsCommandLineException(message)
            i += 1
    finally:
        LocalFree(argv)
    return result
genwincodec.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def genwinmap(codepage):
    MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
    MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
                                    wintypes.LPCSTR, ctypes.c_int,
                                    wintypes.LPWSTR, ctypes.c_int]
    MultiByteToWideChar.restype = ctypes.c_int

    enc2uni = {}

    for i in range(32) + [127]:
        enc2uni[i] = (i, 'CONTROL CHARACTER')

    for i in range(256):
        buf = ctypes.create_unicode_buffer(2)
        ret = MultiByteToWideChar(
            codepage, 0,
            chr(i), 1,
            buf, 2)
        assert ret == 1, "invalid code page"
        assert buf[1] == '\x00'
        try:
            name = unicodedata.name(buf[0])
        except ValueError:
            try:
                name = enc2uni[i][1]
            except KeyError:
                name = ''

        enc2uni[i] = (ord(buf[0]), name)

    return enc2uni
genwincodec.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def genwinmap(codepage):
    MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
    MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
                                    wintypes.LPCSTR, ctypes.c_int,
                                    wintypes.LPWSTR, ctypes.c_int]
    MultiByteToWideChar.restype = ctypes.c_int

    enc2uni = {}

    for i in range(32) + [127]:
        enc2uni[i] = (i, 'CONTROL CHARACTER')

    for i in range(256):
        buf = ctypes.create_unicode_buffer(2)
        ret = MultiByteToWideChar(
            codepage, 0,
            chr(i), 1,
            buf, 2)
        assert ret == 1, "invalid code page"
        assert buf[1] == '\x00'
        try:
            name = unicodedata.name(buf[0])
        except ValueError:
            try:
                name = enc2uni[i][1]
            except KeyError:
                name = ''

        enc2uni[i] = (ord(buf[0]), name)

    return enc2uni
win.py 文件源码 项目:alexa-apple-calendar 作者: zanderxyz 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:Wox.Plugin.Lunar 作者: imwr 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:alfredToday 作者: jeeftor 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:slack_scholar 作者: xLeitix 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
wget.py 文件源码 项目:altyazi 作者: my-old-projects 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def win32_utf8_argv():
    """Uses shell32.GetCommandLineArgvW to get sys.argv as a list of Unicode
    strings.

    Versions 2.x of Python don't support Unicode in sys.argv on
    Windows, with the underlying Windows API instead replacing multi-byte
    characters with '?'.
    """

    from ctypes import POINTER, byref, cdll, c_int, windll
    from ctypes.wintypes import LPCWSTR, LPWSTR

    GetCommandLineW = cdll.kernel32.GetCommandLineW
    GetCommandLineW.argtypes = []
    GetCommandLineW.restype = LPCWSTR

    CommandLineToArgvW = windll.shell32.CommandLineToArgvW
    CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
    CommandLineToArgvW.restype = POINTER(LPWSTR)

    cmd = GetCommandLineW()
    argc = c_int(0)
    argv = CommandLineToArgvW(cmd, byref(argc))
    argnum = argc.value
    sysnum = len(sys.argv)
    result = []
    if argnum > 0:
        # Remove Python executable and commands if present
        start = argnum - sysnum
        for i in range(start, argnum):
            result.append(argv[i].encode('utf-8'))
    return result


# enable unicode output to windows console
# https://stackoverflow.com/questions/878972/windows-cmd-encoding-change-causes-python-crash
win.py 文件源码 项目:ooniprobe-debian 作者: TheTorProject 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:noobotkit 作者: nazroll 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
windows_cmdline.py 文件源码 项目:anaconda-project 作者: Anaconda-Platform 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def windows_split_command_line(command):
    from ctypes import windll, c_int, POINTER, byref
    from ctypes.wintypes import LPCWSTR, LPWSTR, HLOCAL

    CommandLineToArgvW = windll.shell32.CommandLineToArgvW
    CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
    CommandLineToArgvW.restype = POINTER(LPWSTR)

    LocalFree = windll.kernel32.LocalFree
    LocalFree.argtypes = [HLOCAL]
    LocalFree.restype = HLOCAL

    argc = c_int(0)
    argv = CommandLineToArgvW(command, byref(argc))
    if not argv:
        # The docs say CommandLineToArgvW returns NULL on error, but they
        # don't describe any possible errors, so who knows when/if this happens.
        # Maybe only on low memory or something?
        raise WindowsCommandLineException("Windows could not parse command line: " + str(command))
    try:
        result = []
        i = 0
        while i < argc.value:
            try:
                result.append(str(argv[i]))
            except UnicodeEncodeError as e:
                message = (
                    "Windows cannot represent this command line in its character encoding: " + command + ": " + str(e))
                raise WindowsCommandLineException(message)
            i += 1
    finally:
        LocalFree(argv)
    return result
dpapi.py 文件源码 项目:jaraco.windows 作者: jaraco 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def CryptUnprotectData(data, optional_entropy=None, prompt_struct=None, flags=0):
    """
    Returns a tuple of (description, data) where description is the
    the description that was passed to the CryptProtectData call and
    data is the decrypted result.
    """
    data_in = DATA_BLOB(data)
    entropy = DATA_BLOB(optional_entropy) if optional_entropy else None
    data_out = DATA_BLOB()
    ptr_description = wintypes.LPWSTR()
    res = _CryptUnprotectData(
        data_in,
        ctypes.byref(ptr_description),
        entropy,
        None, # reserved
        prompt_struct,
        flags | CRYPTPROTECT_UI_FORBIDDEN,
        data_out,
        )
    handle_nonzero_success(res)
    description = ptr_description.value
    if ptr_description.value is not None:
        ctypes.windll.kernel32.LocalFree(ptr_description)
    res = data_out.get_data()
    data_out.free()
    return description, res
win.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
cache.py 文件源码 项目:StuffShare 作者: StuffShare 项目源码 文件源码 阅读 68 收藏 0 点赞 0 评论 0
def __init__(self, folder):
            self.folder = folder
            # Check the best way to do atomic file replacement.
            if sys.version_info >= (3, 3):
                self.replace = os.replace
            elif sys.platform == "win32":
                import ctypes
                from ctypes import wintypes
                ReplaceFile = ctypes.windll.kernel32.ReplaceFileW
                ReplaceFile.restype = wintypes.BOOL
                ReplaceFile.argtypes = [
                    wintypes.LPWSTR,
                    wintypes.LPWSTR,
                    wintypes.LPWSTR,
                    wintypes.DWORD,
                    wintypes.LPVOID,
                    wintypes.LPVOID,
                    ]

                def replace_windows(src, dst):
                    if not ReplaceFile(dst, src, None, 0, 0, 0):
                        os.rename(src, dst)

                self.replace = replace_windows
            else:
                # POSIX rename() is always atomic
                self.replace = os.rename
win.py 文件源码 项目:Chorus 作者: DonaldBough 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc
win.py 文件源码 项目:tf_aws_ecs_instance_draining_on_scale_in 作者: terraform-community-modules 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, tzres_loc='tzres.dll'):
        # Load the user32 DLL so we can load strings from tzres
        user32 = ctypes.WinDLL('user32')

        # Specify the LoadStringW function
        user32.LoadStringW.argtypes = (wintypes.HINSTANCE,
                                       wintypes.UINT,
                                       wintypes.LPWSTR,
                                       ctypes.c_int)

        self.LoadStringW = user32.LoadStringW
        self._tzres = ctypes.WinDLL(tzres_loc)
        self.tzres_loc = tzres_loc


问题


面经


文章

微信
公众号

扫码关注公众号