i want to develop simple application for Motorolo MC 9190 G mobile it has inbuilt bar code scanner, i want to scan the bar code and display them in the msg box. i dont have the mobile so i have to test it in Emulator. when i deploy the code in emulator it gives null exception error. my code is i add sample.barcode dll
Private barcodeReader As Symbol.Barcode.Reader // error occurs here itself
barcodeReader = New Symbol.Barcode.Reader()
barcodeReader.Actions.Enable()
Dim nextReaderData As Symbol.Barcode.ReaderData = barcodeReader.GetNextReaderData()
MessageBox.Show(nextReaderData.Text)
i mm beginner to this.. pls help..
You need to create an interface and a mock, something along these lines:
interface IBarcodeReader
{
string ReadBarcode();
}
public class SymbolReader : IBarcodeReader
{
private Reader m_reader;
public SymbolReader()
{
m_reader = new SymbolReader.Barcode.Reader;
m_reader.Actions.Enable();
}
public string ReadBarcode()
{
return m_reader.GetNextReaderData().Text;
}
}
public class MockReader : IBarcodeReader
{
public string ReadBarcode()
{
return "MOCK ABCDE";
}
}
Then at runtime, use some logic to determine the platform you're on and create the appropriate instance:
public class Foo
{
IBarcodeReader Reader { get; set; }
public Foo()
{
if (ThisIsASymbolDevice)
{
Reader = new SymbolReader();
}
else
{
Reader = new MockReader();
}
var barcode = Reader.ReadBarcode();
}
}
来源:https://stackoverflow.com/questions/15158792/windows-mobile-application-for-barcode-scanning-with-emulator