/// <summary> /// view user information /// </summary> /// <param name="iLogin">DHLogin return value</param> /// <param name="userInfo">USER_MANAGE_INFOStructure</param> /// <param name="waitTime">waittime</param> /// <returns>true:succeed;false:fail</returns> public static bool NETQueryUserInfo(int iLogin,ref USER_MANAGE_INFO userInfo,int waitTime) { bool retValue = false; IntPtr pBoxInfo = IntPtr.Zero; try { pBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USER_MANAGE_INFO)));//Allocation of fixed specified the size of the memory space if (pBoxInfo != IntPtr.Zero) { retValue = CLIENT_QueryUserInfo(iLogin, pBoxInfo, waitTime); if (retValue == true) { userInfo = (USER_MANAGE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo), typeof(USER_MANAGE_INFO)); } } NETThrowLastError(retValue); } catch (Exception e) { NETThrowLastError(e); retValue = false; } finally { Marshal.FreeHGlobal(pBoxInfo);//Release the fixed memory allocation pBoxInfo = IntPtr.Zero; } return retValue; }
/// <summary> /// 查询用户信息 /// </summary> /// <param name="iLogin">DHLogin的返回值</param> /// <param name="userInfo">USER_MANAGE_INFO结构</param> /// <param name="waitTime">等待时间</param> /// <returns>true:成功;false:失败</returns> public static bool DHQueryUserInfo(int iLogin,ref USER_MANAGE_INFO userInfo,int waitTime) { bool retValue = false; IntPtr pBoxInfo = IntPtr.Zero; try { pBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USER_MANAGE_INFO)));//分配固定的指定大小的内存空间 if (pBoxInfo != IntPtr.Zero) { retValue = CLIENT_QueryUserInfo(iLogin, pBoxInfo, waitTime); if (retValue == true) { userInfo = (USER_MANAGE_INFO)Marshal.PtrToStructure((IntPtr)((UInt32)pBoxInfo), typeof(USER_MANAGE_INFO)); } } DHThrowLastError(retValue); } catch (Exception e) { DHThrowLastError(e); retValue = false; } finally { Marshal.FreeHGlobal(pBoxInfo);//释放固定内存分配 pBoxInfo = IntPtr.Zero; } return retValue; }