Windows Mobile Application for barcode scanning with Emulator

China☆狼群 提交于 2019-12-07 16:42:44

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!