예제 #1
0
        public static IntPtr ToIntPtr(this SConfig sConfig)
        {
            IntPtr msgPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SConfig)));

            Marshal.StructureToPtr(sConfig, msgPtr, true);
            return(msgPtr);
        }
예제 #2
0
        public J2534Err SetConfig(int channelId, int Parameter, int Value)  //leon changed 20190105
        //  public J2534Err SetConfig(int channelId, SConfig_List config)
        {
            J2534Err J2534Err1;
            IntPtr   input  = IntPtr.Zero;
            IntPtr   output = IntPtr.Zero;

            SConfig sconfig = new SConfig();

            sconfig.Parameter = Parameter;
            sconfig.Value     = Value;
            IntPtr[] intptrr = new IntPtr[1];
            intptrr[0] = Marshal.AllocHGlobal(Marshal.SizeOf(sconfig));
            try
            {
                Marshal.StructureToPtr(sconfig, intptrr[0], true);

                SConfig_List sconfig_list = new SConfig_List();
                sconfig_list.NumOfParams = 1;
                sconfig_list.ConfigPtr   = intptrr;

                input = Marshal.AllocCoTaskMem(Marshal.SizeOf(sconfig_list));
                Marshal.StructureToPtr(sconfig_list, input, true);
                J2534Err1 = (J2534Err)m_wrapper.Ioctl(channelId, (int)Ioctl.SET_CONFIG, input, output);
            }
            finally
            {
                Marshal.FreeHGlobal(input);
            }
            return(J2534Err1);

            ////IntPtr InPut = Marshal.AllocHGlobal(Marshal.SizeOf(config));
            //IntPtr InPut = Marshal.AllocCoTaskMem(Marshal.SizeOf(config));
            ////  IntPtr output = IntPtr.Zero;
            //try
            //{
            //    Marshal.StructureToPtr(config, InPut, true);
            //    unsafe
            //    {
            //        //InPut.ToPointer();
            //        J2534Err1 = (J2534Err)m_wrapper.Ioctl(channelId, (int)Ioctl.SET_CONFIG, InPut, output);
            //    }

            //}
            //finally
            //{
            //    Marshal.FreeHGlobal(InPut);
            //}
            //return J2534Err1;
        }
예제 #3
0
        public static IntPtr ToIntPtr(this List <SConfig> sConfigs)
        {
            int    structSize = Marshal.SizeOf(typeof(SConfig));
            int    size       = sConfigs.Count * structSize;
            IntPtr msgPtr     = Marshal.AllocHGlobal(size);

            for (int i = 0; i < sConfigs.Count; i++)
            {
                SConfig sConfig = sConfigs.ElementAt(i);
                Marshal.StructureToPtr(sConfig, (IntPtr)((int)msgPtr + i * size), true);
            }

            return(msgPtr);
        }