Re: [comtypes-users] in,out parameters in comtypes 0.5 (trunk)

2008-07-30 Thread Thomas Heller
MR Michael Robellard (5314) schrieb:
> Hello,
>  
> I am trying to implement the IURLSearchHook2 interface in comtypes and I
> am running into some issues.
>  

> which generate the following in the comtypes.gen .py files:
> class IURLSearchHook2(IURLSearchHook):
> _case_insensitive_ = True
> _iid_ = GUID('{5EE44DA4-6D32-46E3-86BC-07540DEDD0E0}')
> _idlflags_ = []
> IURLSearchHook2._methods_ = [
> COMMETHOD([], HRESULT, 'TranslateWithSearchContext',
>   ( ['in', 'out'], WSTRING, 'lpwszSearchURL' ),
>   ( ['in'], c_ulong, 'cchBufferSize' ),
>   ( ['in'], POINTER(ISearchContext), 'pSearchContext' )),
> ]

> I can get the data into the method and print it out fine.
> The problem is when I try and return a string out. It just plain hangs.
> If anyone has any thoughts. Is this even possible?
> I have tried both the "high level" and "low level" approach as discussed
> in Thomas' recent post

Mike, here are my thoughts on your problem.

The high level comtypes method implementation can only work for 
automation-compatible
argument types, and WSTRING is not one of those.

WSTRING is defined as c_wchar_p in the generated file.

c_wchar_p is interpreted as a zero-terminated wide character string,
but what COM really passes is a buffer with space for 'cchBufferSize' wide 
characters.
Which contains a zero-terminated string that you are supposed to change.

comtypes assumes c_wchar_p as 'const' strings which you cannot/should not 
change.

I think you should change the 'TranslateWithSearchContext' method definition
to something like this:


> IURLSearchHook2._methods_ = [
> COMMETHOD([], HRESULT, 'TranslateWithSearchContext',
>   ( ['in', 'out'], POINTER(c_wchar), 'lpwszSearchURL' ),
>   ( ['in'], c_ulong, 'cchBufferSize' ),
>   ( ['in'], POINTER(ISearchContext), 'pSearchContext' )),
> ]

and write the (low-level) implementation like so:

def TranslateWithSearchContext(self, this, lpwszSearchURL, cchBufferSize, 
pSearchContext):
# lpwszSearchURL is a POINTER(c_wchar) instance.
rawdata = lpwszSearchURL[:cchBufferSize]
# rawdata is now a unicode string of length cchBufferSize, filled with 
NUL characters
# at the end.  The [in] unicode string can probably be get by this:
url = rawdata.split('\0')[0]

# Maybe ctypes.wstring_at(lpwszSearchURL) would also work.

# The [out] string must be written into the lpwszSearchURL buffer, 
maybe this works:
lpwszSearchURL[:cchBufferSize] = '\0' * cchBufferSize # clear it
urlout = "http://web.somewhere.whatdoIknow";
lpwszSearchURL[:len(urlout)] = urlout
return S_OK

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=100&url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] in,out parameters in comtypes 0.5 (trunk)

2008-07-30 Thread Thomas Heller
MR Michael Robellard (5314) schrieb:
>  
> Thomas,
> 
> Here is the script and the parts of the idl file that are relevant for
> the problem.
> 

Mike, I have changed the code you sent me so that I can try it (it is attached).
Removed unneeded imports, adapted the logging, and so on.
Called 'python lilwsearch.py /regserver' to register the server.
Then, I added this value to the registry:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\URLSearchHooks]
"{0BC6E3FA-78EF-4886-842C-5A1258C4455A}"=""


Hope that's the correct registry entry.
Fired up Internet Explorer (version 7, but I've also tried version 6 on another 
machine).
Entered something like "foo bar" in the address field and pressed enter.
According to the log file, the search object is created.
But:  I see only a QueryInterface call for IURLSearchHook, not for 
IURLSearchHook2.
And nothing more.  It seems IE also hangs (well it works, I can browse in 
internet,
but closing the GUI does not end the process).  Do you get more in the 
log-file?  Did
I do the registry entries correctly?  Which comtypes and Python version do you 
use?

Here is what I see:

DEBUG:comtypes.server.inprocserver:Found class 
DEBUG:comtypes._comobject:.QueryInterface({0001---C000-0046}) -> S_OK
DEBUG:comtypes._comobject:1 active COM objects: Added   

DEBUG:comtypes._comobject:.AddRef() -> 1
DEBUG:comtypes.server.inprocserver:DllGetClassObject() -> 0
DEBUG:comtypes.server.inprocserver:ClassFactory.CreateInstance({AC60F6A0-0FD9-11D0-99CB-00C04FD64497})
DEBUG:comtypes._comobject:: 
IURLSearchHook.Translate not implemented
DEBUG:comtypes._comobject:.QueryInterface({AC60F6A0-0FD9-11D0-99CB-00C04FD64497}) -> S_OK
DEBUG:comtypes._comobject:2 active COM objects: Added   

DEBUG:comtypes._comobject:.AddRef() -> 1
DEBUG:comtypes.server.inprocserver:CreateInstance() -> 0
DEBUG:comtypes._comobject:.AddRef() -> 2
DEBUG:comtypes._comobject:.Release() -> 1
DEBUG:comtypes._comobject:.Release() -> 0
DEBUG:comtypes._comobject:1 active COM objects: Removed 

DEBUG:comtypes._comobject:.QueryInterface({AC60F6A0-0FD9-11D0-99CB-00C04FD64497}) -> S_OK
DEBUG:comtypes._comobject:.AddRef() -> 2
DEBUG:comtypes._comobject:.Release() -> 1

Since I apparently cannot debug this myself for whatever reasons, see the other 
post
for suggestions.

Thanks,
Thomas


lilwsearchhook.py
Description: application/python
-
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=100&url=/___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] How to register a comtypes dll with py2exe

2008-07-30 Thread Thomas Heller
MR Michael Robellard (5314) schrieb:
> Everyone,
>  
> We were having trouble registering a comtypes dll we generated using
> py2exe. However with this little change to boot_ctypes_com_server.py you
> can easily get you comtypes COM dlls to register when you create a
> ctypes dll in py2exe.

Which version of py2exe are you using?  I think that the latest one 0.6.8
should work out of the box (but I have to check).

-- 
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=100&url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users


Re: [comtypes-users] problem after packaging with py2exe

2008-07-30 Thread Thomas Heller
Kelie schrieb:
> Hello,
> 
> I wrote a simple script which uses comtypes. When I run it the first time, it
> takes some time to generate the module(s) (in the comtypes/gen directory), 
> which
> is normal.

comtypes creates the modules on the first time they are needed (which is usually
when you call comtypes.client.CreateObject("MyProgId").  If possible, they are 
written
into the comtypes\gen directory.

> When I run the code again, the step of generating module(s) is
> skipped.

Because they are now found in the comtypes\gen directory.

> But after I package the program into an executable with py2exe, it
> re-generates the module(s) every time I run the exe.

Apparently the modules in comtypes\gen have not been included into the exe,
so comtypes needs to generate them again.  Now, since in the exe the comtypes
library is inside the zipfile (library.zip or so), comtypes cannot write
the generated code into the zipfile; the code is only kept in memory.
and it has to be generated again each time your exe runs.

> Apparently it is not the
> case using PyWin32, or at least I cannot notice the delay.

PyWin32 generates the code (if any) into a writeable directory
somewhere else - I will change comtypes to also use another directory
in a future version as well so that generated code can be cached in the 
filesystem
even for a py2exe'd program.

> I'm not sure if this
> is related to its dynamic IDispatch feature that Michael mentioned in this 
> post:
> http://article.gmane.org/gmane.comp.python.comtypes.user/192.
Not really.  Michael wants comtypes to work without generating code at all (for 
some
objects, at least).



Here's a walkthrough with a simple comtypes client program.
This script creates a JScript interpreter and uses it to
evaluate and print a JScript expression:


Re: [comtypes-users] problem after packaging with py2exe

2008-07-30 Thread Kelie
MR Michael Robellard (5314 <[EMAIL PROTECTED]> writes:
>
> Try something like this
>
> # Create the wrapper in the comtypes.gen package, it will be named
> # AGCoreLib; the name is derived from the 'library ' statement
> # in the IDL file
> if not (hasattr(sys, "frozen") or "python25.zip" in __file__):
> # pathname of the type library file
> tlbfile = os.path.join(os.path.dirname(__file__), "lilw.tlb")
> # if running as frozen app (dll or exe), the wrapper should be in
> # the library archive, so we don't need to generate it.
> comtypes.client.GetModule(tlbfile)
 
Thanks Michael. I suppose I need to change "lilw.tlb" to some other tlb file?
This is what I see in the generated module:
typelib_path = u'C:\\Program Files\\Common Files\\Autodesk 
Shared\\acax17enu.tlb'
So, I need copy file acax17enu.tlb into comtypes/gen directory and replace
"lilw.tlb" with "acax17enu.tlb"?
 
> # Import the wrapper
> from comtypes.gen import AGCoreLib
>
 
Where do I put this line? In the program I wrote? If so, where is AGCoreLib used
after being imported?


-
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=100&url=/
___
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users