Struct marshal in C#

前端 未结 2 2145
深忆病人
深忆病人 2021-02-09 22:17

I have the following struct in C#

unsafe public struct control
    {
        public int bSetComPort;
        public int iComPortIndex;
        public int iBaudRa         


        
2条回答
  •  心在旅途
    2021-02-09 22:48

    The error you are reporting as a compile error is in fact a runtime error (an ArgumentException). When you want to use structtobyte to convert a control to byte[] you should pass the method a reference to control, not a byte array (byte[]).

    control ctrl = new control();
    byte[] bytes = structtobyte(ctrl);
    

提交回复
热议问题