By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,364 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,364 IT Pros & Developers. It's quick & easy.

Convert a raw pointer to IDispatch

P: n/a
Hi,

I am trying to use the function "CreateStreamOnHGlobal" from python code
(I need to pass an IStream object to MSXML, like I do in C++ code).

I was able to retrieve a pointer on the IStream object in this way:

from ctypes import *

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
print "%x"%stream.value

The problem is that I would like to attach this pointer to a python
IDispatch object (in Python only, not using a C++ DLL to do the stuff).
Do you know a way to do it ?

Thanks for your attention.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Roger That <fa********@free.fr> writes:
Hi,

I am trying to use the function "CreateStreamOnHGlobal" from python
code (I need to pass an IStream object to MSXML, like I do in C++
code).

I was able to retrieve a pointer on the IStream object in this way:

from ctypes import *

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
print "%x"%stream.value

The problem is that I would like to attach this pointer to a python
IDispatch object (in Python only, not using a C++ DLL to do the
stuff). Do you know a way to do it ?


What do you want to do with this pointer? Pass it to a function called
via ctypes?

Thomas
Jul 18 '05 #2

P: n/a
Le Thu, 17 Feb 2005 19:22:16 +0100, Thomas Heller s'est écrié:
from ctypes import *

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
print "%x"%stream.value

What do you want to do with this pointer? Pass it to a function called via
ctypes?


Once it is a IDispatch object (like the IDispatch object returned by
"win32com.client.Dispatch"), I will call the IStream methods on it and
pass it to a DOMDocument of MSXML. It should look like that:

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
stream_obj = some_conversion(stream)
# IDispatch call
stream_obj.Write("some data", 9)

doc = win32com.client.Dispatch("MSXML2.DOMDocument.4.0")
doc.load(stream_obj)
Jul 18 '05 #3

P: n/a
Le Thu, 17 Feb 2005 19:22:16 +0100, Thomas Heller a écrit*:
I am trying to use the function "CreateStreamOnHGlobal" from python code
(I need to pass an IStream object to MSXML, like I do in C++ code).

I was able to retrieve a pointer on the IStream object in this way:

from ctypes import *

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
print "%x"%stream.value

The problem is that I would like to attach this pointer to a python
IDispatch object (in Python only, not using a C++ DLL to do the stuff).
Do you know a way to do it ?


What do you want to do with this pointer? Pass it to a function called via
ctypes?

Once it is a IDispatch object (like the IDispatch object returned by
"win32com.client.Dispatch"), I will call the IStream methods on it and
pass it to a DOMDocument of MSXML. It should look like that:

stream = c_int()
windll.ole32.CreateStreamOnHGlobal(c_long(0), c_long(1), byref(stream))
stream_obj = some_conversion(stream)
# IDispatch call
stream_obj.Write("some data", 9)

doc = win32com.client.Dispatch("MSXML2.DOMDocument.4.0")
doc.load(stream_obj)

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.