Win32com
Bill Bell
bill-bell at bill-bell.hamilton.on.ca
Mon Jul 2 16:13:04 EDT 2001
"Mamoon Khan" <mamoonk at nortelnetworks.com> wrote:
> I am trying to create a ComServer . Following is some part of the
> code that you guys need to see if I am doing it right.
>
> _public_methods_ = [ 'SomeMethod']
> _reg_progid_ = "PythonComTest.TestClass"
> _reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"
>
> Here the vb code that I am using
>
> Dim SomeServer as Variant
> Set SomeServer = CreateObject(PythonComTest.TestClass")
>
> msgbox SomeServer.SomeMethod()
>
> I can register the Com Server fine and can call it from within python
> using createobject no problem.
>
> When I go to use it from VB I can create an object SomeServer fine but
> when I call a method and return a string from a function and try to
> display the results in a message box, I get an error invalid type.
>
> Could someone tell me what the heck is going on here with this.
Mamoon:
Maybe someone else can guess what's wrong, given this
information. I can't. I executed the following code in order to
register the server.
class SomeServer:
_public_methods_ = [ 'SomeMethod']
_reg_progid_ = "PythonComTest.TestClass"
_reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"
def SomeMethod(self):
return "A valid string"
if __name__=='__main__':
import win32com.server.register
win32com.server.register.UseCommandLine(SomeServer)
I believe this corresponds to what you gave in the way of
information.
The following worked as an MS Excel macro.
Public Sub ForMamoon()
Set someserver = CreateObject("PythonComTest.TestClass")
MsgBox someserver.somemethod
End Sub
And the following worked in VB6.
Private Sub Command1_Click()
Dim someserver As Object
Set someserver = CreateObject("PythonComTest.TestClass")
MsgBox someserver.somemethod
End Sub
Or, IOW, what you've supplied ~could~ be part of a COM server. :o)
I'd suggest that a reading of Chapter 12 of the Win32 book by
Hammond and Robinson in the O'Reilly series, if you haven't
already done that. What Mark Hammond suggested to me once
was that I implement the debugging machinery in my Python code
(also described in aforementioned reading) and see if that helps.
Good luck!
Bill
More information about the Python-list
mailing list