[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Problem using SystemParametersInfo

Dave Leach

7/22/2003 9:34:00 PM

I am trying to control the current state of the Mousekeys
accessibility feature with a simple Windows Forms app. I
am using the SystemParametersInfo() function found in the
user32.dll.

The function is returning a value of zero, indicating an
unsuccessful call. I then call GetLastError(), which
returns the error value 127; "The specified procedure
could not be found."

I have copied relevant sections of the code below.
Any ideas on what I am doing wrong? Why is the call not
successful?

Thanks,
Dave

using System.Runtime.InteropServices;
namespace MouseKeys
{
public class MouseKeys : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnToggle;
private System.Windows.Forms.Button btnClose;

private void btnToggle_Click(
object sender,
System.EventArgs e)
{
Win32.MOUSEKEYS mkeys = new Win32.MOUSEKEYS();
uint size = (uint)(Marshal.SizeOf(mkeys));
mkeys.cbSize = size;

int result = Win32.SystemParametersInfo(
Win32.SPI_GETMOUSEKEYS, // uiAction
size, // uiParam
ref mkeys, // pvParam
0); // fWinIni

if (result != 0)
{
this.textBox1.Text = mkeys.dwFlags.ToString();
}
else
{
uint error = Win32.GetLastError();

string msg = string.Format(
"GetLastError(): {0}",
error);

MessageBox.Show(
msg,
"MouseKeys SystemParametersInfo Error");
}
}

public class Win32
{
public const int SPI_GETMOUSEKEYS = 0x0036;
public const int SPI_SETMOUSEKEYS = 0x0037;
public const int MKF_AVAILABLE = 0x00000002;
public const int MKF_MOUSEKEYSON = 0x00000001;

[StructLayout(LayoutKind.Sequential)]
public class MOUSEKEYS
{
public uint cbSize;
public uint dwFlags;
public uint iMaxSpeed;
public uint iTimeToMaxSpeed;
public uint iCtrlSpeed;
public uint dwReserved1;
public uint dwReserved2;
}

[DllImport("user32.dll", SetLastError=true)]
public static extern int SystemParametersInfo(
uint uiAction,
uint uiParam,
ref MOUSEKEYS pvParam,
uint fWinIni);

[DllImport("kernel32.dll")]
public static extern uint GetLastError();
}
}

8 Answers

Dave Leach

7/23/2003 4:22:00 PM

0

Justin,

Okay, I changed the declaration as you suggested, but now
how do I pass the MOUSEKEYS structure into the function and
retrieve the results? What conversion or marshalling is
required to pass the structure in and out of the call to
SystemParametersInfo()? When uiAction parameter is set to
SPI_GETMOUSEKEYS, the pvParam parameter must be a MOUSEKEYS
structure.

Thanks,
Dave

>-----Original Message-----
>Please declare SystemParameter like this:
>
>public static extern int SystemParametersInfo(
> uint uiAction,
> uint uiParam,
> ref uint pvParam, ''***use uint instead of MOUSEKEYS
> uint fWinIni);
>
>Regards,
>Justin Wan
>Microsoft Partner Online Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>
>.
>

justinew

7/24/2003 2:11:00 PM

0

Because the pvParam is PVoid not MOUSEKEYS, 127 error appears when you
declare the API with MOUSEKEYS.

Because pvParam indicates a variable struct for the API under different
scenario, we can not pass a fix struct reference to it.

We need pass a byte array (memory block) to it and API will explain it as
it is called in unmanaged environment.

There is an article about this.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/c...
l/cpconarrayssample.asp

Your program need fill the memory block with the struct of MOUSEKEYS and
then pass it as byte array to SystemParameterInfo.

Regards,
Justin Wan
Microsoft Partner Online Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Dave Leach

7/24/2003 5:54:00 PM

0

Justin,

I got the SystemParametersInfo() function to work by using
the following declaration:

[DllImport("user32.dll", SetLastError=true)]
public static extern bool SystemParametersInfo(
uint uiAction,
uint uiParam,
IntPtr pvParam,
uint fWinIni);

Notice that the third parameter is declared as an IntPtr.
To call the function and retrieve the data, I needed to
marshall the structure to and from an IntPtr buffer as
follows:

private void btnGetFlags_Click(object sender,
System.EventArgs e)
{
Win32.MOUSEKEYS mkeys = new Win32.MOUSEKEYS();
int size = Marshal.SizeOf(mkeys);
mkeys.cbSize = (uint)size;
IntPtr buffer =
Marshal.AllocCoTaskMem( Marshal.SizeOf(mkeys) );
Marshal.StructureToPtr(mkeys, buffer, false);

if ( Win32.SystemParametersInfo(
(uint)Win32.SPI_GETMOUSEKEYS,
(uint)size,
buffer,
0) )
{
Win32.MOUSEKEYS mkeysRes = (Win32.MOUSEKEYS)
Marshal.PtrToStructure(buffer,
typeof(Win32.MOUSEKEYS));
this.textBox1.Text = mkeysRes.dwFlags.ToString("X");
}
else
{
uint error = Win32.GetLastError();
string msg = string.Format("GetLastError(): {0}",
error);
MessageBox.Show(msg,
"MouseKeys SystemParametersInfo Error");
}
}

I found the information I needed in an article near the one
you pointed me to (cpconosinfosample.asp).

Thanks for your help,
Dave

>-----Original Message-----
>Because the pvParam is PVoid not MOUSEKEYS, 127 error
appears when you
>declare the API with MOUSEKEYS.
>
>Because pvParam indicates a variable struct for the API
under different
>scenario, we can not pass a fix struct reference to it.
>
>We need pass a byte array (memory block) to it and API
will explain it as
>it is called in unmanaged environment.
>
>There is an article about this.
>http://msdn.microsoft.com/library/de...
url=/library/en-us/cpguide/htm
>l/cpconarrayssample.asp
>
>Your program need fill the memory block with the struct
of MOUSEKEYS and
>then pass it as byte array to SystemParameterInfo.
>
>Regards,
>Justin Wan
>Microsoft Partner Online Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>
>.
>

H.E. Eickleberry

10/10/2011 10:26:00 AM

0

On 9/27/2011 8:25 AM, Mulligan wrote:
> On Sep 25, 8:50 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>> On 9/24/2011 8:13 AM, Mulligan wrote:
>>
>>
>>
>>
>>
>>> On Sep 24, 4:56 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>> On 9/21/2011 9:41 AM, Mulligan wrote:
>>
>>>>> On Sep 21, 1:49 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>>>> On 9/20/2011 8:35 AM, Mulligan wrote:
>>
>>>>>> [snip]
>>
>>>>>>> If you think quoting paul at that time when he hadn't yet attained it
>>
>>>>>> NO ONE EVER ATTAINS IT, until the resurrection, when one puts off
>>>>>> corruption and puts on incorruption.
>>
>>>>> And you would be wrong as paul writes of thsoe that had it already.
>>
>>>> Yeah. The dead in Christ who have already (from the eternal perspective)
>>>> gone on to glory.
>>
>>>> Ike
>>
>>> The quotes I allude to and have put in this thread do not apply to
>>> those, but to those here.
>>
>> There ARE none here
>
> At the time the letter was written.

Not then, either; the references are to the DEAD IN CHRIST, not the
living in the flesh.

NO ONE is perfected in the flesh, and anyone who says otherwise is a
blasphemer.

"If we say we have no sin, we DECEIVE ourselves, and THE TRUTH IS NOT IN
US."

Ike

--
http://thetriunist.weebly.com/...
http://www.facebook.com...!/pages/The-Triune-Hypothesis/102657386473773

H.E. Eickleberry

10/10/2011 10:37:00 AM

0

On 9/27/2011 8:28 AM, Mulligan wrote:
> On Sep 25, 9:00 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>> On 9/24/2011 8:17 AM, Mulligan wrote:
>>
>>
>>
>>
>>
>>> On Sep 24, 5:22 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>> On 9/22/2011 9:13 AM, Mulligan wrote:
>>
>>>>> On Sep 22, 4:24 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>>>> On 9/21/2011 9:33 AM, Mulligan wrote:
>>
>>>>>>> LOL.
>>>>>>> You are living in some fantasy land.
>>>>>>> Paul went out and put huge numbers of roman citizens into the church.
>>>>>>> Gentile version of christianity outnumbered jewish version of
>>>>>>> christianity and paul won out.
>>>>>>> The result of paul's churches he set up became what is known as roman
>>>>>>> catholicism.
>>
>>>>>> LOL
>>
>>>>>> You're as ignorant of church history as you are everything else.
>>
>>>>>> There was no "Roman Catholic Church" until the East-West Schism of 1050
>>>>>> AD, which resulted from the Latin and Greek writers opposing one another
>>>>>> on certain theological points.
>>
>>>>> LOL
>>
>>>>> Around 150 AD or so the bishops of the church looked around and
>>>>> noticed the church membership
>>>>> had become quite large.
>>>>> Shortly after that, the word catholic came into use as the general
>>>>> religion of christianity.
>>
>>>> You're completely full of shit.
>>
>>>> The term "Catholic," originating from the Greek and carried over to
>>>> Latin, was used by ALL the churches--east and west--from the Second
>>>> Century on.
>>
>>> That is what I typed above.
>>
>> But not what you typed before that
>
> Since that is the catholic which became roman catholic, your quibble
> is ridiculous.

Absolute stupidity: Even the Reformation-era Churches refer to
themselves as "Catholic," as per the creeds, you ignorant moron.

Roman Catholicism, Orthodox, the Reformationists, etc, etc, ALL teach a
"Catholic" Church," i.e.

"...I believe in one holy catholic and apostolic church..."

Could you be any more ignorant?

Ike
--
http://thetriunist.weebly.com/...
http://www.facebook.com...!/pages/The-Triune-Hypothesis/102657386473773

Mulligan

10/12/2011 1:22:00 PM

0

On Oct 10, 6:26 am, "H.E. Eickleberry" <xeicklebo...@gmail.com> wrote:
> On 9/27/2011 8:25 AM, Mulligan wrote:
>
>
>
>
>
> > On Sep 25, 8:50 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>  wrote:
> >> On 9/24/2011 8:13 AM, Mulligan wrote:
>
> >>> On Sep 24, 4:56 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>    wrote:
> >>>> On 9/21/2011 9:41 AM, Mulligan wrote:
>
> >>>>> On Sep 21, 1:49 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>      wrote:
> >>>>>> On 9/20/2011 8:35 AM, Mulligan wrote:
>
> >>>>>> [snip]
>
> >>>>>>> If you think quoting paul at that time when he hadn't yet attained it
>
> >>>>>> NO ONE EVER ATTAINS IT, until the resurrection, when one puts off
> >>>>>> corruption and puts on incorruption.
>
> >>>>> And you would be wrong as paul writes of thsoe that had it already.
>
> >>>> Yeah. The dead in Christ who have already (from the eternal perspective)
> >>>> gone on to glory.
>
> >>>> Ike
>
> >>> The quotes I allude to and have put in this thread do not apply to
> >>> those, but to those here.
>
> >> There ARE none here
>
> > At the time the letter was written.
>
> Not then, either; the references are to the DEAD IN CHRIST, not the
> living in the flesh.

Show me from the scriptures I quoted about this that they applied to
that group you mention.

H.E. Eickleberry

11/1/2011 9:13:00 PM

0

On 10/12/2011 9:22 AM, Mulligan wrote:
> On Oct 10, 6:26 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>> On 9/27/2011 8:25 AM, Mulligan wrote:
>>
>>
>>
>>
>>
>>> On Sep 25, 8:50 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>> On 9/24/2011 8:13 AM, Mulligan wrote:
>>
>>>>> On Sep 24, 4:56 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>>>> On 9/21/2011 9:41 AM, Mulligan wrote:
>>
>>>>>>> On Sep 21, 1:49 am, "H.E. Eickleberry"<xeicklebo...@gmail.com> wrote:
>>>>>>>> On 9/20/2011 8:35 AM, Mulligan wrote:
>>
>>>>>>>> [snip]
>>
>>>>>>>>> If you think quoting paul at that time when he hadn't yet attained it
>>
>>>>>>>> NO ONE EVER ATTAINS IT, until the resurrection, when one puts off
>>>>>>>> corruption and puts on incorruption.
>>
>>>>>>> And you would be wrong as paul writes of thsoe that had it already.
>>
>>>>>> Yeah. The dead in Christ who have already (from the eternal perspective)
>>>>>> gone on to glory.
>>
>>>>>> Ike
>>
>>>>> The quotes I allude to and have put in this thread do not apply to
>>>>> those, but to those here.
>>
>>>> There ARE none here
>>
>>> At the time the letter was written.
>>
>> Not then, either; the references are to the DEAD IN CHRIST, not the
>> living in the flesh.
>
> Show me from the scriptures I quoted about this that they applied to
> that group you mention.

I Co 15:
39 All flesh is not the same flesh: but there is one kind of flesh of
men, another flesh of beasts, another of fishes, and another of birds.
40 There are also celestial bodies, and bodies terrestrial: but the
glory of the celestial is one, and the glory of the terrestrial is another.
41 There is one glory of the sun, and another glory of the moon, and
another glory of the stars: for one star differeth from another star in
glory.
42 So also is the resurrection of the dead. It is sown IN CORRUPTION;
it is raised in incorruption:
43 It is sown IN DISHONOUR; it is raised in glory: it is sown IN
WEAKNESS; it is raised in power:
44 It is sown a natural body; it is raised a spiritual body. There is a
natural body, and there is a spiritual body.
45 And so it is written, The first man Adam was made a living soul; the
last Adam was made a quickening spirit.
46 Howbeit that was not first which is spiritual, but that which is
natural; and afterward that which is spiritual.
47 The first man is of the earth, earthy: the second man is the Lord
from heaven.
48 As is the earthy, such are they also that are earthy: and as is the
heavenly, such are they also that are heavenly.
49 And as we have borne the image of the earthy, we shall also bear the
image of the heavenly.
50 Now this I say, brethren, that flesh and blood cannot inherit the
kingdom of God; neither doth corruption inherit incorruption.

Anyone who says they are perfected in the flesh (save Jesus) is a liar
and fraud.

"If we SAY [present tense] that we HAVE [present tense] no sin, we
DECEIVE ourselves, and the truth is not in us; but if we confess our
sins, God is faithful and just to FORGIVE [eternal sense] our sins, and
cleanse [eternal sense] us from all unrighteousness."

Ike


--
http://thetriunist.weebly.com/...
http://www.facebook.com...!/pages/The-Triune-Hypothesis/102657386473773

amalthea79

11/1/2011 9:50:00 PM

0

On Nov 1, 11:13 am, "H.E. Eickleberry" <xeicklebo...@gmail.com> wrote:
> On 10/12/2011 9:22 AM, Mulligan wrote:
>
>
>
>
>
> > On Oct 10, 6:26 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>  wrote:
> >> On 9/27/2011 8:25 AM, Mulligan wrote:
>
> >>> On Sep 25, 8:50 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>    wrote:
> >>>> On 9/24/2011 8:13 AM, Mulligan wrote:
>
> >>>>> On Sep 24, 4:56 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>      wrote:
> >>>>>> On 9/21/2011 9:41 AM, Mulligan wrote:
>
> >>>>>>> On Sep 21, 1:49 am, "H.E. Eickleberry"<xeicklebo...@gmail.com>        wrote:
> >>>>>>>> On 9/20/2011 8:35 AM, Mulligan wrote:
>
> >>>>>>>> [snip]
>
> >>>>>>>>> If you think quoting paul at that time when he hadn't yet attained it
>
> >>>>>>>> NO ONE EVER ATTAINS IT, until the resurrection, when one puts off
> >>>>>>>> corruption and puts on incorruption.
>
> >>>>>>> And you would be wrong as paul writes of thsoe that had it already.
>
> >>>>>> Yeah. The dead in Christ who have already (from the eternal perspective)
> >>>>>> gone on to glory.
>
> >>>>>> Ike
>
> >>>>> The quotes I allude to and have put in this thread do not apply to
> >>>>> those, but to those here.
>
> >>>> There ARE none here
>
> >>> At the time the letter was written.
>
> >> Not then, either; the references are to the DEAD IN CHRIST, not the
> >> living in the flesh.
>
> > Show me from the scriptures I quoted about this that they applied to
> > that group you mention.
>
> I Co 15:
> 39  All flesh is not the same flesh: but there is one kind of flesh of
> men, another flesh of beasts, another of fishes, and another of birds.
> 40  There are also celestial bodies, and bodies terrestrial: but the
> glory of the celestial is one, and the glory of the terrestrial is another.
> 41  There is one glory of the sun, and another glory of the moon, and
> another glory of the stars: for one star differeth from another star in
> glory.
> 42  So also is the resurrection of the dead. It is sown IN CORRUPTION;
> it is raised in incorruption:
> 43  It is sown IN DISHONOUR; it is raised in glory: it is sown IN
> WEAKNESS; it is raised in power:
> 44  It is sown a natural body; it is raised a spiritual body. There is a
> natural body, and there is a spiritual body.
> 45  And so it is written, The first man Adam was made a living soul; the
> last Adam was made a quickening spirit.
> 46  Howbeit that was not first which is spiritual, but that which is
> natural; and afterward that which is spiritual.
> 47  The first man is of the earth, earthy: the second man is the Lord
> from heaven.
> 48  As is the earthy, such are they also that are earthy: and as is the
> heavenly, such are they also that are heavenly.
> 49  And as we have borne the image of the earthy, we shall also bear the
> image of the heavenly.
> 50  Now this I say, brethren, that flesh and blood cannot inherit the
> kingdom of God; neither doth corruption inherit incorruption.
>
> Anyone who says they are perfected in the flesh (save Jesus) is a liar
> and fraud.
>
> "If we SAY [present tense] that we HAVE [present tense] no sin, we
> DECEIVE ourselves, and the truth is not in us; but if we confess our
> sins, God is faithful and just to FORGIVE [eternal sense] our sins, and
> cleanse [eternal sense] us from all unrighteousness."
>
> Ike
>
> --http://thetriunist.weebly.com/index.htmlhttp://www.facebook.com...!/pages/The-Triune-Hypothesis/102657...-

A God that kills children is not my judge.