Exemple #1
0
        /// <summary>
        /// 将指针转化为结构体
        /// </summary>
        /// <param name="_ptr"></param>
        /// <param name="_type"></param>
        /// <param name="_struct"></param>
        /// <returns></returns>
        public static sObjectInfo IntPtrToStruct(IntPtr _ptr)
        {
            sObjectInfo sObjInfo = new sObjectInfo();

            sObjInfo = (sObjectInfo)Marshal.PtrToStructure(_ptr, typeof(sObjectInfo));
            Marshal.FreeHGlobal(_ptr);
            return(sObjInfo);
        }
Exemple #2
0
        /// <summary>
        /// 把一个自定义类型的对象转化为对象信息结构体
        /// </summary>
        /// <param name="_Obj"></param>
        /// <returns></returns>
        public static sObjectInfo GetObjInfoFromObject(object _Obj)
        {
            Int32  iSize  = 0;
            IntPtr ptrObj = IntPtr.Zero;

            ptrObj = ClassToIntPtr(_Obj, out iSize);
            sObjectInfo sObjInfo = new sObjectInfo();

            sObjInfo.m_pObject = ptrObj;
            sObjInfo.m_iSize   = iSize;
            return(sObjInfo);
        }
Exemple #3
0
 /// <summary>
 /// 根据对象信息结构体获取对象
 /// </summary>
 /// <param name="_sObjInfo"></param>
 /// <returns></returns>
 public static object GetObjectFromObjInfo(sObjectInfo _sObjInfo)
 {
     return(IntPtrToClass(_sObjInfo.m_pObject, _sObjInfo.m_iSize));
 }