[UWP]如何在UWP应用程序中使用基于COM的API? [英] [ UWP ] how to use a COM based API in UWP application?

查看:162
本文介绍了[UWP]如何在UWP应用程序中使用基于COM的API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款能够与扫描仪配合使用的UWP应用。此应用程序是一个POS应用程序,并读取条形码。 Windows 10提供内置条形码扫描器类。这用于UWP应用程序,但功能有限。你可以在这里查看。



>用于UWP的Window 10条形码扫描仪<仅限创建者更新>



!我们应该在我们的应用程序中使用SNAPI协议和条形码扫描。因此,我们不再使用内置的.NET类,而是使用第三方条码扫描器SDK,它在其代码中为我们提供了SNAPI协议。它是基于COM的API。你可以在这里查看。



适用于Windows的Zebra扫描仪SDK



此SDK已经很老了。它适用于较旧的.NET平台,如Winforms和WPF等。但我无法从UWP应用程序中使用它的服务。

我们想在我们的UWP应用程序中使用这个基于COM的API,但我们无法找到从UWP使用它的方法。有没有办法在UWP应用程序中使用基于COM的API?



我尝试过:



我们尝试制作WCF服务,间接使用第三方SDK,但这是一个大问题的重要解决方案,它也增加了代码复杂性。

我也用过PCL(可移植类库)从UWP使用该API,但PCL也无法访问基于COM的API。

这是我几天都被困住的问题,找不到互联网上的任何适当的解决方案。

I’m currently working on a UWP app to work with scanners. This application is a POS app and reads barcodes. Windows 10 Provides its built in barcode scanner class. That is used for UWP apps but it is limited in functionalities. you can check it here.

Window 10 barcode Scanner for UWP < Available in Creaters Update only >

further! we are supposed to use SNAPI protocol with barcode scanning in our app. So instead of working with built in .NET class we proceeded with 3rd Party Barcode Scanner SDK, which provides us the SNAPI Protocol in its Code. It is a COM based API. You can check it here.

Zebra Scanner SDK for Windows

This SDK is very old. It works fine with older .NET platforms like Winforms and WPF etc. but I'm unable to consume its services from UWP app.
We want to use This COM based API in our UWP app, but we are unable to find a way to consume it from UWP. Is there a way to use COM based APIs in UWP apps?

What I have tried:

we tried to make WCF Services instead, to consume 3rd party SDK indirectly but this is a heavy solution of a large problem and it increases code complexity as well.
I also used PCL ( Portable class library ) to consume that API from UWP but PCL is also not able to access COM based APIs.
This is problem that on I’ve been stuck from few days, couldn’t find any appropriate solution on Internet as well.

推荐答案

一些COM组件在UWP应用程序中工作,大多数不能。为什么?



UWP应用程序在沙箱中运行,其中应用程序需要权限才能执行任何操作。它们仅限于使用Win32和COM API的有限子集。大多数现有的COM组件,除非它们是为UWP明确编写的,否则将无法工作,因为它们调用的API不存在或在受限制的沙箱中不可用。



由于它具有通用性质,并非所有平台都可以处理COM或者可以真正拥有任何COM支持,例如Windows Phone。这就是为什么你真的没有在UWP中使用COM组件的好解决方案。



您可以尝试通过这个 [ ^ ]文章。它适用于Windows 8,但它仍适用于Win10。祝你好运!
Some COM components work in UWP apps, most don't. Why?

UWP applications run in a "sandbox" where the application needs permissions to do just about anything. They are restricted to using a limited subset of the Win32 and COM API's. Most existing COM components, unless they are explicitly written for UWP, will not work because they call API's that don't exist or are not available in the restricted sandbox.

Because of it's "universal" nature, not all platforms can handle COM or can really have any COM support, like Windows Phone. That's why you really don't have a good solution for using COM components in UWP.

You can try going through this[^] article. It's for Windows 8, but it still applies to Win10. Good luck!


这篇关于[UWP]如何在UWP应用程序中使用基于COM的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆