Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Error with Enum GCHandleType.Pinned #174

Copy link
Copy link
@aPere3

Description

@aPere3
Issue body actions

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 enumare modeled by int?

Anyway, I can't get to have my code working...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.