[python-win32] Implement a com server with a undocument interface

winterTTr winterttr at gmail.com
Wed May 6 03:54:52 CEST 2009


I want to use the win32com to implement a shell extension
with the function to display custom information
when i move mouse over a txt file in explorer on windows.
I search for the method to do this and found a com interface
which i can't find it in the current win32com library.
It is "IQueryInfo" .

And my coding is like this ( part of ):

*****************************************************************
import pythoncom
from win32com.shell import shell, shellcon
import win32gui
import win32con
import os
import winerror
from win32com.server.exception import COMException
from pywintypes import IID

IPersistFile_Methods = "IsDirty Load Save SaveCompleted
GetCurFile".split()

IID_IQueryInfo = "{00021500-0000-0000-C000-000000000046}"  # <==
IQueryInfo_Methods = ["GetInfoFlags","GetInfoTip"]

class ShellExtension:
    _reg_progid_ = "ShellExtension.winterTTr"
    _reg_desc_ = "Shell Extension from winterTTr"
    _reg_clsid_ = "{EB0D2B97-287A-4B91-A455-D2E021B894AC}"
    _com_interfaces_ = [
            pythoncom.IID_IPersistFile,
            IID(IID_IQueryInfo)]
    _public_methods_ = IPersistFile_Methods + IQueryInfo_Methods

# =============== IPersistFile : from ======================
def GetInfoFlags(self , Flags ):
    #raise COMException(desc="No Implemented",scode=winerror.E_NOTIMPL)
    raise COMException(hresult=winerror.E_NOTIMPL)

def GetInfoTip(self , flags ):
    print flags
    print "======== GetInfoTip ==========="
    return ""

# =============== IPersistFile : to ======================


# =============== IPersistFile : from ======================
def IsDirty( self ):
    raise COMException(hresult=winerror.E_NOTIMPL)

def Load(self, filename, mode):
    #self.filename = filename
    #self.mode = mode
    print filename


def Save( self ,FileName, Remember):
    raise COMException(hresult=winerror.E_NOTIMPL)

def SaveCompleted( self , pszFileName):
    raise COMException(hresult=winerror.E_NOTIMPL)

def GetCurFile( self ):
    raise COMException(hresult=winerror.E_NOTIMPL)

# =============== IPersistFile : to ======================

*****************************************************************

and i also modify the register as adding this
"HKEY_CLASSES_ROOT\\.txt\\{00021500-0000-0000-C000-000000000046}\\{EB0D2B97-287A-4B91-A455-D2E021B894AC}"


and my question is :
can i use IQueryInfo IID directly which i can't find it in pywin32com?
If it could , why i can't see the output from GetInfoTip via win32traceutil.py
( OK , i already register the com with --debug mode )

PS: i can see the out put that Load is invoked , but no "GetInfoTip" output

any one can give some advice ? Thanks.


More information about the python-win32 mailing list