KeyBoardHook OpenNetCF with Windows CE 5.0

H

harry

Hi CompactFramework Experts,

I am having this problems for couple of weeks, we are developing a
windows CE 5.0 application. I am using OpenNetCF ver 2.3 community
edition. For keyboard Hook functionality, it's purpose is to trap when
F1,F2,F3 key pressed in the keyboard.

This below code works perfectly on the emulator, but when I deploy to
my LXE MX7 device with CompactFramework 3.5 installed, it generates an
error when I try to open up the form, the error is like this:

a MessageBox with

Error
A user break has occured in GACScan2009.exe

when I click on the details:

Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)


I am using below tools :

Microsoft Visual Studio 2008 SP1
OpenNetCF version 2.3 (Smart Device Framework)

Emulator for Windows CE Version
(virtual x86 Hardware Reference Board provided by Microsoft Corp
version 5.3.0.26)

Below is my code snippet for entire class :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GACSCAN_WINMOBILE2003;
using GACScan2009.ServiceInbound;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;

public partial class InboundNew : Form
{

GACScan2009.ServiceInbound.ServiceInbound service = new
ServiceInbound();
MotherClass mc;
KeyboardHook m_keyHook;

public InboundNew(MotherClass mcTemp)
{
InitializeComponent();
m_keyHook = new KeyboardHook();
mc = mcTemp;
getUser();
m_keyHook.KeyDetected += OnKeyDetected;
m_keyHook.Enabled = true;
}

private void getUser()
{
lblUser.Text = User.UserName;
}

private void getValue()
{
string srNo = "";
srNo = txtGACScanId.Text.Trim();

AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;

Cursor.Current = Cursors.WaitCursor;

service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
DataTable ResultSet = service.SelectSRNO(srNo).Tables[0];

if (ResultSet.Rows.Count == 0)
{
MessageBox.Show("No Record Found", "Failed to retrieve
record");
}
else
{
//dataset retrieval
}
}

private void txtGACScanId_KeyPress(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}

private void cmdBack_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
m_keyHook.Dispose();
m_keyHook = null;

CloseScreen();

}

void OnKeyDetected(OpenNETCF.Win32.WM keyMessage, KeyData
keyData)
{
if (this.InvokeRequired)
{
this.Invoke(new KeyHookEventHandler(OnKeyDetected),
new object[] { keyMessage, keyData });
return;
}

if (keyData.KeyCode == 112)
{
/*F1 KEY PRESSED*/
/*SAVE*/
//MessageBox.Show("F1 Key Pressed");
Save_Click_1(null, null);

}

if (keyData.KeyCode == 113)
{
/*F2 KEY PRESSED*/
ClearScreen();
}

if (keyData.KeyCode == 114)
{
/*F3 KEY PRESSED*/
cmdBack_Click(null, null);
}

//char c = (char)keyData.KeyCode;
//if (keyMessage == WM.KEYUP)
//{
// if (char.IsLetterOrDigit(c))
// {

// }
//}
}

private void ClearScreen()
{
lblSKU.Text = string.Empty;
lblDescription.Text = string.Empty;
lblExpDate.Text = string.Empty;
lblLotNo.Text = string.Empty;
lblPUOM.Text = string.Empty;
lblMUOM.Text = string.Empty;
lblLUOM.Text = string.Empty;
lbPQTY.Text = string.Empty;
lblMQty.Text = string.Empty;
lblLQty.Text = string.Empty;
lblSiteTo.Text = string.Empty;
lblSiteLocTo.Text = string.Empty;
txtGACScanId.Text = String.Empty;
txtGACScanId.Focus();
}

private void InboundNew_Load(object sender, EventArgs e)
{
ClearScreen();
}

//private void InboundNew_Deactivate(object sender, EventArgs
e)
//{
// ClearScreen();
//}

private void confirm()
{
string SRNO = txtGACScanId.Text.Trim();
string UserId = User.UserId;

AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;

Cursor.Current = Cursors.WaitCursor;

service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
string Result = service.ConfirmInbound(SRNO, UserId);
if (Result.Trim().Length > 0)
{
MessageBox.Show(Result.Trim());
}
else
{
MessageBox.Show("Confirmed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1);
}
}

private void Save_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Confirm ?",
"Confirm Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);

if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}

private void Save_Click_1(object sender, EventArgs e)
{
if (lblSKU.Text.Trim().Length > 0)
{
DialogResult result = MessageBox.Show("Confirm
Save ?", "Confirm Dialog", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
}

private void CloseScreen()
{
if (mc.inboundNew != null)
{
mc.inboundNew.Close();
mc.inboundNew.Dispose();
mc.inboundNew = null;
}

InboundMain inbounMain = new InboundMain(this.mc);
inbounMain.Show();

}

private void txtGACScanId_KeyPress_1(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
}


I wonder what caused the problems, I've google for hours. Other
solutions are using C++ and call the Dll within the application. I am
not familiar with C++, can I just fix my code, so the code will work
fine on my LXE MX7. Looking forward for your favorable reply.

Best Regards,

Harry
 
C

Chris Tacke, eMVP

Well the specific error is because I screwed up and left in a debugger.break
call. What should be happening is it should be throwing a Win32Exception,
so it's would still be failing even without that. The break point is only
hit when the SetWindowsHookEx fails. Can you tell it to continue so that
the exception will come through? That will gie you the error code from the
system.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

harry said:
Hi CompactFramework Experts,

I am having this problems for couple of weeks, we are developing a
windows CE 5.0 application. I am using OpenNetCF ver 2.3 community
edition. For keyboard Hook functionality, it's purpose is to trap when
F1,F2,F3 key pressed in the keyboard.

This below code works perfectly on the emulator, but when I deploy to
my LXE MX7 device with CompactFramework 3.5 installed, it generates an
error when I try to open up the form, the error is like this:

a MessageBox with

Error
A user break has occured in GACScan2009.exe

when I click on the details:

Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)


I am using below tools :

Microsoft Visual Studio 2008 SP1
OpenNetCF version 2.3 (Smart Device Framework)

Emulator for Windows CE Version
(virtual x86 Hardware Reference Board provided by Microsoft Corp
version 5.3.0.26)

Below is my code snippet for entire class :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GACSCAN_WINMOBILE2003;
using GACScan2009.ServiceInbound;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;

public partial class InboundNew : Form
{

GACScan2009.ServiceInbound.ServiceInbound service = new
ServiceInbound();
MotherClass mc;
KeyboardHook m_keyHook;

public InboundNew(MotherClass mcTemp)
{
InitializeComponent();
m_keyHook = new KeyboardHook();
mc = mcTemp;
getUser();
m_keyHook.KeyDetected += OnKeyDetected;
m_keyHook.Enabled = true;
}

private void getUser()
{
lblUser.Text = User.UserName;
}

private void getValue()
{
string srNo = "";
srNo = txtGACScanId.Text.Trim();

AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;

Cursor.Current = Cursors.WaitCursor;

service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
DataTable ResultSet = service.SelectSRNO(srNo).Tables[0];

if (ResultSet.Rows.Count == 0)
{
MessageBox.Show("No Record Found", "Failed to retrieve
record");
}
else
{
//dataset retrieval
}
}

private void txtGACScanId_KeyPress(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}

private void cmdBack_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
m_keyHook.Dispose();
m_keyHook = null;

CloseScreen();

}

void OnKeyDetected(OpenNETCF.Win32.WM keyMessage, KeyData
keyData)
{
if (this.InvokeRequired)
{
this.Invoke(new KeyHookEventHandler(OnKeyDetected),
new object[] { keyMessage, keyData });
return;
}

if (keyData.KeyCode == 112)
{
/*F1 KEY PRESSED*/
/*SAVE*/
//MessageBox.Show("F1 Key Pressed");
Save_Click_1(null, null);

}

if (keyData.KeyCode == 113)
{
/*F2 KEY PRESSED*/
ClearScreen();
}

if (keyData.KeyCode == 114)
{
/*F3 KEY PRESSED*/
cmdBack_Click(null, null);
}

//char c = (char)keyData.KeyCode;
//if (keyMessage == WM.KEYUP)
//{
// if (char.IsLetterOrDigit(c))
// {

// }
//}
}

private void ClearScreen()
{
lblSKU.Text = string.Empty;
lblDescription.Text = string.Empty;
lblExpDate.Text = string.Empty;
lblLotNo.Text = string.Empty;
lblPUOM.Text = string.Empty;
lblMUOM.Text = string.Empty;
lblLUOM.Text = string.Empty;
lbPQTY.Text = string.Empty;
lblMQty.Text = string.Empty;
lblLQty.Text = string.Empty;
lblSiteTo.Text = string.Empty;
lblSiteLocTo.Text = string.Empty;
txtGACScanId.Text = String.Empty;
txtGACScanId.Focus();
}

private void InboundNew_Load(object sender, EventArgs e)
{
ClearScreen();
}

//private void InboundNew_Deactivate(object sender, EventArgs
e)
//{
// ClearScreen();
//}

private void confirm()
{
string SRNO = txtGACScanId.Text.Trim();
string UserId = User.UserId;

AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;

Cursor.Current = Cursors.WaitCursor;

service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
string Result = service.ConfirmInbound(SRNO, UserId);
if (Result.Trim().Length > 0)
{
MessageBox.Show(Result.Trim());
}
else
{
MessageBox.Show("Confirmed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1);
}
}

private void Save_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Confirm ?",
"Confirm Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);

if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}

private void Save_Click_1(object sender, EventArgs e)
{
if (lblSKU.Text.Trim().Length > 0)
{
DialogResult result = MessageBox.Show("Confirm
Save ?", "Confirm Dialog", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
}

private void CloseScreen()
{
if (mc.inboundNew != null)
{
mc.inboundNew.Close();
mc.inboundNew.Dispose();
mc.inboundNew = null;
}

InboundMain inbounMain = new InboundMain(this.mc);
inbounMain.Show();

}

private void txtGACScanId_KeyPress_1(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
}


I wonder what caused the problems, I've google for hours. Other
solutions are using C++ and call the Dll within the application. I am
not familiar with C++, can I just fix my code, so the code will work
fine on my LXE MX7. Looking forward for your favorable reply.

Best Regards,

Harry
 
H

harry

Hi, Mr. Chris, tx for your reply.

Tried to bypass the debugger.break, by inserting try catch with an
empty catch procedure in the constructor. Here's the following result
I get :
Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)
at InboundNew..ctor(MotherClass mcTemp)
at InboundMain.btnPutAwayConf_Click(Object sender, EventArgs e)
at Control.OnClick(EventArgs e)
at Button.OnClick(EventArgs e)
at ButtonBase.WnProc(WM wm,Int32 wParam, Int32 IParam)
at Control,_InternalWnProc(WM wm,Int32 wParam, Int32 IParam)
at EVL.EnterMainLoop(IntPtr hwnMain)
at Application.Run(Form fm)
at MotherClass.Main()

Two buttons Continue and Quit --> when I press on Continue, it will
continue to display the screen but with no functionality of
keyboardhook. I have tried to contact the LXE and get below
information :

"As for our MX7 CE, the processor type is StrongArm/Xscale and the
setting on their emulator is X86, which is referring to their PC
Processor. It could be the program can run on the emulator without any
problem, but it can caused some issues if the program installed on our
terminal due to the processor types being used. You may ask them to
recompile the program by using the StrongArm/Xscale processor type"

Is this true?. Please give us your advice.

Best Regards,
Harry



Well the specific error is because I screwed up and left in a debugger.break
call.  What should be happening is it should be throwing a Win32Exception,
so it's would still be failing even without that.  The break point is only
hit when the SetWindowsHookEx fails.  Can you tell it to continue so that
the exception will come through?  That will gie you the error code fromthe
system.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com


Hi CompactFramework Experts,
I am having this problems for couple of weeks, we are developing a
windows CE 5.0 application. I am using OpenNetCF ver 2.3 community
edition. For keyboard Hook functionality, it's purpose is to trap when
F1,F2,F3 key pressed in the keyboard.
This below code works perfectly on the emulator, but when I deploy to
my LXE MX7 device with CompactFramework 3.5 installed, it generates an
error when I try to open up the form, the error is like this:
a MessageBox with
Error
A user break has occured in GACScan2009.exe
when I click on the details:
Error
GACScan2009.exe
(null)
 at Debugger.Break()
 at KeyboardHook.set_Enabled(Boolean value)
I am using below tools :
Microsoft Visual Studio 2008 SP1
OpenNetCF version 2.3 (Smart Device Framework)
Emulator for Windows CE Version
(virtual x86 Hardware Reference Board provided by Microsoft Corp
version 5.3.0.26)
Below is my code snippet for entire class :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GACSCAN_WINMOBILE2003;
using GACScan2009.ServiceInbound;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;
public partial class InboundNew : Form
   {
       GACScan2009.ServiceInbound.ServiceInbound service = new
ServiceInbound();
       MotherClass mc;
       KeyboardHook m_keyHook;
       public InboundNew(MotherClass mcTemp)
       {
           InitializeComponent();
           m_keyHook = new KeyboardHook();
           mc = mcTemp;
           getUser();
           m_keyHook.KeyDetected += OnKeyDetected;
           m_keyHook.Enabled = true;
       }
       private void getUser()
       {
           lblUser.Text = User.UserName;
       }
       private void getValue()
       {
           string srNo = "";
           srNo = txtGACScanId.Text.Trim();
           AuthSoapHeader autHeader = new AuthSoapHeader();
           autHeader.strUserName = User.UserId;
           autHeader.strPassword = User.Password;
           Cursor.Current = Cursors.WaitCursor;
           service.Url = Global.WebServiceInboundURL();
           service.AuthSoapHeaderValue = autHeader;
           DataTable ResultSet = service.SelectSRNO(srNo)..Tables[0];
           if (ResultSet.Rows.Count == 0)
           {
               MessageBox.Show("No Record Found", "Failed to retrieve
record");
           }
           else
           {
              //dataset retrieval
           }
       }
       private void txtGACScanId_KeyPress(object sender,
KeyPressEventArgs e)
       {
           if (e.KeyChar == (char)Keys.Enter)
           {
               e.Handled = true;
               getValue();
           }
       }
       private void cmdBack_Click(object sender, EventArgs e)
       {
           this.Close();
           this.Dispose();
           m_keyHook.Dispose();
           m_keyHook = null;
           CloseScreen();
       }
       void OnKeyDetected(OpenNETCF.Win32.WM keyMessage, KeyData
keyData)
       {
           if (this.InvokeRequired)
           {
               this.Invoke(new KeyHookEventHandler(OnKeyDetected),
new object[] { keyMessage, keyData });
               return;
           }
           if (keyData.KeyCode == 112)
           {
               /*F1 KEY PRESSED*/
               /*SAVE*/
               //MessageBox.Show("F1 Key Pressed");
               Save_Click_1(null, null);
           }
           if (keyData.KeyCode == 113)
           {
               /*F2 KEY PRESSED*/
               ClearScreen();
           }
           if (keyData.KeyCode == 114)
           {
               /*F3 KEY PRESSED*/
               cmdBack_Click(null, null);
           }
           //char c = (char)keyData.KeyCode;
           //if (keyMessage == WM.KEYUP)
           //{
           //    if (char.IsLetterOrDigit(c))
           //    {
           //    }
           //}
       }
       private void ClearScreen()
       {
           lblSKU.Text = string.Empty;
           lblDescription.Text = string.Empty;
           lblExpDate.Text = string.Empty;
           lblLotNo.Text = string.Empty;
           lblPUOM.Text = string.Empty;
           lblMUOM.Text = string.Empty;
           lblLUOM.Text = string.Empty;
           lbPQTY.Text = string.Empty;
           lblMQty.Text = string.Empty;
           lblLQty.Text = string.Empty;
           lblSiteTo.Text = string.Empty;
           lblSiteLocTo.Text = string.Empty;
           txtGACScanId.Text = String.Empty;
           txtGACScanId.Focus();
       }
       private void InboundNew_Load(object sender, EventArgs e)
       {
           ClearScreen();
       }
       //private void InboundNew_Deactivate(object sender, EventArgs
e)
       //{
       //    ClearScreen();
       //}
       private void confirm()
       {
           string SRNO = txtGACScanId.Text.Trim();
           string UserId = User.UserId;
           AuthSoapHeader autHeader = new AuthSoapHeader();
           autHeader.strUserName = User.UserId;
           autHeader.strPassword = User.Password;
           Cursor.Current = Cursors.WaitCursor;
           service.Url = Global.WebServiceInboundURL();
           service.AuthSoapHeaderValue = autHeader;
           string Result = service.ConfirmInbound(SRNO, UserId);
           if (Result.Trim().Length > 0)
           {
               MessageBox.Show(Result.Trim());
           }
           else
           {
               MessageBox.Show("Confirmed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1);
           }
       }
       private void Save_Click(object sender, EventArgs e)
       {
           DialogResult result = MessageBox.Show("Confirm?",
"Confirm Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
           if (result == System.Windows.Forms.DialogResult.Yes)
           {
               confirm();
           }
       }
       private void Save_Click_1(object sender, EventArgs e)
       {
           if (lblSKU.Text.Trim().Length > 0)
           {
               DialogResult result = MessageBox.Show("Confirm
Save ?", "Confirm Dialog", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
               if (result == System.Windows.Forms.DialogResult.Yes)
               {
                   confirm();
               }
           }
         }
       private void CloseScreen()
       {
           if (mc.inboundNew != null)
           {
               mc.inboundNew.Close();
               mc.inboundNew.Dispose();
               mc.inboundNew  = null;
           }
           InboundMain inbounMain = new InboundMain(this.mc);
           inbounMain.Show();
       }
       private void txtGACScanId_KeyPress_1(object sender,
KeyPressEventArgs e)
       {
           if (e.KeyChar == (char)Keys.Enter)
           {
               e.Handled = true;
               getValue();
           }
       }
   }
I wonder what caused the problems, I've google for hours. Other
solutions are using C++ and call the Dll within the application. I am
not familiar with C++, can I just fix my code, so the code will work
fine on my LXE MX7. Looking forward for your favorable reply.
Best Regards,
 
C

Chris Tacke, eMVP

Your OEM is absolutely cluess. Managed code is processor agnostic, and
anyone that knows anything about programming knows that. The emulator also
hasn't been x86 based in years. So no, they're completely wrong. As to why
the hook fails, I have no idea. You'd have to debug the source, look at the
Win32 error that's returned and try to decipher that. Personally I'd try a
small native sample that does a hook to see if it works at all.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com



Hi, Mr. Chris, tx for your reply.

Tried to bypass the debugger.break, by inserting try catch with an
empty catch procedure in the constructor. Here's the following result
I get :
Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)
at InboundNew..ctor(MotherClass mcTemp)
at InboundMain.btnPutAwayConf_Click(Object sender, EventArgs e)
at Control.OnClick(EventArgs e)
at Button.OnClick(EventArgs e)
at ButtonBase.WnProc(WM wm,Int32 wParam, Int32 IParam)
at Control,_InternalWnProc(WM wm,Int32 wParam, Int32 IParam)
at EVL.EnterMainLoop(IntPtr hwnMain)
at Application.Run(Form fm)
at MotherClass.Main()

Two buttons Continue and Quit --> when I press on Continue, it will
continue to display the screen but with no functionality of
keyboardhook. I have tried to contact the LXE and get below
information :

"As for our MX7 CE, the processor type is StrongArm/Xscale and the
setting on their emulator is X86, which is referring to their PC
Processor. It could be the program can run on the emulator without any
problem, but it can caused some issues if the program installed on our
terminal due to the processor types being used. You may ask them to
recompile the program by using the StrongArm/Xscale processor type"

Is this true?. Please give us your advice.

Best Regards,
Harry



Well the specific error is because I screwed up and left in a
debugger.break
call. What should be happening is it should be throwing a Win32Exception,
so it's would still be failing even without that. The break point is only
hit when the SetWindowsHookEx fails. Can you tell it to continue so that
the exception will come through? That will gie you the error code from the
system.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com


Hi CompactFramework Experts,
I am having this problems for couple of weeks, we are developing a
windows CE 5.0 application. I am using OpenNetCF ver 2.3 community
edition. For keyboard Hook functionality, it's purpose is to trap when
F1,F2,F3 key pressed in the keyboard.
This below code works perfectly on the emulator, but when I deploy to
my LXE MX7 device with CompactFramework 3.5 installed, it generates an
error when I try to open up the form, the error is like this:
a MessageBox with
Error
A user break has occured in GACScan2009.exe
when I click on the details:
Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)
I am using below tools :
Microsoft Visual Studio 2008 SP1
OpenNetCF version 2.3 (Smart Device Framework)
Emulator for Windows CE Version
(virtual x86 Hardware Reference Board provided by Microsoft Corp
version 5.3.0.26)
Below is my code snippet for entire class :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GACSCAN_WINMOBILE2003;
using GACScan2009.ServiceInbound;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;
public partial class InboundNew : Form
{
GACScan2009.ServiceInbound.ServiceInbound service = new
ServiceInbound();
MotherClass mc;
KeyboardHook m_keyHook;
public InboundNew(MotherClass mcTemp)
{
InitializeComponent();
m_keyHook = new KeyboardHook();
mc = mcTemp;
getUser();
m_keyHook.KeyDetected += OnKeyDetected;
m_keyHook.Enabled = true;
}
private void getUser()
{
lblUser.Text = User.UserName;
}
private void getValue()
{
string srNo = "";
srNo = txtGACScanId.Text.Trim();
AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;
Cursor.Current = Cursors.WaitCursor;
service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
DataTable ResultSet = service.SelectSRNO(srNo).Tables[0];
if (ResultSet.Rows.Count == 0)
{
MessageBox.Show("No Record Found", "Failed to retrieve
record");
}
else
{
//dataset retrieval
}
}
private void txtGACScanId_KeyPress(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
private void cmdBack_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
m_keyHook.Dispose();
m_keyHook = null;
CloseScreen();

void OnKeyDetected(OpenNETCF.Win32.WM keyMessage, KeyData
keyData)
{
if (this.InvokeRequired)
{
this.Invoke(new KeyHookEventHandler(OnKeyDetected),
new object[] { keyMessage, keyData });
return;
}
if (keyData.KeyCode == 112)
{
/*F1 KEY PRESSED*/
/*SAVE*/
//MessageBox.Show("F1 Key Pressed");
Save_Click_1(null, null);

if (keyData.KeyCode == 113)
{
/*F2 KEY PRESSED*/
ClearScreen();
}
if (keyData.KeyCode == 114)
{
/*F3 KEY PRESSED*/
cmdBack_Click(null, null);
}
//char c = (char)keyData.KeyCode;
//if (keyMessage == WM.KEYUP)
//{
// if (char.IsLetterOrDigit(c))
// {
// }
//}
}
private void ClearScreen()
{
lblSKU.Text = string.Empty;
lblDescription.Text = string.Empty;
lblExpDate.Text = string.Empty;
lblLotNo.Text = string.Empty;
lblPUOM.Text = string.Empty;
lblMUOM.Text = string.Empty;
lblLUOM.Text = string.Empty;
lbPQTY.Text = string.Empty;
lblMQty.Text = string.Empty;
lblLQty.Text = string.Empty;
lblSiteTo.Text = string.Empty;
lblSiteLocTo.Text = string.Empty;
txtGACScanId.Text = String.Empty;
txtGACScanId.Focus();
}
private void InboundNew_Load(object sender, EventArgs e)
{
ClearScreen();
}
//private void InboundNew_Deactivate(object sender, EventArgs
e)
//{
// ClearScreen();
//}
private void confirm()
{
string SRNO = txtGACScanId.Text.Trim();
string UserId = User.UserId;
AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;
Cursor.Current = Cursors.WaitCursor;
service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
string Result = service.ConfirmInbound(SRNO, UserId);
if (Result.Trim().Length > 0)
{
MessageBox.Show(Result.Trim());
}
else
{
MessageBox.Show("Confirmed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1);
}
}
private void Save_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Confirm ?",
"Confirm Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
private void Save_Click_1(object sender, EventArgs e)
{
if (lblSKU.Text.Trim().Length > 0)
{
DialogResult result = MessageBox.Show("Confirm
Save ?", "Confirm Dialog", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
}
private void CloseScreen()
{
if (mc.inboundNew != null)
{
mc.inboundNew.Close();
mc.inboundNew.Dispose();
mc.inboundNew = null;
}
InboundMain inbounMain = new InboundMain(this.mc);
inbounMain.Show();

private void txtGACScanId_KeyPress_1(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
}
I wonder what caused the problems, I've google for hours. Other
solutions are using C++ and call the Dll within the application. I am
not familiar with C++, can I just fix my code, so the code will work
fine on my LXE MX7. Looking forward for your favorable reply.
Best Regards,
 
H

harry

Your OEM is absolutely cluess.  Managed code is processor agnostic, and
anyone that knows anything about programming knows that.  The emulator also
hasn't been x86 based in years.  So no, they're completely wrong.  Asto why
the hook fails, I have no idea.  You'd have to debug the source, look at the
Win32 error that's returned and try to decipher that.  Personally I'd try a
small native sample that does a hook to see if it works at all.

--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com


Hi, Mr. Chris, tx for your reply.

Tried to bypass the debugger.break, by inserting try catch with an
empty catch procedure in the constructor. Here's the following result
I get :
Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)
at InboundNew..ctor(MotherClass mcTemp)
at InboundMain.btnPutAwayConf_Click(Object sender, EventArgs e)
at Control.OnClick(EventArgs e)
at Button.OnClick(EventArgs e)
at ButtonBase.WnProc(WM wm,Int32 wParam, Int32 IParam)
at Control,_InternalWnProc(WM wm,Int32 wParam, Int32 IParam)
at EVL.EnterMainLoop(IntPtr hwnMain)
at Application.Run(Form fm)
at MotherClass.Main()

Two buttons Continue and Quit --> when I press on Continue, it will
continue to display the screen but with no functionality of
keyboardhook. I have tried to contact the LXE and get below
information :

"As for our MX7 CE, the processor type is StrongArm/Xscale and the
setting on their emulator is X86, which is referring to their PC
Processor. It could be the program can run on the emulator without any
problem, but it can caused some issues if the program installed on our
terminal due to the processor types being used. You may ask them to
recompile the program by using the StrongArm/Xscale processor type"

Is this true?. Please give us your advice.

Best Regards,
Harry

Well the specific error is because I screwed up and left in a
debugger.break
call. What should be happening is it should be throwing a Win32Exception,
so it's would still be failing even without that. The break point is only
hit when the SetWindowsHookEx fails. Can you tell it to continue so that
the exception will come through? That will gie you the error code from the
system.

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded communityhttp://community.OpenNETCF.com
news:3cdc0175-ac8d-4dc3-84c7-75617fbeadf2@w35g2000prg.googlegroups.com....
Hi CompactFramework Experts,
I am having this problems for couple of weeks, we are developing a
windows CE 5.0 application. I am using OpenNetCF ver 2.3 community
edition. For keyboard Hook functionality, it's purpose is to trap when
F1,F2,F3 key pressed in the keyboard.
This below code works perfectly on the emulator, but when I deploy to
my LXE MX7 device with CompactFramework 3.5 installed, it generates an
error when I try to open up the form, the error is like this:
a MessageBox with
Error
A user break has occured in GACScan2009.exe
when I click on the details:
Error
GACScan2009.exe
(null)
at Debugger.Break()
at KeyboardHook.set_Enabled(Boolean value)
I am using below tools :
Microsoft Visual Studio 2008 SP1
OpenNetCF version 2.3 (Smart Device Framework)
Emulator for Windows CE Version
(virtual x86 Hardware Reference Board provided by Microsoft Corp
version 5.3.0.26)
Below is my code snippet for entire class :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GACSCAN_WINMOBILE2003;
using GACScan2009.ServiceInbound;
using OpenNETCF.Windows.Forms;
using OpenNETCF.Win32;
public partial class InboundNew : Form
{
GACScan2009.ServiceInbound.ServiceInbound service = new
ServiceInbound();
MotherClass mc;
KeyboardHook m_keyHook;
public InboundNew(MotherClass mcTemp)
{
InitializeComponent();
m_keyHook = new KeyboardHook();
mc = mcTemp;
getUser();
m_keyHook.KeyDetected += OnKeyDetected;
m_keyHook.Enabled = true;
}
private void getUser()
{
lblUser.Text = User.UserName;
}
private void getValue()
{
string srNo = "";
srNo = txtGACScanId.Text.Trim();
AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;
Cursor.Current = Cursors.WaitCursor;
service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
DataTable ResultSet = service.SelectSRNO(srNo).Tables[0];
if (ResultSet.Rows.Count == 0)
{
MessageBox.Show("No Record Found", "Failed to retrieve
record");
}
else
{
//dataset retrieval
}
}
private void txtGACScanId_KeyPress(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
private void cmdBack_Click(object sender, EventArgs e)
{
this.Close();
this.Dispose();
m_keyHook.Dispose();
m_keyHook = null;
CloseScreen();
}
void OnKeyDetected(OpenNETCF.Win32.WM keyMessage, KeyData
keyData)
{
if (this.InvokeRequired)
{
this.Invoke(new KeyHookEventHandler(OnKeyDetected),
new object[] { keyMessage, keyData });
return;
}
if (keyData.KeyCode == 112)
{
/*F1 KEY PRESSED*/
/*SAVE*/
//MessageBox.Show("F1 Key Pressed");
Save_Click_1(null, null);
}
if (keyData.KeyCode == 113)
{
/*F2 KEY PRESSED*/
ClearScreen();
}
if (keyData.KeyCode == 114)
{
/*F3 KEY PRESSED*/
cmdBack_Click(null, null);
}
//char c = (char)keyData.KeyCode;
//if (keyMessage == WM.KEYUP)
//{
// if (char.IsLetterOrDigit(c))
// {
// }
//}
}
private void ClearScreen()
{
lblSKU.Text = string.Empty;
lblDescription.Text = string.Empty;
lblExpDate.Text = string.Empty;
lblLotNo.Text = string.Empty;
lblPUOM.Text = string.Empty;
lblMUOM.Text = string.Empty;
lblLUOM.Text = string.Empty;
lbPQTY.Text = string.Empty;
lblMQty.Text = string.Empty;
lblLQty.Text = string.Empty;
lblSiteTo.Text = string.Empty;
lblSiteLocTo.Text = string.Empty;
txtGACScanId.Text = String.Empty;
txtGACScanId.Focus();
}
private void InboundNew_Load(object sender, EventArgs e)
{
ClearScreen();
}
//private void InboundNew_Deactivate(object sender, EventArgs
e)
//{
// ClearScreen();
//}
private void confirm()
{
string SRNO = txtGACScanId.Text.Trim();
string UserId = User.UserId;
AuthSoapHeader autHeader = new AuthSoapHeader();
autHeader.strUserName = User.UserId;
autHeader.strPassword = User.Password;
Cursor.Current = Cursors.WaitCursor;
service.Url = Global.WebServiceInboundURL();
service.AuthSoapHeaderValue = autHeader;
string Result = service.ConfirmInbound(SRNO, UserId);
if (Result.Trim().Length > 0)
{
MessageBox.Show(Result.Trim());
}
else
{
MessageBox.Show("Confirmed successfully", "Success",
MessageBoxButtons.OK, MessageBoxIcon.None,
MessageBoxDefaultButton.Button1);
}
}
private void Save_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("Confirm ?",
"Confirm Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
private void Save_Click_1(object sender, EventArgs e)
{
if (lblSKU.Text.Trim().Length > 0)
{
DialogResult result = MessageBox.Show("Confirm
Save ?", "Confirm Dialog", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == System.Windows.Forms.DialogResult.Yes)
{
confirm();
}
}
}
private void CloseScreen()
{
if (mc.inboundNew != null)
{
mc.inboundNew.Close();
mc.inboundNew.Dispose();
mc.inboundNew = null;
}
InboundMain inbounMain = new InboundMain(this.mc);
inbounMain.Show();
}
private void txtGACScanId_KeyPress_1(object sender,
KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
getValue();
}
}
}
I wonder what caused the problems, I've google for hours. Other
solutions are using C++ and call the Dll within the application. I am
not familiar with C++, can I just fix my code, so the code will work
fine on my LXE MX7. Looking forward for your favorable reply.
Best Regards,
Harry


I finally got a solution without using OpenNetCF 2.3,

Thanks.

Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top