Problem with access to shared memory(W2K) SOLVED
Claudio Grondi
claudio.grondi at freenet.de
Fri Apr 8 08:27:26 EDT 2005
I have got a solution to my problem from Thomas Heller by email.
The problem was solved by using .from_address() instead of
causing trouble cast() - here the solution as a generalized
example of code for reading access to shared memory area
with given 'appropriateName':
from ctypes import *
FILE_MAP_READ = 2
strNameOfSharedMemoryAreaToAccess = 'appropriateName'
handle = windll.kernel32.OpenFileMappingA(
FILE_MAP_READ
, 0
, strNameOfSharedMemoryAreaToAccess
)
if not handle:
raise WinError()
addr = windll.kernel32.MapViewOfFile(
handle
,FILE_MAP_READ
,0
,0
,0
)
if not addr:
raise WinError()
class structureOfSharedMemoryArea(Structure):
_fields_ = [
("Elem01" , c_short ) # or any other ctype or ctype structure
("Elem02" , c_long )
...
("ElemNN" , c_long )
]
contentOfSharedMemoryArea = structureOfSharedMemoryArea.from_address(addr)
print 'Elem01 ', contentOfSharedMemoryArea.Elem01
print 'Elem02 ', contentOfSharedMemoryArea.Elem02
...
print 'ElemNN ', contentOfSharedMemoryArea.ElemNN
Claudio
More information about the Python-list
mailing list