Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Markus Gritsch
Hi,

just to let you know: I gave up on creating .lnk files using comtypes
and instead use .url files with a local address.  For my application
placing such a file in the Windows startup folder they works just
fine, and have the huge advantage of being simple text files.

Thanks again for the help,
Markus

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Tim Golden
Markus Gritsch wrote:
 Hi,
 
 just to let you know: I gave up on creating .lnk files using comtypes
 and instead use .url files with a local address.  For my application
 placing such a file in the Windows startup folder they works just
 fine, and have the huge advantage of being simple text files.

Sorry I haven't been much help here. I'm deep in the middle
of something else or else I'd probably have knocked something
up for you. For the record, is there a particular reason why
you can't just use one of the pywin32 solutions?

TJG

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Thomas Heller
Martin (gzlist) schrieb:
 On 03/11/2008, Markus Gritsch [EMAIL PROTECTED] wrote:
 Hi,

  I would like to create shell links (.lnk) from my Python program.
  ...
  It would be very nice, if someone could give me any advice
  how to do this using comtypes.
 
 When I wanted to do this in a hurry and didn't have time to look up
 the right way to do it, I ended up with code something like:
 
 import comtypes
 from comtypes.client import CreateObject
 ws = CreateObject(WScript.Shell)
 from comtypes.gen import IWshRuntimeLibrary
 shortcut = comtypes.cast(ws.CreateShortcut(test_shortcut.lnk),
 comtypes.POINTER(IWshRuntimeLibrary.IWshShortcut))
 shortcut.TargetPath = cmd.exe
 shortcut.Arguments = /K C:\Python24\python.exe
 shortcut.Save()
 
 This worked for me, but may be bad practice or generally bogus in some
 way or other.
 
 I think I got there by reading
 http://www.ironpython.info/index.php/Creating_a_Shortcut_File_with_WSH_Interop
 then looking at the comtypes generated code, then poking things until
 it stopped throwing exceptions.

Cool!  The only thing I would suggest to change
is to use QueryInterface instead of cast:

 import comtypes
 from comtypes.client import CreateObject
 ws = CreateObject(WScript.Shell)
 from comtypes.gen import IWshRuntimeLibrary
  shortcut = 
ws.CreateShortcut(test_shortcut.lnk).QueryInterface(IWshRuntimeLibrary.IWshShortcut)
 shortcut.TargetPath = cmd.exe
 shortcut.Arguments = /K C:\Python24\python.exe
 shortcut.Save()

-- 
Thanks,
Thomas


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Thomas Heller
Markus Gritsch schrieb:
 Hi,
 
 just to let you know: I gave up on creating .lnk files using comtypes
 and instead use .url files with a local address.  For my application
 placing such a file in the Windows startup folder they works just
 fine, and have the huge advantage of being simple text files.

Does the solution that Martin posted not work for you?

-- 
Thanks,
Thomas


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Martin (gzlist)
On 05/11/2008, Thomas Heller [EMAIL PROTECTED] wrote:

 Cool!  The only thing I would suggest to change
  is to use QueryInterface instead of cast:

Aha. Thanks, thought there must be an easier way of doing that.

On 05/11/2008, Markus Gritsch [EMAIL PROTECTED] wrote:
 On Wed, Nov 5, 2008 at 1:19 PM, Thomas Heller [EMAIL PROTECTED] wrote:
  
   Does the solution that Martin posted not work for you?


 I am developing on a Windows XP machine, but test the py2exe-packed
  binaries also on Windows 2000 and Windows 98 virtual machines.

You'll be pleased to hear then that I just tried it on a real win98se
box, with python 2.4.4/ctypes 1.0.2/comtypes 0.5.2 and it worked fine
(after swapping cmd.exe for command.com that is).

  Traceback (most recent call last):

   File test.py, line 5, in module
  AttributeError: 'POINTER(IUnknown)' object has no attribute 'CreateShortcut'

Obvious stab-in-the-dark here, try:

 from comtypes.gen import IWshRuntimeLibrary
+ws = ws.QueryInterface(IWshRuntimeLibrary.IWshShell2)
 shortcut = ws.CreateShortcut(test_shortcut.lnk).QueryInterface(
IWshRuntimeLibrary.IWshShortcut)

Also make sure you're on the latest comtypes version, I vaugely
remember the code generator messing me around a bit before I upgraded
(to 0.4.2 that would have been, though).

  Maybe the version of the Windows Script Host installed there is too
  old to contain the CreateShortcut functionality.  Therefore I would
  prefer not to depend on the Windows Script Host.

This strikes me as a misdiagnosis, problem looks to be with the
generated interface, not the underlying library in win98.

Martin

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] Creating Shell Links using comtypes

2008-11-05 Thread Thomas Heller
Markus Gritsch schrieb:
 Hi,
 
 I would like to create shell links (.lnk) from my Python program.  I
 found the following solution at [1] which uses win32com:
 
 import os, sys
 import pythoncom
 from win32com.shell import shell, shellcon
 
 shortcut = pythoncom.CoCreateInstance (
   shell.CLSID_ShellLink,
   None,
   pythoncom.CLSCTX_INPROC_SERVER,
   shell.IID_IShellLink
 )
 shortcut.SetPath (sys.executable)
 shortcut.SetDescription (Python %s % sys.version)
 shortcut.SetIconLocation (sys.executable, 0)
 
 desktop_path = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
 persist_file = shortcut.QueryInterface (pythoncom.IID_IPersistFile)
 persist_file.Save (os.path.join (desktop_path, python.lnk), 0)
 
 I was trying to translate this to comtypes, but had absolutely no
 success.  It would be very nice, if someone could give me any advice
 how to do this using comtypes.

I have now bit the bullet and implemented the IPersistFile (in 
comtypes.persist),
IShellLinkA, IShellLinkW interfaces plus the ShellLink coclass in comtypes SVN.
A usage example is at the bottom of the comtypes.shelllink file:

http://comtypes.svn.sourceforge.net/viewvc/comtypes/trunk/comtypes/shelllink.py?revision=457view=markup

Thomas


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] interpreting idl files: [out] is actually an [in], is there something we can do?

2008-11-05 Thread Thomas Heller
Torbjorn Tyridal schrieb:
 Hi, I have another one for you:
 
 from the idl file (oleview)
 
 interface ISoftUSBEndpointEvents : IUnknown {
 
 ...
 
 [helpstring(Fired when an IN transaction is received from the host.
 Allows device simulator to directly return data to host controller for
 the transaction.), helpcontext(0x06bd)] HRESULT _stdcall
 OnReadTransfer(
 
 [in] unsigned char DataToggle,
 
 [out] unsigned char* pbDataBuffer,
 
 [in] unsigned long cbDataBuffer,
 
 [out] unsigned long* cbDataWritten,
 
 [out] unsigned char* pbStatus);
 
 
 
 Note the [out] unsigned char* pbDataBuffer, while we compare this to
 microsoft documentation for ISoftUSBEndpointEvents::OnReadTransfer,
 and especially the given example
 (http://msdn.microsoft.com/en-us/library/bb201520.aspx)
 
 STDMETHODIMP CSoftUSBEndpointEvent::OnReadTransfer(__in BYTE DataToggle,
 __in_bcount(cbDataBuffer) BYTE *pbDataBuffer,
 __in ULONG  cbDataBuffer,
 __out ULONG  *cbDataWritten,
 __out BYTE *pbStatus)
 
 
 That [out] has now become an __in because the caller allocates the buffer.

As far as I understand this, '__in_bcount(cbDataBuffer) BYTE *pdDataBuffer' is
MS' SAL (source code annotation language).  It means that the caller has to 
supply
a buffer of 'cdDataBuffer' length, the callee will fill it, and the contents
will be returned (that is the 'out' value then).

There is a somewhat similar notation in the IDL files for COM (size_is, 
length_is, and so on),
but type libraries have no way to represent this information.  The MIDL 
compiler, when it
compiles an IDL file uses this info to generate marshalling C/C++ code that can 
be
used to create proxy dlls for COM object.

However, comtypes has no way to use this annotation simply because it is not in 
the
typelib, as I said before.

 is there something (else than editing the generated file) I can do to
 solve this?
 

Are you calling this method, or are you implementing it with comtypes?
(Since it is an event interface, I assume the latter.)

If *calling* this method, you should not call the obj.OnReadTransfer(...) 
method,
instead you should call the low level obj.__com_OnReadTransfer(...) method which
is also created at runtime by comtypes' metaclasses.  See, as one example, the
QueryInterface implementation in comtypes\__init__.py:

class IUnknown(object):

def QueryInterface(self, interface, iid=None):
QueryInterface(interface) - instance
p = POINTER(interface)()
if iid is None:
iid = interface._iid_
self.__com_QueryInterface(byref(iid), byref(p))
clsid = self.__dict__.get('__clsid')
if clsid is not None:
p.__dict__['__clsid'] = clsid
return p


If you are *implementing* this method - is there a problem at all?
The caller HAS already allocated the buffer, you only have to fill it.
Anyway, if you have special requirements that can not be fullfilled by
the 'high level' method implementation then you should use the 'low level'
implementation; I have posted several times about them.

Thomas


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] PATCH accepting interleaved [out] and [in] arguments (on event handlers)

2008-11-05 Thread Thomas Heller
Torbjorn Tyridal schrieb:
 Oh well.. Here it is anyway..

Many thanks for the patch.  I will create additional unittests
for the new behaviour and eventually commit it.

 The asumtion that [out] arguments are placed after [in] arguments
 proved false, here is a patch that accepts arguments in any order.
 
 ==
 --- comtypes-0.5.2\_comobject.py  Fri Sep 19 21:49:50 2008
 +++ comtypes\_comobject.pyWed Oct 29 22:04:20 2008
 @@ -89,34 +89,44 @@ def hack(inst, mth, paramflags, interfac
  # An argument is an input arg either if flags are NOT set in the
  # idl file, or if the flags contain 'in'. In other words, the
  # direction flag is either exactly '0' or has the '1' bit set:
 -args_in = len([f for f in dirflags if (f == 0) or (f  1)])
 -# number of output arguments:
 -args_out = len([f for f in dirflags if f  2])
 +# Output arguments have flag '2'
 +
 +args_out_idx=[]
 +args_in_idx=[]
 +for i,a in enumerate(dirflags):
 +if a2:
 +args_out_idx.append(i)
 +if a1 or a==0:
 +args_in_idx.append(i)
 +args_out = len(args_out_idx)
 +
  ## XXX Remove this:
  ##if args_in != code.co_argcount - 1:
  ##return catch_errors(inst, mth, interface, mthname)
 -# This code assumes that input args are always first, and output
 -# args are always last.  Have to check with the IDL docs if this
 -# is always correct.
 
  clsid = getattr(inst, _reg_clsid_, None)
  def call_without_this(this, *args):
 -outargs = args[len(args)-args_out:]
  # Method implementations could check for and return E_POINTER
  # themselves.  Or an error will be raised when
  # 'outargs[i][0] = value' is executed.
  ##for a in outargs:
  ##if not a:
  ##return E_POINTER
 +
 +#make argument list for handler by index array built above
 +inargs=[]
 +for a in args_in_idx:
 +inargs.append(args[a])
 +
  try:
 -result = mth(*args[:args_in])
 +result = mth(*inargs)
  if args_out == 1:
 -outargs[0][0] = result
 +args[args_out_idx[0]][0] = result
  elif args_out != 0:
  if len(result) != args_out:
  raise ValueError(Method should have returned a
 %s-tuple % args_out)
  for i, value in enumerate(result):
 -outargs[i][0] = value
 +args[args_out_idx[i]][0] = value
  except ReturnHRESULT, (hresult, text):
  return ReportError(text, iid=interface._iid_,
 clsid=clsid, hresult=hresult)
  except COMError, (hr, text, details):
 
 


-- 
Thanks,
Thomas


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users