.net 使用仿真器进行条形码扫描的Windows Mobile应用程序

.net 使用仿真器进行条形码扫描的Windows Mobile应用程序,.net,windows-mobile,.net,Windows Mobile,我想为Motorolo MC 9190 G mobile开发一个简单的应用程序。它内置了条形码扫描仪,我想扫描条形码并将其显示在msg框中。我没有手机,所以我必须在模拟器中测试它。当我在emulator中部署代码时,它会给出null异常错误。我的代码是 我添加了sample.dll Private barcodeReader As Symbol.Barcode.Reader // error occurs here itself barcodeReader = New Symbol.Barco

我想为Motorolo MC 9190 G mobile开发一个简单的应用程序。它内置了条形码扫描仪,我想扫描条形码并将其显示在msg框中。我没有手机,所以我必须在模拟器中测试它。当我在emulator中部署代码时,它会给出null异常错误。我的代码是 我添加了sample.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)

我是这方面的新手。。请帮助..

您需要创建一个界面和一个模拟,大致如下:

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";
    }
}
然后在运行时,使用一些逻辑来确定您所在的平台并创建适当的实例:

public class Foo
{
    IBarcodeReader Reader { get; set; }

    public Foo()
    {
        if (ThisIsASymbolDevice)
        {
            Reader = new SymbolReader();
        }
        else
        {
            Reader = new MockReader();
        }

        var barcode = Reader.ReadBarcode();
    }
}

很好的解决方法。由于仿真器不知道也不支持条形码读取器,因此不能在仿真器上使用符号DLL和运行时。通过使用兼容层,您可以模拟您认为真正的硬件将提供的功能。我们还可以在OpenNETCF.IoC模块中将SymbolReader、MyOwnScanner作为服务实现;-)你的模拟器有条形码阅读器吗?您如何模拟读取条形码?