Пример #1
0
    private static HW_PROFILE_INFO ProfileInfo()
    {
        HW_PROFILE_INFO profile    = null;
        IntPtr          profilePtr = IntPtr.Zero;

        try
        {
            profile    = new HW_PROFILE_INFO();
            profilePtr = Marshal.AllocHGlobal(Marshal.SizeOf(profile));
            Marshal.StructureToPtr(profile, profilePtr, false);

            if (!GetCurrentHwProfile(profilePtr))
            {
                throw new Exception("Error cant get current hw profile!");
            }
            else
            {
                Marshal.PtrToStructure(profilePtr, profile);
                return(profile);
            }
        }
        catch (Exception e)
        {
            throw new Exception(e.ToString());
        }
        finally
        {
            if (profilePtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(profilePtr);
            }
        }
    }
Пример #2
0
        private static HW_PROFILE_INFO ProfileInfo()
        {
            HW_PROFILE_INFO profile = null;
            IntPtr profilePtr = IntPtr.Zero;
            try
            {
                profile = new HW_PROFILE_INFO();
                profilePtr = Marshal.AllocHGlobal(Marshal.SizeOf(profile));
                Marshal.StructureToPtr(profile, profilePtr, false);

                if (!GetCurrentHwProfile(profilePtr))
                {
                    throw new Exception("Error cant get current hw profile!");
                }
                else
                {
                    Marshal.PtrToStructure(profilePtr, profile);
                    return profile;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.ToString());
            }
            finally
            {
                if (profilePtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(profilePtr);
                }
            }
        }