public static IntPtr ToIntPtr(this SConfigList sConfigList) { IntPtr msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SConfigList))); Marshal.StructureToPtr(sConfigList, msgPtr, true); return(msgPtr); }
unsafe public J2534Err GetConfig(int channelId, ref List <SConfig> config) { SConfigList sConfigList = new SConfigList(); sConfigList.ListPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SConfig)) * config.Count); for (int i = 0; i < config.Count; i++) { Marshal.StructureToPtr(config[i], new IntPtr(sConfigList.ListPtr.ToInt64() + Marshal.SizeOf(typeof(SConfig)) * i), false); } IntPtr output = IntPtr.Zero; IntPtr input = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SConfigList))); Marshal.StructureToPtr(sConfigList, input, false); var err = (J2534Err)_wrapper.Ioctl(channelId, (int)Ioctl.GET_CONFIG, input, output); var configList = input.AsStruct <SConfigList>().GetList(); config = new List <SConfig>(); for (int i = 0; i < configList.Count; i++) { config.Add(configList[i]); } return(err); }