[python-win32] How to create a com_record?

Kevin Patterson patter001 at gmail.com
Mon Feb 4 18:06:52 CET 2008


(adding win32  list back in in case someone know more about GetType)

Yeah, that's a good way for getting/setting the data. The hangup is:

guid = win32com.client.Record("GUID", some_ob)

I don't have the some_obj that allows me to build "GUID". From looking
through the code it seems that GUID has to be exposed by the COM (which it
is not) for that function call to work.

VB.NET (GetType) and C++ (__uuid) both already know that a GUID is a
record.  It seems the python CLSID is the same thing, but i don't know what
to call to get a CLSID that is a com_record type.

Am I understanding the win32com.client.Record call correctly? It needs GUID
to be defined by the COM right? It's not something that I can define within
the python code? The other choice appears to be to call
pythoncom.GetRecordByTypeInfo directly, but I can't figure out how to make
that work without the COM exposing the GUID as well.

Its odd b/c the GIUD (python's CLSID) is all over the COM definitions its
just type VT_RECORD type that I'm not understanding how to convert to.


On Feb 3, 2008 10:33 PM, Mark Hammond <mhammond at skippinet.com.au> wrote:

>  Something like:
>
>
>
> >>> struct.unpack("ihh8b", buffer(pythoncom.IID_IUnknown))
>
> (0, 0, 0, -64, 0, 0, 0, 0, 0, 0, 70)
>
> >>>
>
>
>
> Might help?
>
>
>
> I'm not quite sure how the BYTE[] array will be handled, but maybe
> something like:
>
>
>
> >>> struct.unpack("ihh8s", buffer(pythoncom.IID_IUnknown))
>
> (0, 0, 0, '\xc0\x00\x00\x00\x00\x00\x00F')
>
>
>
> would be better if a string was necessary.  Specifically, you would say:
>
>
>
> guid = win32com.client.Record("GUID", some_ob)
>
> d1, d2, d3, d4 = struct.unpack("ihh8s", buffer(pythoncom.IID_IUnknown))
>
> guid.Data1 = d1
>
> guid.Data2 = d2
>
> etc
>
>
>
>
>
> Mark
>
>
>
> *From:* Kevin Patterson [mailto:patter001 at gmail.com]
> *Sent:* Monday, 4 February 2008 1:59 PM
>
> *To:* Mark Hammond
> *Subject:* Re: [python-win32] How to create a com_record?
>
>
>
> Yeah, I'll try to rename some of the variables and post to the list.
>
> The GUID is the record. It is a struct defined like below (its the same as
> the CLSID in the makepy generated file). The trick/problem is how to turn it
> in to a VT_RECORD.
>
> typedef struct _GUID {
>
>   DWORD Data1;
>
>   WORD Data2;
>
>   WORD Data3;
>
>   BYTE Data4[8];
>
> } GUID;
>
>
>
> On Feb 3, 2008 5:38 PM, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> I'm afraid I don't know what GetType() does, but the record seems to have
> an element named GUID.  Maybe you could post this info to the mailing list,
> where someone might know more than me about VB.
>
>
>
> Thanks,
>
>
>
> Mark
>
>
>
> *From:* Kevin Patterson [mailto:patter001 at gmail.com]
> *Sent:* Monday, 4 February 2008 5:44 AM
>
>
> *To:* Mark Hammond
> *Subject:* Re: [python-win32] How to create a com_record?
>
>
>
> Here's how the COM is accessed in VB.NET...The GetInterface is the
> function I'm trying to use. It is the one looking for a VT_RECORD. I'm
> assuming the GetType is a standard VB.NET function.  I don't have a
> complete C++ example, but the one snippet I saw of C++ used something like:
> __uuidof(ILib.IApi) as the parameter to GetInterface function.
>
> [VB.Net]
> Dim myinstance As AccessManagerLib.Instance ' Obtained earlier
> Dim myapi As ILib.IApi
> Try
>     myapi = myinstance.GetInterface(GetType(ILib.IApi).GUID)
>     ' Do something with myapi
>     myapi = Nothing ' Release interface when done
> End Try
>
> On Feb 2, 2008 10:59 PM, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> I don't think you can pass an arbitrary buffer as a COM record - you will
> need to find the name and type of the element in the record.  Do you have
> example code for any other language?
>
>
>
> Mark
>
>
>
> *From:* Kevin Patterson [mailto:patter001 at gmail.com]
> *Sent:* Friday, 1 February 2008 10:50 PM
> *To:* Mark Hammond
> *Subject:* Re: [python-win32] How to create a com_record?
>
>
>
> Thanks Mark. I'll dig around the various windows typelilbs and see if one
> of them has a GUID structure.
>
> If I know the order of the structure myself (and know how to turn in to a
> buffer) do you know how I could convert the buffer in to a com_record ?
>
> On Feb 1, 2008 12:34 AM, Mark Hammond <mhammond at skippinet.com.au> wrote:
>
> The record will be defined in a typelib somewhere, and have named
> elements.  For example, the win32com test VB code:
>
>
>
> Public Type VBStruct
>
>     int_val As Integer
>
>     str_val As String
>
>     ob_val As Object
>
>     sub_val As SubStruct
>
> End Type
>
>
>
> And VB arranges for that to become a COM record.  Python code can then
> say:
>
>
>
>     s = win32com.client.Record("VBStruct", vbtest)
>
>     s.int_val = -1
>
>
>
> (Where vbtest in the first line is a COM object that comes from the same
> typelib which defines the struct).  The object 's' can then be passed as a
> param, where it will become VT_RECORD.  Without knowing how the struct is
> defined in your case I can't speculate how a GUID would be carried.  If it
> was a simply array of bytes, then using 'buffer(guid)' will give you the raw
> bytes.
>
>
>
> Cheers,
>
>
>
> Mark
>
>
>
> *From:* python-win32-bounces at python.org [mailto:
> python-win32-bounces at python.org] *On Behalf Of *Kevin Patterson
> *Sent:* Friday, 1 February 2008 2:34 PM
> *To:* python-win32 at python.org
> *Subject:* [python-win32] How to create a com_record?
>
>
>
> I have a COM server that is expecting a GUID as an argument. The generated
> makepy shows that the function is expecting a VT_RECORD. I cannot seem to
> pass in the CLSID, I get the following:
>
> TypeError: Only com_record objects can be used as records
>
> I looked at the win32com.client.Record function, but it looks like it will
> create another COM object if I give it the GUID.What I really need is to
> pass the GUID in to this function as a sort of structure.  I "think" I have
> to build a struct (using the struct class?) turn it into a buffer and then
> somehow convert this to a Record object....Trouble is I can't find any
> documentation on com_record objects anywhere....Any ideas?
>
> Thanks,
> Kevin
>
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080204/88101f63/attachment.htm 


More information about the python-win32 mailing list