SystemParametersInfo problems

  • Thread starter Thread starter philippe.joliet
  • Start date Start date
P

philippe.joliet

Hello,

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

I've got this definition

[DllImport("user32.dll")]
private static extern int SystemParametersInfo(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
 
Philippe,

The SystemParametersInfo 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.
 
Thanks Nicholas,

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

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

rect.left=scrLimit.Left;
rect.top=scrLimit.Top;
rect.right=scrLimit.Right;
rect.bottom=scrLimit.Bottom;

p = Marshal.AllocHGlobal(Marshal.SizeOf(rect));

Marshal.StructureToPtr(rect,p,false);
int i=SystemParametersInfo(SPI_SETWORKAREA,0,p,0);

int ret=Marshal.GetLastWin32Error();

}
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 said:
Philippe,

The SystemParametersInfo 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]
- (e-mail address removed)

Hello,

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

I've got this definition

[DllImport("user32.dll")]
private static extern int SystemParametersInfo(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
 
Back
Top