Click here to Skip to main content
15,887,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code


C#
public Form1()
 {
     LASTINPUTINFO lastInPut = new LASTINPUTINFO();
     lastInPut.cbSize = (uint)
       System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);

     InitializeComponent();
 }


and

C#
[DllImport("User32.dll")]
private static extern bool
        GetLastInputInfo(ref LASTINPUTINFO plii);

internal struct LASTINPUTINFO
{
    public uint cbSize;

    public uint dwTime;
}


and this is me trying to access the dwTime

C#
private void Form1_Load(object sender, EventArgs e)
   {
    
 this.Text = dwTime.toString();
   }


but it obously doesn't work, i should be able to access it because i made it public, why??
Posted

No, a public property cannot be accessed without specifying the object. Without telling the compiler where your "dwTime" is coming from, it will not be able to find it.

lastInPut.dwTime
 
Share this answer
 
Comments
[no name] 30-Aug-12 7:09am    
I understand. I just tried the code

this.Text = lastInPut.dwTime;

but its telling me that lastInPut doesn't exist in the current context
Eddy Vluggen 30-Aug-12 7:13am    
Because it doesn't; it only exists as a local variable in your constructor. Make it a private class-level variable, and you can access it.
[no name] 30-Aug-12 7:22am    
I don't know if i can :(

LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)

has to be in the Initialize
Kumar, Ravikant 30-Aug-12 8:04am    
As suggested, declare it as private member and initialize in constructor. Simple.
private LASTINPUTINFO lastInPut;
public Form1()
{
lastInPut = new LASTINPUTINFO();
}
private LASTINPUTINFO lastInPut;
public Form1()
       {
           lastInPut = new LASTINPUTINFO();
           lastInPut.cbSize = (uint)
             System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);

           InitializeComponent();
       }

Try again.

You might want to head to the library and get a good book for beginners; declaring variables is not difficult, but it's not a good idea to continue doing more complexer things without the basics.
 
Share this answer
 
Comments
Andreas Gieriet 30-Aug-12 14:29pm    
See his Q&A Questions and his Comments. He's ignorant on such advise... Even he very much needs it... And if you ask some question back, you get weird responses. Sad.
Cheers
Andi
[no name] 30-Aug-12 18:26pm    
This ha nothing to do with the question please remove your comment
Andreas Gieriet 1-Sep-12 4:18am    
It has to do with many of your questions, so, this is just one of them.
You have to face reality: If you don't know how to set a variable (or a field, etc.), you need to go back to the very basics and learn these. You got that advise in many of your questions and you obviously still continue to ignore that advise.
Please keep in mind that everyone who answers a question implicitly assumes some common ground where he starts to give an answer. If that common ground is not given, then it's time to get to a common ground. That is clearly a task on your side. No one here is probably assuming that he needs to explain how to set a variable.
You ask questions where I must assume that you know the basics - but your followup questions show differently.
Please, please, go back and take that advise to learn the very basics first, for the benefit of you and all of us.
Cheers
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900