I am trying to call a method on a COM Object from a loaded .dll assembly. The problem is very similar to this one, it's just I am working with ironpython 2.7. instead of ironruby.
As with that issue, I can call any property or method which does not take any arguments.
But once a method requires at least one argument, I am getting an error message:
Could not convert argument 0 for call to Open.
Here is the example code:
import clr
import os
shpfilename = "C:/example.shp"
dllsfilename = "C:/mapwindow_dlls"
clr.AddReferenceToFileAndPath(os.path.join(dllsfilename, "Interop.MapWinGIS.dll"))
print "Interop.MapWinGIS.dll loaded: ", "Interop.MapWinGIS" in [assembly.GetName().Name for assembly in clr.References] # prints: True
import MapWinGIS
sf = MapWinGIS.ShapefileClass()
sf.Open(shpfilename, None) # raises upper error message
Does anyone know why is this happening?
I googled a bit, look like the issue might be with the shpfilename
type. So I tried passing the shpfilename
by-reference:
shpfilenameRef = clr.Reference[System.String](shpfilename)
sf.Open(shpfilenameRef, None) # again, raises upper error message
But still the upper error message does not go away.
The Open function has this signature:
Help on method-descriptor Open Open(...)
Open(self: ShapefileClass, ShapefileName: str, cBack: Callback) -> bool
// MapWinGIS.ShapefileClass
[DispId(11)]
[MethodImpl(MethodImplOptions.InternalCall)]
public virtual extern bool Open([MarshalAs(UnmanagedType.BStr)] [In] string ShapefileName, [MarshalAs(UnmanagedType.Interface)] [In] ICallback cBack = null);