Hi all,
my form1 class contains a bunch of data that I need to save, so there should only be one instance of it running at a time.
public partial class Form1 : Form
{
public string form1string = "I really need to save this data";
public Form1()
{
InitializeComponent();
// Even if I pass my form1 object here I still can't access it from
// the upcoming static methods.
InterceptKeys hook = new InterceptKeys();
}
InterceptKeys, which is not my code, contains a bunch of static methods required for keyboard hooks.
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
int trueKeyPressed = Marshal.ReadInt32(lParam);
if (Form1.mirror)
{
Form1.newKeyPress(trueKeyPressed);
return (IntPtr)1;
}
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
Because the HookCallBack method is static, Form1.newKeyPress() needs to be static as well.
But if newKeyPress in static, I can't access the data that I need! I wouldn't want to declare a new form1 object here, as that would give me different versions of the data. Correct?
I'm not an Object Oriented Expert. How should I format this, to ensure that all of the InterceptKey's form1 method calls are going to THE form1 object that I want?
Thanks, please let me know if there's any more info that you need!