SystemParametersInfo problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • philippe.joliet@valain.com

    #1

    SystemParametersInfo problems

    Hello,

    I'm currently try to use the SystemParameter sInfo function in a c#
    environnement but I have a problem to use it with the action
    SPI_SETWORKAREA

    I've got this definition

    [DllImport("user 32.dll")]
    private static extern int SystemParameter sInfo(int uAction, int
    uParam, string pvParam, int fuWinIni);

    in the SDK it is shown that I must pass to pvParam a pointer to a RECT
    structure and not a string.

    How do I do that?

    I tried to define a struct equivalent to the RECT structure but it
    does not seems to work :(

    If you 've got an idee? it will be helpfull

    In advance, thanks
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: SystemParameter sInfo problems

    Philippe,

    The SystemParameter sInfo API call takes a pointer where the data
    returned is to be written to. Because of this, you should declare the
    parameter as an IntPtr and then marshal the information yourself based on
    what the return value is.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    <philippe.jolie t@valain.com> wrote in message
    news:99159f50.0 309100839.5c5e4 de4@posting.goo gle.com...[color=blue]
    > Hello,
    >
    > I'm currently try to use the SystemParameter sInfo function in a c#
    > environnement but I have a problem to use it with the action
    > SPI_SETWORKAREA
    >
    > I've got this definition
    >
    > [DllImport("user 32.dll")]
    > private static extern int SystemParameter sInfo(int uAction, int
    > uParam, string pvParam, int fuWinIni);
    >
    > in the SDK it is shown that I must pass to pvParam a pointer to a RECT
    > structure and not a string.
    >
    > How do I do that?
    >
    > I tried to define a struct equivalent to the RECT structure but it
    > does not seems to work :(
    >
    > If you 've got an idee? it will be helpfull
    >
    > In advance, thanks[/color]


    Comment

    • philippe.joliet@valain.com

      #3
      Re: SystemParameter sInfo problems

      Thanks Nicholas,

      I've explored this way and I've written this method:

      public void SetWorkArea(Rec tangle scrLimit)
      {
      GUIRECT rect;
      IntPtr p;

      rect.left=scrLi mit.Left;
      rect.top=scrLim it.Top;
      rect.right=scrL imit.Right;
      rect.bottom=scr Limit.Bottom;

      p = Marshal.AllocHG lobal(Marshal.S izeOf(rect));

      Marshal.Structu reToPtr(rect,p, false);
      int i=SystemParamet ersInfo(SPI_SET WORKAREA,0,p,0) ;

      int ret=Marshal.Get LastWin32Error( );

      }
      private struct GUIRECT
      {
      public long left;
      public long top;
      public long right;
      public long bottom;

      }


      and the ret integer as a value of 87 (incorrect parameter)

      Something I was wondering is the SPI_SETWORKAREA command is a "write"
      command and the third parameter is only read or I miss something?

      I'm not very familiar with Marshaling, and I hope once more that you
      can help me. I known that I'm perhaps abusing but I'm wasting time on
      this little detail of my application, I'm getting nervous

      Thanks a lot

      Philippe




      "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote in message news:<OaN$zu7dD HA.1632@TK2MSFT NGP12.phx.gbl>. ..[color=blue]
      > Philippe,
      >
      > The SystemParameter sInfo API call takes a pointer where the data
      > returned is to be written to. Because of this, you should declare the
      > parameter as an IntPtr and then marshal the information yourself based on
      > what the return value is.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - nicholas.paldin o@exisconsultin g.com
      >
      > <philippe.jolie t@valain.com> wrote in message
      > news:99159f50.0 309100839.5c5e4 de4@posting.goo gle.com...[color=green]
      > > Hello,
      > >
      > > I'm currently try to use the SystemParameter sInfo function in a c#
      > > environnement but I have a problem to use it with the action
      > > SPI_SETWORKAREA
      > >
      > > I've got this definition
      > >
      > > [DllImport("user 32.dll")]
      > > private static extern int SystemParameter sInfo(int uAction, int
      > > uParam, string pvParam, int fuWinIni);
      > >
      > > in the SDK it is shown that I must pass to pvParam a pointer to a RECT
      > > structure and not a string.
      > >
      > > How do I do that?
      > >
      > > I tried to define a struct equivalent to the RECT structure but it
      > > does not seems to work :(
      > >
      > > If you 've got an idee? it will be helpfull
      > >
      > > In advance, thanks[/color][/color]

      Comment

      Working...