Hi Thomas,

On 19 Dec 2013, at 11:46, Thomas Heller 
<thel...@ctypes.org<mailto:thel...@ctypes.org>> wrote:

Am 18.12.2013 09:49, schrieb Wedel, Jan:
Hi,

I already wrote to this mailing list ("Serious problem with
RPC_E_SERVERFAULT (0x80010105)") last year.

Unfortunately but understandably, Thomas Heller stopped supporting
comtypes actively. However, I saw there was some development going on in
terms of a new release, so I wanted to bump this topic because we
couldn't find a solution yet.

Let me sum up the issue and what we've found out so far:

- We've written an OPC (OLE for Process Control) COM Server in Python

- The existing version of this server works perfectly for over a year on
a Win XP machine

- Because XP is quite old and not supported anymore, we needed to move
on to Win 7 / Server 2008

- On these recent OSes, the server stopped working

- It actually starts and responds to some method calls. But, when a
method needs to return a pointer to an array of structures, the client
receives the COM error 0x80010105

- The server continues running.

- We've modified the code to use the low-level comtypes implementation
so that the client actually receives the server response without an
error. But, unfortunately, the response is corrupted (the first two
bytes of the array are overwritten).

- We assumed memory being unintentionally freed because we're returning
a pointer but not the actual array.

Hm, as far as I know you cannot pass arbitrary pointers via COM.
At least not in automation compatible interfaces.  Or do you do
some custom marshalling?

It’s not automation compatible. It an OPC DA 2.0 compatible COM server used as 
a data source for SCADA systems.

Yesterday, in the evening, I actually found a solution (at least I believe it). 
I’ve written some more precise description on StackOverflow:
http://stackoverflow.com/questions/20546303/ctypes-memory-management-when-returning-pointers-in-com-server

But the summary is:

I had to explicitly allocate memory with windll.ole32.CoTaskMemAlloc for 
anything that is returned by pointer like strings, pointers to structs, pointer 
to arrays of structs.

I saw some C++ implementation that called that function for a pointer to an 
array so I was wandering if com types is doing it. So I found out that it’s 
actually not.

In one of your test cases, I saw one function that creates a COM string with 
this function so I used that as a base for the other allocations I needed 
(structs, arrays). See StackOverflow for the code.

I thought that com types is actually handling that for me by allocating memory 
for everything that is returned.

The most interesting thing is that the code worked on XP without allocation. 
But on the MSDN forum, they told me that they’d changed that memory manager in 
Windows 7 /Server 2003.

Do you think the approach is correct or do see any obvious problems with that?

Thanks Jan


- We modified the python code to keep a reference to the array but then
the client again gets the same COM error 0x80010105

- We've debugged the issue with a windows debugger (see stack trace from
the old mail) and it seems as if an access violation happens when ctypes
calls CoTaskMemFree internally.

Thomas



------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to