Closed
Description
Hello,
I try to use the following snippet from this page to turn a byte[]
into a numpy array:
from ctypes import string_at
clr.AddReference("System.Runtime.InteropServices")
from System.Runtime.InteropServices import GCHandle, GCHandleType
handler = GCHandle.Alloc(CSArray, GCHandleType.Pinned)
try:
pointer = handler.AddrOfPinnedObject().ToInt32()
dest = np.fromstring(string_at(pointer, len(CSArray)))
finally:
if handler.IsAllocated: handler.Free()
On this line:
handler = GCHandle.Alloc(CSArray, GCHandleType.Pinned)
I get the following error: TypeError: No method matches given arguments
Executing this code:
handler = GCHandle.Alloc(CSArray)
brings no error, so I assume that the issue must be from GCHandleType.Pinned
.
I'm a bit troubled by:
print(type(GCHandleType.Pinned))
>>>int
print(GCHandleType.Pinned)
>>>3
Is it normal that enum
are modeled by int
?
Anyway, I can't get to have my code working...
Metadata
Metadata
Assignees
Labels
No labels