Python ctypes.wintypes 模块,LPVOID 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用ctypes.wintypes.LPVOID

项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def ReadFile(file, buffer, number_of_bytes_to_read, number_of_bytes_read, overlapped):
    """See: ReadFile function
       https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx
    """
    ReadFile_Fn = windll.kernel32.ReadFile
    ReadFile_Fn.argtypes = [
    wintypes.HANDLE,    # _In_        HANDLE       hFile,
    LPVOID,             # _Out_       LPVOID       lpBuffer,
    wintypes.DWORD,     # _In_        DWORD        nNumberOfBytesToRead,
    LPDWORD,            # _Out_opt_   LPDWORD      lpNumberOfBytesRead,
    LPOVERLAPPED        # _Inout_opt_ LPOVERLAPPED lpOverlapped
    ]
    ReadFile_Fn.restype = wintypes.BOOL

    ret = wintypes.BOOL(ReadFile_Fn(
        file, 
        buffer, 
        number_of_bytes_to_read, 
        number_of_bytes_read, 
        overlapped
    ))
项目:driverlib    作者:sam-b    | 项目源码 | 文件源码
def send_ioctl(self, ioctl, inbuf, inbufsiz, outbuf, outbufsiz):
        """See: DeviceIoControl function
        http://msdn.microsoft.com/en-us/library/aa363216(v=vs.85).aspx
        """
        DeviceIoControl_Fn = windll.kernel32.DeviceIoControl
        DeviceIoControl_Fn.argtypes = [
                wintypes.HANDLE,                    # _In_          HANDLE hDevice
                wintypes.DWORD,                     # _In_          DWORD dwIoControlCode
                wintypes.LPVOID,                    # _In_opt_      LPVOID lpInBuffer
                wintypes.DWORD,                     # _In_          DWORD nInBufferSize
                wintypes.LPVOID,                    # _Out_opt_     LPVOID lpOutBuffer
                wintypes.DWORD,                     # _In_          DWORD nOutBufferSize
                LPDWORD,                            # _Out_opt_     LPDWORD lpBytesReturned
                LPOVERLAPPED]                       # _Inout_opt_   LPOVERLAPPED lpOverlapped
        DeviceIoControl_Fn.restype = wintypes.BOOL
        print ioctl
        # allocate a DWORD, and take its reference
        dwBytesReturned = wintypes.DWORD(0)
        lpBytesReturned = ctypes.byref(dwBytesReturned)
        status = DeviceIoControl_Fn(self.handle,
                      ioctl,
                      inbuf,
                      inbufsiz,
                      outbuf,
                      outbufsiz,
                      lpBytesReturned,
                      None)

        return status, dwBytesReturned
项目:constructor    作者:conda    | 项目源码 | 文件源码
def _link(src, dst, linktype=LINK_HARD):
    if linktype == LINK_HARD:
        if on_win:
            from ctypes import windll, wintypes
            CreateHardLink = windll.kernel32.CreateHardLinkW
            CreateHardLink.restype = wintypes.BOOL
            CreateHardLink.argtypes = [wintypes.LPCWSTR, wintypes.LPCWSTR,
                                       wintypes.LPVOID]
            if not CreateHardLink(dst, src, None):
                raise OSError('win32 hard link failed')
        else:
            os.link(src, dst)
    elif linktype == LINK_COPY:
        # copy relative symlinks as symlinks
        if islink(src) and not os.readlink(src).startswith(os.path.sep):
            os.symlink(os.readlink(src), dst)
        else:
            shutil.copy2(src, dst)
    else:
        raise Exception("Did not expect linktype=%r" % linktype)
项目:azure-cli    作者:Azure    | 项目源码 | 文件源码
def _set_internet_options(self, setting, on=True):
        """
        Sets the internet options
        """
        InternetSetOption = windll.wininet.InternetSetOptionW
        InternetSetOption.argtypes = [LPVOID, DWORD, LPVOID, DWORD]
        InternetSetOption.restype = BOOL

        List = INTERNET_PER_CONN_OPTION_LIST()
        Option = (INTERNET_PER_CONN_OPTION * 3)()
        nSize = c_ulong(sizeof(INTERNET_PER_CONN_OPTION_LIST))

        Option[0].dwOption = self.INTERNET_PER_CONN_FLAGS
        Option[0].Value.dwValue = (2 if on else 1)
        Option[1].dwOption = self.INTERNET_PER_CONN_PROXY_SERVER
        Option[1].Value.pszValue = setting
        Option[2].dwOption = self.INTERNET_PER_CONN_PROXY_BYPASS
        Option[2].Value.pszValue = create_unicode_buffer('<-loopback>')

        List.dwSize = sizeof(INTERNET_PER_CONN_OPTION_LIST)
        List.pszConnection = None
        List.dwOptionCount = 3
        List.dwOptionError = 0
        List.pOptions = Option

        InternetSetOption(None, self.INTERNET_OPTION_PER_CONNECTION_OPTION, byref(List), nSize)
        InternetSetOption(None, self.INTERNET_OPTION_SETTINGS_CHANGED, None, 0)
        InternetSetOption(None, self.INTERNET_OPTION_REFRESH, None, 0)


# pylint: disable=too-few-public-methods
项目:win_driver_plugin    作者:mwrlabs    | 项目源码 | 文件源码
def send_ioctl(self, ioctl, inbuf, inbufsiz, outbuf, outbufsiz):
        """See: DeviceIoControl function
        http://msdn.microsoft.com/en-us/library/aa363216(v=vs.85).aspx
        """
        DeviceIoControl_Fn = windll.kernel32.DeviceIoControl
        DeviceIoControl_Fn.argtypes = [
                wintypes.HANDLE,                    # _In_          HANDLE hDevice
                wintypes.DWORD,                     # _In_          DWORD dwIoControlCode
                wintypes.LPVOID,                    # _In_opt_      LPVOID lpInBuffer
                wintypes.DWORD,                     # _In_          DWORD nInBufferSize
                wintypes.LPVOID,                    # _Out_opt_     LPVOID lpOutBuffer
                wintypes.DWORD,                     # _In_          DWORD nOutBufferSize
                LPDWORD,                            # _Out_opt_     LPDWORD lpBytesReturned
                LPOVERLAPPED]                       # _Inout_opt_   LPOVERLAPPED lpOverlapped
        DeviceIoControl_Fn.restype = wintypes.BOOL
        # allocate a DWORD, and take its reference
        dwBytesReturned = wintypes.DWORD(0)
        lpBytesReturned = ctypes.byref(dwBytesReturned)
        status = DeviceIoControl_Fn(self.handle,
                      ioctl,
                      inbuf,
                      inbufsiz,
                      outbuf,
                      outbufsiz,
                      lpBytesReturned,
                      None)

        return status, dwBytesReturned
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
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