[IronPython] Change to COM Interop in IronPython 2

Michael Foord michael.foord at resolversystems.com
Mon Dec 1 14:13:43 CET 2008


Hello guys,

In some of our Resolver One installer tests we do some COM interop to 
check that the targets of the shortcuts the installer creates are correct.

It looks like the way COM interop is done in IronPython 2 has changed a 
bit. We are now getting an exception thrown when previously None was 
returned to us, and I'd like to check that this is the correct / 
expected behaviour.

The code use to look like this:

   def GetLinkTarget(filename):
       import clr
       import sys
       sys.path.append(Path.GetFullPath('TestUtils'))
       clr.AddReferenceToFile('Interop.Shell32.dll')
       from Interop.Shell32 import ShellClass
       shell = ShellClass()
       folder = shell.NameSpace(Path.GetDirectoryName(filename))
       folderItem = folder.ParseName(Path.GetFileName(filename))
       if folderItem is not None:
           return folderItem.GetLink.Path

In moving to IronPython 2 we've had to change the last line to:

    return folderItem.GetLink().Path()

If we call the function with a filename that doesn't exist, 
folder.ParseName(...) used to return None. Now we get the following 
exception:

Traceback (most recent call last):
 File "FunctionalTests\UnitTests\InstallerTestTest.py", line 97, in 
testGetLinkTarget2
   self.assertNone(InstallerTest.GetLinkTarget(
 File "C:\shared\Ipy2\FunctionalTests\InstallerTest.py", line 67, in 
GetLinkTarget
   folderItem = folder.ParseName(Path.GetFileName(filename))
TypeError: Value cannot be null.
Parameter name: pUnk

All the best,

Michael Foord

-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog





More information about the Ironpython-users mailing list