[python-win32] CoInitialize not called?

James Carroll mrmaple at gmail.com
Fri Mar 10 20:14:30 CET 2006


Hi,  I have a multi-threaded wxPython App that examines shortcuts
using the function below.  The first time my thread runs that opens
hundreds of links and looks for my target exe everything is fine.  The
second time I get the following error:

Unhandled exception in thread started by
Traceback (most recent call last):
 File "C:\jimc\prj\bright\scripts\multiUser\searchLinksJob.py", line 54, in Run
self.fileChecker.CheckFile(file)
 File "C:\jimc\prj\bright\scripts\multiUser\UserAppFrame.py", line 47,
in CheckFile
(linkName, target, startIn, description) = wintools.ReadShortcut(file)
 File "C:\jimc\prj\bright\scripts\multiUser\wintools.py", line 77, in
ReadShortcut
sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been
called.', None, None)
Script terminated.

Should I just call CoInitialize myself randomly?

Thanks,
-Jim


def ReadShortcut(linkFileName):
    import pythoncom
    from win32com.shell import shell

    # Get the shell interface.
    sh = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)

    # Get an IPersist interface
    persist = sh.QueryInterface(pythoncom.IID_IPersistFile)
    try:
        persist.Load(linkFileName)
    except pywintypes.com_error:
        pass

    target = sh.GetPath(shell.SLGP_SHORTPATH)[0]
    arguments = sh.GetArguments()
    description = sh.GetDescription()
    startIn = sh.GetWorkingDirectory()
    return (linkFileName, target, startIn, description)
#


More information about the Python-win32 mailing list