[python-win32] makepy problem with a .Net assembly => COM

Mark Hammond mhammond@skippinet.com.au
Sat, 15 Feb 2003 11:53:45 +1100


I suggest you package up a small example that demonstrates the problem.
Note that even though the function is declared as returning an Object, A
NULL reference could still be returned - ie, a functio that returns an
"Object" may also return None.

In general, you should find the COM interop stuff works OK.  The Python for
.NET compiler I played with uses win32com to talk to the Reflection::Emit
APIs.  While there are some problems, they are fairly esoteric, so
non-compilers shouldn't have them.

Mark.

> -----Original Message-----
> From: python-win32-admin@python.org
> [mailto:python-win32-admin@python.org]On Behalf Of Dan Kruger
> Sent: Saturday, 15 February 2003 7:13 AM
> To: python-win32@python.org
> Subject: [python-win32] makepy problem with a .Net assembly => COM
>
>
> Hello!
>
> I'm new to .Net, and Python, so please forgive me in advance
> if I sound rather inexperienced..
>
> I've been building a set of tools for the programming staff
> where I work to provide simple access to some of the
> more complexities behind accessing a MySQL server with a
> dedicated data provider as well as some of the business rules..
>
> Internal processing programs will be using the .Net
> assemblies I've produced, but our web content is mostly created with
> Python (thru CGI scripting) because it's a far easier for the
> web-designers to comprehend.
>
> Currently, there has been functions written to emulate the
> functionality of the .Net assemblies, which could potentially
> create a maintenance headache if business policies were to
> change.. (i.e. the python functions would have to be updated
> along side the .Net functions)
>
> So.. what I'd like to do is use the .Net assemblies in the
> Python scripts so that all data processing is going through
> the same engine.
>
> Anyway.. here are the steps I've gone through to make this
> happen, and here's the problem I'm experiencing:
> I ...
> 1)  compiled the assembly
> 2) placed it in the same directory as the python interpretter
> 3) regasm /tlb'ed the assembly.
>
> >>> import win32com.client
> Rebuilding cache of generated files for COM support...
> Done.
> >>> a =
> win32com.client.Dispatch("DotNetSystemTools.ByteFXDataAccess.c
> lsMySQLQueryExecute")
> >>> print a.Execute("SELECT NOW()",0)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "<COMObject
> DotNetSystemTools.ByteFXDataAccess.clsMySQLQueryExecute>",
> line 2, in Execute
> com_error: (-2147352567, 'Exception occurred.', (0,
> 'DotNetSystemTools', 'Object reference not set to an instance
> of an object.', None, 0, -2147467261), None)
>
>
> So.. I run the makepy utility..  I get...
>
> >>> Generating to
> C:\Python22\lib\site-packages\win32com\gen_py\F9CBB761-1389-40
> 44-87AC-F68E4286CD02x0x1x0.py
>
> Now when I try to reference the COM object I get...
>
> >>> a =
> win32com.client.Dispatch("DotNetSystemTools.ByteFXDataAccess.c
> lsMySQLQueryExecute")
> >>> print a.Execute("SELECT NOW()",0)
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File
> "C:\Python22\lib\site-packages\win32com\client\__init__.py",
> line 368, in __getattr__
>     raise AttributeError, "'%s' object has no attribute '%s'"
> % (repr(self), attr)
> AttributeError:
> '<win32com.gen_py.F9CBB761-1389-4044-87AC-F68E4286CD02x0x1x0._
DotNetSystemTools_ByteFXDataAccess_clsMySQLQueryExecute>' object has no
attribute 'Execute'
>
> I got no warnings when I built the tlb files with regasm.
> Any idea why this won't go from the meager amount of
> information I've given here.  (I would probably be able to
> supply the source)
>
> The assembly does have some 3rd party reference .dlls (I
> believe the author wrote these in C# managed code).  Would
> this make a difference?  I'm guessing it wouldn't since there
> are NO direct interfaces to these 3rd party interfaces are
> public (just function/property wrappers I've written that
> hand the data off).
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>