c# - Unions of fixed size structures for use in safe context -
I am working with packets which I can receive or send as a byte array, which has a fixed structure Therefore, I am trying to create an effective union in the form of:
Using the system; // etc .. Nameslace WindowsApplication1 {Public partial class main: form {public const int PktMaxSize = 124; // ... etc ... // ... will use the Pkt structure below ...} [system. time. Interop Search Structure Layout (LayoutCind.exe)] Public Structure Pkt {[System.Runtime.InteropServices.FieldOffset (0)] Fixed Byte Bytes [Main.PktMaxSize]; // complete byte PKT [System.Runtime.InteropServices.FieldOffset (0)] fixed byte PktID [8]; [System.Runtime.InteropServices.FieldOffset (8)] UInt16 properties; // ... etc ..}}
I get a C # error
The signal and size buffers should be used only in an unsafe context
What do I need to do to create and use "unsafe" structures in a secure env?
Thanks for your help - How to open packet structures for any suggestions, which can be easily changed with a fixed byte stream, which is sent by (or sent by C + + interop class Gaya) can be obtained.
pct and
[Layout layout] Public insecure structure PKT [[Field Offset (0)] Fixed Byte Bytes [124] ; ...}
If you do not want to use insecure code, you can declare Pkt
as follows:
< Code> [structure layout (layout kick)] Public Structure PKT [[Marshal AS (unmanaged type, Bevalre, size console = 124)] [field offset (0)] byte [] bytes; [Marshall AS (unmanaged type. Bevalre, shape consonant = 8)] [field offset (0)] byte [] PktID; [Field Offset (8)] UInt16 Properties; }
Comments
Post a Comment