Windows Universal App integrates C/+ + DLLs

Source: Internet
Author: User
Tags sprintf

With the popularity of Windows 10, Microsoft started to push universal application development. Universal applications, like Android and iOS apps, run in the sandbox, in the desktop environment EXE can not double-click Run. You can submit to Windows Store after you make a appx package. Any device running Windows 10 can run. So is it possible to have an existing C + + SDK compatible at the time of development? The answer is yes, but there are some limitations. If you want the SDK to be compatible with all devices, you need to provide line x86, x64, arm three version DLLs. I experimented with the Dynamsoft Barcode SDK.

Refer to the original text: How to Create a Universal Barcode Reader on Windows Ten with C + + Legacy Code

Xiao Ling

Translation: Yushulx

Preparatory work
    • Activate developer mode in Windows 10.

    • Install Visual Studio 2015.

    • Install the Dynamsoft Barcode SDK.

Hello World

Writing Hello World is simple enough to learn about Microsoft's online tutorial https://msdn.microsoft.com/en-us/library/windows/apps/dn996906.aspx.

Integrating the C + + SDK in the Universal app

Create a universal app.

Add the Image, Button , and TextBlockin mainpage.xaml :

<scrollviewer grid.row= "1"  verticalscrollmode= "Auto"  verticalscrollbarvisibility= "Auto"  verticalalignment= "Top" >                 <StackPanel>                     <grid x:name= "Image"  Margin= "0,0,0,5"   Verticalalignment= "Top" >                         <image x:name= "PreviewImage"   Horizontalalignment= "left"  verticalalignment= "Top"  maxwidth= "" "/>                     </Grid>                      <stackpanel orientation= "Horizontal"  margin= "0, 0, 0, 5"  verticalalignment= "Top" >                          <button x:name= "button"  margin= "0, 0, 5, 0"  Click= "Button_ Click " verticalalignment=" Top >                             < viewbox maxheight= " maxwidth=" >                                  <symbolicon symbol= "OpenFile"/>                              </viewbox>                         </Button>                         <textblock  x:name= "Barcoderesults"  margin= "0,0,0,10"  textwrapping= "Wrap"  text= "Results:"  Height = " width="  verticalalignment= "Stretch"  horizontalalignment= "left"  />                      </StackPanel>                 </stackpanel>            </ Scrollviewer>

To load a file using fileopenpicker :

fileopenpicker^ picker = ref new Fileopenpicker ();p icker->filetypefilter->append (". bmp");p icker-> Suggestedstartlocation = Pickerlocationid::P ictureslibrary;

C + + pointers to get image data from WriteableBitmap :

byte* Getpointertopixeldata (ibuffer^ pixelbuffer, unsigned int *length) {if (length! = nullptr) {*length = P    ixelbuffer->length;    }//Query the Ibufferbyteaccess interface.    Comptr<ibufferbyteaccess> bufferbyteaccess;     Reinterpret_cast<iinspectable*> (Pixelbuffer)->queryinterface (Iid_ppv_args (&bufferByteAccess));    Retrieve the buffer data.    byte* pixels = nullptr;    Bufferbyteaccess->buffer (&pixels); return pixels;}

Use Decodebuffer to detect image data. Because there is no corresponding interface, you need to construct the data yourself (bitmapinfoheader + Image data). The Bitmapinfoheader is 40 bytes, plus the actual data:

Char *total = (char *) malloc (len + 40); Bitmapinfoheader bitmap_info = {max, width, height, 0, 0, Len, 0, 0, 0, 0};memcpy (total, &bitmap_info, +); char * data = Total + 40;memcpy (data, buffer, Len);

Get barcode Results:

IRet = reader.     Decodebuffer ((unsigned char*) total, Len + 40);    Output Barcode Result psztemp = (char*) malloc (4096);        if (iRet! = DBR_OK) {sprintf (psztemp, "Failed to read barcode:%s\r\n", dbr_geterrorstring (IRet));        Free (psztemp);    return nullptr;    } Pbarcoderesultarray paryresult = NULL; Reader. Getbarcodes (&paryresult);

The next step is to convert C String into platform::string^. Answers can be found on StackOverflow:

Results = ref new array<string^> (Paryresult->ibarcodecount);     for  (iindex = 0; iindex < paryresult->ibarcodecount; iindex++)     {        sprintf (pszTemp,  "Barcode % D:\r\n ",  iindex + 1);         sprintf (pszTemp, "%s     page: %d\r\n ",  psztemp, paryresult->ppbarcodes[iindex]->ipagenum) ;         sprintf (psztemp,  "%s    type: % S\r\n ",  psztemp, getformatstr (Paryresult->ppbarcodes[iindex]->llformat));         pszTemp1 =  (char*) malloc (paryresult->ppbarcodes[iindex]-> ibarcodedatalength + 1);         memset (PszTemp1, 0,  paryresult->ppbarcodes[iindex]->ibarcodedatalength + 1);         memcpy ( Psztemp1, paryresult->ppbarcodes[iindex]->pbarcodedata, paryresult->ppbarcodes[iindex]-> Ibarcodedatalength);         sprintf (psztemp,  "%s     value: %s\r\n ", &NBSP;PSZTEMP,&NBSP;PSZTEMP1);          // http://stackoverflow.com/questions/11545951/how-to-convert-from-char-to-platformstring-c-cli         std::string s_str = std::string (pszTemp);         std::wstring wid_str = std::wstring (S_str.begin (),  s_str.end ());         const wchar_t* w_char =  wid_str.c_str ();         outputdebugstring (W_char);          barcode_result = ref new string (W_char);         Results->set (Iindex, barcode_result);         free (PSZTEMP1);     }

From <dynamsoft Barcode sdk>\redist\c_c++ directory copy DynamsoftBarcodeReaderx86.dll to DYNAMSOFTBARCODEREADER\DEBUG\DYNAMSOFTBARCODEREADER\APPX directory.

You can now run the program through the ctrl+f5 or menu.

Universal Barcode Reader:

Known Issues
    • When developing universal applications, some C interfaces are limited, so the decodefile interface provided in the SDK is not available because fopenneeds to be called. You can refer to the CRT functions not supported in Universal Windows Platform apps for specific limitations.

    • The QR code decoding provided in the SDK is invalid.

    • Only BMP images are used when using decodebuffer .

Source

Https://github.com/dynamsoftsamples/universal-windows-barcode-reader


Windows Universal App integrates C/+ + DLLs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.