You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HI I am trying to convert some C# code and have run into an issue when trying to marshal a structure pointer. So as an example here is the C# psuedo code:
[StructLayout(LayoutKind.Sequential)]publicstructEXAMPLE_StTRUCT{publicushortVar1;publicushortVar2;}IntPtrpStruct;<dosomestuff to get the correct ptr>
Struct =Marshal.PtrToStructure<EXAMPLE_STRUCT>(pStruct);
I have been using Ctypes.Structure in previous projects without having many problems but it appears that Marshall.PtrtoStructure can't get the layout information with those. StructLayout does not appear to be importable directly so I have imported StructLayoutAttribute which seems like the correct thing but I haven't figured out to be able to build the struct still. I have tried applying it as a decorator like:
but when I call Marshal.PtrToStructure(pStruct, EXAMPLE_STRUCT) I still get an error about my struct needing to be blittable. Thanks for the help y'all are a great community.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
HI I am trying to convert some C# code and have run into an issue when trying to marshal a structure pointer. So as an example here is the C# psuedo code:
I have been using Ctypes.Structure in previous projects without having many problems but it appears that
Marshall.PtrtoStructure
can't get the layout information with those.StructLayout
does not appear to be importable directly so I have importedStructLayoutAttribute
which seems like the correct thing but I haven't figured out to be able to build the struct still. I have tried applying it as a decorator like:but that throws an error about StructLayoutAttribute not being callable. I have also tried:
but that fails with an error about the meta class which leads me to believe I need to do something like:
but when I call
Marshal.PtrToStructure(pStruct, EXAMPLE_STRUCT)
I still get an error about my struct needing to be blittable. Thanks for the help y'all are a great community.Beta Was this translation helpful? Give feedback.
All reactions