728x90
728x170
        /// <summary>
        /// Byte[] 를 Struct 로 변환합니다.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="bytes"></param>
        /// <returns></returns>
        private T ConvertSrtuctFromBytes<T>(byte[] bytes) where T : struct
        {
            int size = Marshal.SizeOf(typeof(T));

            if (size > bytes.Length)
            {
                return default(T);
            }

            IntPtr ptr = Marshal.AllocHGlobal(size);
            Marshal.Copy(bytes, 0, ptr, size);
            T result = (T)Marshal.PtrToStructure(ptr, typeof(T));
            Marshal.FreeHGlobal(ptr);

            return result;
        }
728x90
그리드형
Posted by kjun.kr
,