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
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