"无法加载DLL"使用VideoOCR.dll时出错

时间:2017-07-31 07:18:47

标签: c# xaml dll uwp uwp-xaml

我正在尝试使用UWP应用程序使用VideoOCR dll来读取Passport MRZ代码。但是,只要我加载DLL,应用程序完全崩溃并出现以下错误:无法加载DLL' videoocr.dll':找不到指定的模块。 (HRESULT异常:0x8007007E)

** bin文件夹中的dll位置

public partial class ViewModel
{
    // Location of the DLL required
    private const String DLL_LOCATION = "videoocr.dll";

    // structure required for MRZ data
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct DLL_MRZDATA
    {
        [MarshalAs(UnmanagedType.BStr)]
        public String RawMRZ;

        [MarshalAs(UnmanagedType.BStr)]
        public String DocumentNumber;

        [MarshalAs(UnmanagedType.BStr)]
        public String DOB;

        [MarshalAs(UnmanagedType.BStr)]
        public String Expiry;

        [MarshalAs(UnmanagedType.BStr)]
        public String Issuer;

        [MarshalAs(UnmanagedType.BStr)]
        public String Nationality;

        [MarshalAs(UnmanagedType.BStr)]
        public String LastNames;

        [MarshalAs(UnmanagedType.BStr)]
        public String FirstNames;

        [MarshalAs(UnmanagedType.BStr)]
        public String Type;

        [MarshalAs(UnmanagedType.BStr)]
        public String Discretionary1;

        [MarshalAs(UnmanagedType.BStr)]
        public String Discretionary2;

        [MarshalAs(UnmanagedType.BStr)]
        public String Gender; // added 130810
    }

    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct DLL_STATUS
    {
        [MarshalAs(UnmanagedType.Bool)]
        public Boolean CameraPresent;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean PassportPresent;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean RFIDPresent;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean Active;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean Busy;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean MRZDecoded;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean RFIDDecoded;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean UVEnabled;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean RFIDEnabled;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean ColourEnabled;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean AutoStopEnabled;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean InfraredEnabled;

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean BadDecode; // added 110810

        [MarshalAs(UnmanagedType.Bool)]
        public Boolean DocumentPresent; // added 110810
    }

    // DLL function signatures
    [DllImport(DLL_LOCATION)]
    private static extern Boolean voInitialiseReader(Boolean InfraRed, Boolean Colour, Boolean UV, Boolean RFID, Boolean AutoStop);

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voStartRead();

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voStopRead();

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voQueryReaderState(ref DLL_STATUS Status);

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voRegisterMrzCallback(MRZDelegate Callback, [MarshalAs(UnmanagedType.U4)] ref UInt32 Parameter);

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voRegisterImageCallback(ImageDelegate Callback, ref UInt32 Parameter);

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voTerminate();

    [DllImport(DLL_LOCATION)]
    private static extern Boolean voGetImage(int ImageType, Boolean FullSize);
}

这是我的VM代码

public partial class ViewModel
{
    // Delegate definitions
    private delegate void updatePictureBox(int bitmap, int imageType);

    private delegate void MRZDelegate(ref UInt32 Parameter, ref DLL_MRZDATA Data);

    private delegate void ImageDelegate(ref UInt32 Parameter, int ImageType, IntPtr hBitmap);

    private delegate void BadDecodeDelegate(ref UInt32 Parameter, [MarshalAs(UnmanagedType.BStr)] String BadMRZ, UInt32 hBitmap);

    private delegate void updateMrzTextBox(string text);

    private DLL_STATUS Status;
    private MRZDelegate md;
    private ImageDelegate id;

    public ViewModel()
    {
        // Get Form class as we need to update when data arrives

        // create the delegates for the callback functions
        md = new MRZDelegate(MRZCallback);
        id = new ImageDelegate(ImageCallback);

        Status = new DLL_STATUS();
    }

    public void initialiseReader()
    {
        // Start up the reader Set up capture of all illumination types and RFID
        Boolean Temp = voInitialiseReader(true, true, true, true, false);

        UInt32 Val = 0;

        // register image and MRZ callback functions
        voRegisterMrzCallback(md, ref Val);
        voRegisterImageCallback(id, ref Val);
    }

    public void reInitialiseReader()
    {
        // Terminates all the process threads and goes into an ide state
        voTerminate();

        // Set up capture of all illumination types and RFID
        voInitialiseReader(true, true, true, true, false);

        UInt32 Val = 0;

        // register image and MRZ callback functions
        voRegisterMrzCallback(md, ref Val);
        voRegisterImageCallback(id, ref Val);
    }

    public void startReader()
    {
        // Start the capture system of the scanner
        Boolean status = voStartRead();
    }

    public void getIRImage()
    {
        // Takes a colour image of whats on scanner plate
        voGetImage(0, true);
    }

    public void getColourImage()
    {
        // Takes a colour image of whats on scanner plate
        voGetImage(1, true);
    }

    public void getUVImage()
    {
        // Takes a colour image of whats on scanner plate
        voGetImage(2, true);
    }

    public Boolean getScannerStatus()
    {
        // Get current status of the system
        Boolean returnValue = voQueryReaderState(ref Status);
        return (returnValue);
    }

    private void updateTextBox(string text)
    {
        //frontend.textBoxMRZ.Text = text;
    }

    private void updatePicture(int bitmap, int imageType)
    {
        //switch (imageType)
        //{
        //    case 0:

        // frontend.pictureBoxGrey.Image = bitmap; break;

        // case 1:

        // frontend.pictureBoxColour.Image = bitmap; break;

        // case 2:

        // frontend.pictureBoxUV.Image = bitmap; break;

        //    case 3:
        //        frontend.pictureBoxRFID.Image = bitmap;
        //        break;
        //}
    }

    private void MRZCallback(ref UInt32 Parameter, ref DLL_MRZDATA Data)
    {
        // Make sure the text box update is running in the same thread as the form ;
        //frontend.textBoxMRZ.Invoke(new updateMrzTextBox(updateTextBox), Data.RawMRZ);
    }

    private void ImageCallback(ref UInt32 Parameter, int ImageType, IntPtr Handle)
    {
        //Bitmap bitmap;

        // depending on the image type - store and display the new image
        //switch (ImageType)
        //{
        //    case 0:
        //        bitmap = System.Drawing.Image.FromHbitmap(Handle);
        //        frontend.pictureBoxGrey.Invoke(new updatePictureBox(updatePicture), new Object[] { bitmap, ImageType });
        //        break;

        // case 1: bitmap = (Bitmap)System.Drawing.Image.FromHbitmap(Handle).Clone();
        // frontend.pictureBoxColour.Invoke(new updatePictureBox(updatePicture), new Object[] {
        // bitmap, ImageType} ); break;

        // case 2: bitmap = System.Drawing.Image.FromHbitmap(Handle);
        // frontend.pictureBoxUV.Invoke(new updatePictureBox(updatePicture), new Object[] { bitmap,
        // ImageType }); break;

        //    case 3:
        //        bitmap = System.Drawing.Image.FromHbitmap(Handle);
        //        frontend.pictureBoxRFID.Invoke(new updatePictureBox(updatePicture), new Object[] { bitmap, ImageType });
        //        break;
        //}
    }

    public Boolean RFIDPresent { get { return (Status.RFIDPresent); } }
    public Boolean RFIDecoded { get { return (Status.RFIDDecoded); } }
    public Boolean busy { get { return (Status.Busy); } }
    public Boolean passportPresent { get { return (Status.PassportPresent); } }
    public Boolean documentPresent { get { return (Status.DocumentPresent); } }
    public Boolean MRZDecoded { get { return (Status.MRZDecoded); } }
}

这个代码第二件事是使用System.Drawing(Bitmap),但是UWP不支持它,所以我可以使用什么?

0 个答案:

没有答案