So here is my problem, I have to implement a com server, that would be used by DotNet application, which can not work with late binding (apparently they don't have CreateObject of VB). So i am following the approach suggested by http://starship.python.net/crew/theller/ctypes/sum_sample.html, and things worked for a while but I am getting weird results now. Weird: python stops working, just shows the prompt.
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> w = win32com.client.Dispatch("ctypes.asd")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "C:\Python23\Lib\site-packages\win32com\client\__init__.py", line 95, in
Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,c
lsctx)
File "C:\Python23\Lib\site-packages\win32com\client\dynamic.py", line 91, in _
GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python23\Lib\site-packages\win32com\client\dynamic.py", line 79, in _
GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.II
D_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
>>> w = win32com.client.Dispatch("ctypes.SumObject")
>>> w
>>> w
>>> 1+2
>>>
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
>>> w = win32com.client.Dispatch("PythonDemos.Utilities")
>>> w
<COMObject PythonDemos.Utilities>
>>> dir(w)
['_ApplyTypes_', '_FlagAsMethod', '_LazyAddAttr_', '_NewEnum', '_Release_', '__A
ttrToID__', '__LazyMap__', '__call__', '__cmp__', '__doc__', '__getattr__', '__g
etitem__', '__init__', '__int__', '__len__', '__module__', '__nonzero__', '__rep
r__', '__setattr__', '__setitem__', '__str__', '_builtMethods_', '_enum_', '_fin
d_dispatch_type_', '_get_good_object_', '_get_good_single_object_', '_lazydata_'
, '_make_method_', '_mapCachedItems_', '_oleobj_', '_olerepr_', '_print_details_
', '_proc_', '_unicode_to_string_', '_username_', '_wrap_dispatch_']
>>> w.SplitString("asd")
(u'asd',)
>>> w = win32com.client.Dispatch("ctypes.SumObject")
>>> w.get(2,3)
>>> w
>>> 1+2
>>>
Does it sound familiar? A bug in win32com.client.Dispatch or should I be looking at my com server code [which is almost what is presented in sum_sample page I linked above? GUID conflict? I am stuck, please help.
TIA,
--
Amit Upadhyay
Blog: http://www.rootshell.be/~upadhyay
+91-9820-859-701
/* A TypeLibrary, compiled to sum.tlb */
[
uuid(90810cb9-d427-48b6-81ff-92d4a2098b45),
version(1.0),
helpstring("Sum 1.0 Type Library")
]
library SumLib
{
importlib("stdole2.tlb");
/* a dual interface, derived from IDispatch */
[
object,
dual,
uuid(6edc65bf-0cb7-4b0d-9e43-11c655e51ae9),
helpstring("IDualSum Interface"),
pointer_default(unique)
]
interface IDualSum: IDispatch {
[id(100)] HRESULT Add(double a, double b, [out, retval]
double *result);
};
[
uuid(2e0504a1-1a23-443f-939d-869a6c731521),
helpstring("CSum Class")
]
/* a coclass, implementing this interface */
coclass CSum
{
[default] interface IDualSum;
}
};
# -*- python -*-
# Generated from C:\Documents and Settings\Webroo\Desktop\p2p\test\sum.tlb
###############################################################
# NOTE: This is a GENERATED file. Please do not make changes, #
# they will be overwritten next time it is regenerated. #
###############################################################
from ctypes import *
from ctypes.com import IUnknown, GUID, STDMETHOD, HRESULT
from ctypes.com.automation import IDispatch, BSTR, VARIANT, dispinterface, \
DISPMETHOD, DISPPARAMS, EXCEPINFO
##############################################################################
# The Type Library
class SumLib:
'Sum 1.0 Type Library'
guid = GUID('{90810CB9-D427-48B6-81FF-92D4A2098B45}')
version = (1, 0)
flags = 0x8
path = 'C:\\Documents and Settings\\Webroo\\Desktop\\p2p\\test\\sum.tlb'
##############################################################################
class IDualSum(IDispatch):
"""IDualSum Interface"""
_iid_ = GUID('{6EDC65BF-0CB7-4B0D-9E43-11C655E51AE9}')
IDualSum._methods_ = IDispatch._methods_ + [
STDMETHOD(HRESULT, "Add", c_double, c_double, POINTER(c_double)),
]
##############################################################################
class CSum:
"""CSum Class"""
_reg_clsid_ = '{2E0504A1-1A23-443F-939D-869A6C731521}'
_com_interfaces_ = [IDualSum]
from sum_p import *
from ctypes.com.automation import DualObjImpl
class SumObject(DualObjImpl):
_com_interfaces_ = [IDualSum]
_typelib_ = SumLib
_reg_progid_ = "ctypes.SumObject"
_reg_desc_ = "Sum Object"
_reg_clsid_ = CSum._reg_clsid_
def IDualSum_Add(self, this, a, b, presult):
presult[0] = a + b
return 0
if __name__ == '__main__':
from ctypes.com.server import UseCommandLine
UseCommandLine(SumObject)
_______________________________________________ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
