Hello Thomas,
(now to correct list address...)
Many thanks for the answer but unfortunately it does not help.
I'm not experienced with (D)COM. As I see if I want to use the CoClass (resp.
QueryInterface) I
have to do this
from comtypes.gen import AutomaticTesting
#help (AutomaticTesting.AutomaticTesting)
self.__appl=CreateObject(AutomaticTesting.AutomaticTesting)
print self.__appl.SendService("1101").Value()
but I get the same error "parameter not optional" as well as when I use
QueryInterface:
from comtypes.gen import AutomaticTesting
instance=comtypes.CoCreateInstance(self.CLSID)
self.__appl =instance.QueryInterface(AutomaticTesting.IAutomaticTesting)
print self.__appl.SendService("1101").Value()
print self.__appl.SendService("1101").Value()
File "C:\Programs\Python25\Lib\site-packages\comtypes\__init__.py", line 414,
in func
return self.Invoke(obj, memid, _invkind=1, *args, **kw) #
DISPATCH_METHOD File
"C:\Programs\Python25\Lib\site-packages\comtypes\automation.py",line 596, in
Invoke
byref(result), byref(excepinfo), byref(argerr))
_ctypes.COMError: (-2147352561, 'Parameter nicht optional.', (None, None,None,
0, None))
I have a Perl example to use this server that works fine:
use strict;
use Win32::OLE;
use Win32::OLE::Variant;
Win32::OLE->Option( Warn => 3 );
my $objApp = Win32::OLE->new("AutomaticTesting.Application","Quit");
my $Result = -1;
my $Answer = Variant(VT_BYREF|VT_VARIANT, Variant(VT_BSTR, ""));
print "Send Service 1101\n";
$Result = $objApp->SendService("1101",$Answer);
if ($Result != 0)
{
print "Error at 1101!";
exit();
}
Other ideas ?
Thanks,
Jens
Thomas Heller wrote:
> Jens schrieb:
>
>> Hi,
>>
>> the COM server I want to use has a method "SendService" with two
>> paramaters, one paramter as "pass by reference" value.
>>
>> When I try the following code:
>>
>> self.__tlb=GetModule(["{C4B24B71-044F-4145-85AD-6401244686CC}",self.MajorVersion,self.MinorVersion])
>> help(self.__tlb)
>> self.__appl=CreateObject(self.APPLICATION)
>> #help(self.__appl) #->exception
>> print self.__appl.SendService("1101").Value()
>>
>>
>> I get the error:
>>
>> --- cut ---
>> File C:\Programs\Python25\Lib\site-packages\comtypes\client\dynamic.py",
>> line 37, in __call__
>> return self._obj._comobj.Invoke(self._id, *args)
>> File "C:\Programs\Python25\lib\site-packages\comtypes\automation.py",
>> line 596, in Invoke
>> byref(result), byref(excepinfo), byref(argerr))
>> _ctypes.COMError: (-2147352561, 'Parameter nicht optional.', (None,
>> None,None, 0, None))
>> --- cut ---
>>
>>
>> The generated code of:
>> C:\Programs\Python25\Lib\site-packages\comtypes\gen\_C4B24B71_044F_4145_85AD_6401244686CC_0_1_0.py
>>
>> is:
>>
>> [...]
>>
>> IAutomaticTesting._disp_methods_ = [
>> DISPMETHOD([dispid(1), helpstring(u'method SendService')], c_int,
>> 'SendService',
>>( [], BSTR, 'szBuffer' ),
>>( ['retval', 'out'], POINTER(VARIANT), 'pValue' )),
>>
>> [...]
>>
>>
>> I had the same problem with win32com. Here is the solution to use
>> gencache.EnsureModule():
>>
>> self.__early=win32com.client.gencache.EnsureModule(self.CLSID,elf.LCID,self.MajorVersion,self.MinorVersion)
>> self.__appl = win32com.client.Dispatch(self.APPLICATION)
>> self.__appl = self.__early.MyApplication(self.__appl)
>> print self.__appl.SendService("1101") #without exception
>>
>>
>> But how to do it with comtypes ?
>>
>
> It looks like your CreateObject call is returning a dispatch pointer,
> which does not expose typeinfo (or comtypes is unable to access it, for
> whatever reasons). In this case, comtypes uses dynamic dispatch calls
> from comtypes\client\dynamic.py.
>
> You could probably either QueryInterface this pointer to the
> 'IAutomaticTesting'
> interface, or you call CreateObject with the application CoClass defined
> in the generated code.
>
> Does this help?
>
> Thanks,
> Thomas
>
>
-
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users