473,411 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Convert a raw pointer to IDispatch

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
3 2758
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Sparago | last post by:
I am working with the MSHTML editor control. I used win32com.client.gencache.EnsureModule on the MSHTML type library to generate the necessary IDispatch support for all the various interfaces used...
10
by: Simon | last post by:
I'm a js newbie trying to use some very simple js to call an ActiveX object's methods. I need to use a pointer to call an embedded ActiveX object's method to receive a number. As I understand it,...
5
by: Dominic Godin | last post by:
Hi, I have decleared the IDispatch interface but I'm having trouble using it. Word.Application MSWord = new Word.ApplicationClass(); IDispatch wb = (IDispatch)MSWord.WordBasic; int lcid =...
1
by: Dmitry Medvedev | last post by:
Hello, I need to write C# class, that would implement IDispatch interface to be used in ActiveScript. I can't use IReflect interface here due to design issues, I need to handle GetIDsOfNames...
4
by: Phil Coveney | last post by:
Hello, I am implementing a class in C# that wraps an automation server and am stuck on something basic. Using the following code fragment: using System; using System.Runtime.InteropServices;...
0
by: Jim Hubbard | last post by:
How would I implement the IDispatch interface to handle the following in VB.Net <BEGIN> Controlling Download and Execution The WebBrowser Control gives you control over what it downloads,...
3
by: ZhaoYingpu | last post by:
Hello,all I am using win32com to use com. and invoke a method as follows: void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp); but i pass 0 or None to third parameter and get error info:...
0
by: Brad Johnson | last post by:
I have a C++ application that creates a collection of COM objects. I would like to give the Python interpreter access to these interfaces that were created in C++ land. Stated another way, how...
3
by: Huayang Xia | last post by:
I am trying to use ctypes to call dll functions. One of the functions requires argument "struct IDispatch* ". I do have a PyIDispatch object in python. How can I convert this "PyIDispatch object"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.