P
P
Pavel Kaptur2016-02-10 14:37:44
Windows
Pavel Kaptur, 2016-02-10 14:37:44

Why doesn't SystemParametersInfo work?

I'm trying to call SystemParametersInfo from C# and change the direction of font smoothing SPI_SETFONTSMOOTHINGORIENTATION I
declared the function like this

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, ref uint pvParam, SPIF fWinIni);

I use like this, where value is one of the enum with directions
if (SystemParametersInfo(SPI.SPI_SETFONTSMOOTHINGORIENTATION, 0, ref value,
                SPIF.SPIF_UPDATEINIFILE | SPIF.SPIF_SENDCHANGE) == false)
            {
                int code = Marshal.GetLastWin32Error();              
                return false;
            }

Structures are declared like this.
[Description("SPI_(System-wide parameter - Used in SystemParametersInfo function )"), Flags]
   public enum SPI : uint
   {
       /// <summary>
       /// Determines whether the warning beeper is on. 
       /// The pvParam parameter must point to a BOOL variable that receives TRUE if the beeper is on, or FALSE if it is off.
       /// </summary>
       SPI_GETBEEP = 0x0001,

   [Description("SPIF_(System-wide parameter - Used in SystemParametersInfo function )"), Flags]
     public enum SPIF : uint
    {
        None = 0x00,
        SPIF_UPDATEINIFILE = 0x01,
        SPIF_SENDCHANGE = 0x02,

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kaptur, 2016-02-10
@drem1lin

Should have declared without ref
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, ref uint pvParam, SPIF fWinIni);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question