Python pythoncom 模块,STGMEDIUM 实例源码

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

项目:CNKI-QQFriend    作者:hsluoyz    | 项目源码 | 文件源码
def clip_files(file_list):
    offset = ctypes.sizeof(DROPFILES)
    length = sum(len(p) + 1 for p in file_list) + 1
    size = offset + length * ctypes.sizeof(ctypes.c_wchar)
    buf = (ctypes.c_char * size)()
    df = DROPFILES.from_buffer(buf)
    df.pFiles, df.fWide = offset, True
    for path in file_list:
        path = path.decode('gbk')
        print "copying to clipboard, filename = " + path
        array_t = ctypes.c_wchar * (len(path) + 1)
        path_buf = array_t.from_buffer(buf, offset)
        path_buf.value = path
        offset += ctypes.sizeof(path_buf)
    stg = pythoncom.STGMEDIUM()
    stg.set(pythoncom.TYMED_HGLOBAL, buf)
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    try:
        win32clipboard.SetClipboardData(win32clipboard.CF_HDROP, stg.data)
        print "clip_files() succeed"
    finally:
        win32clipboard.CloseClipboard()
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed  = fe
        if aspect & pythoncom.DVASPECT_CONTENT and \
           tymed==pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                # ensure always 'bytes' by encoding string.
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, unicode(self.strval))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed  = fe
        if aspect & pythoncom.DVASPECT_CONTENT and \
           tymed==pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                # ensure always 'bytes' by encoding string.
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, unicode(self.strval))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed  = fe
        if aspect & pythoncom.DVASPECT_CONTENT and \
           tymed==pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                # ensure always 'bytes' by encoding string.
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, unicode(self.strval))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def GetData(self, fe):
        ret_stg = None
        cf, target, aspect, index, tymed  = fe
        if aspect & pythoncom.DVASPECT_CONTENT and \
           tymed==pythoncom.TYMED_HGLOBAL:
            if cf == win32con.CF_TEXT:
                ret_stg = pythoncom.STGMEDIUM()
                # ensure always 'bytes' by encoding string.
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str2bytes(self.strval))
            elif cf == win32con.CF_UNICODETEXT:
                ret_stg = pythoncom.STGMEDIUM()
                ret_stg.set(pythoncom.TYMED_HGLOBAL, str(self.strval))

        if ret_stg is None:
            raise COMException(hresult=winerror.E_NOTIMPL)
        return ret_stg
项目:OSPTF    作者:xSploited    | 项目源码 | 文件源码
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0"))
项目:pupy    作者:ru-faraon    | 项目源码 | 文件源码
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0"))
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0"))
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def testWin32ToCom(self):
        # Set the data via the std win32 clipboard functions.
        val = str2bytes("Hello again!") # ensure always bytes, even in py3k
        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_TEXT, val)
        win32clipboard.CloseClipboard()
        # and get it via an IDataObject provided by COM
        do = pythoncom.OleGetClipboard()
        cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL
        stg = do.GetData(cf)
        got = stg.data
        # The data we get back has the \0, as our STGMEDIUM has no way of 
        # knowing if it meant to be a string, or a binary buffer, so
        # it must return it too.
        self.failUnlessEqual(got, str2bytes("Hello again!\0"))