[UWP] [C#]从UWP应用程序调用c#dll [英] [UWP][C#]Calling c# dll from a UWP app

查看:626
本文介绍了[UWP] [C#]从UWP应用程序调用c#dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UWP应用的新手。我需要从UWP应用程序调用C#dll。  c#dll枚举USB设备并使用setup api调用和  CreateFile()等获取设备句柄。  是否可以从a调用此DLL UWP app?
I am new to UWP apps. I need to call a C# dll from a UWP app. The c# dll enumerates USB devices and obtains handle to the devices using setup api calls and CreateFile() etc.  Is it possible to call this DLL from a UWP app?

推荐答案

你好, 

Hello, 

欢迎来到开发通用Windows应用程序
论坛!

请阅读粘性帖子,尤其是  发布指南:subject行
代码
   Windows 10 SDK和工具的已知问题 ,
并且不要忘记在您的问题中添加标记。

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools , and don't forget add tag to your question.

C#dll你的意思是.NET类库吗?由于存在一些安全限制,您无法从UWP应用程序(桌面版)直接使用任何.NET类库。您可以做的是创建一些沟通层。 

By C# dll you mean .NET Class Library exact ? You can not direct consume any .NET Class Library from UWP app (Desktop version) because of there is some security restrictions. What you can do is create some communication layer. 

但在描述如何创建沟通之前,让我介绍一下其他解决方案。

But before describe how you can create that communication let me introduce an other solutions.

1)如果您的应用程序是用于桌面设备,那么您可以创建标准WPF应用程序并在使用
转换后
Desktop Bridge
是否有资格上传Windows 10 PC的Windows商店

samples

1) If your app is for Desktop devices then you can create standard WPF app and after convert it by using Desktop Bridge for be it eligible to upload  Windows store for Windows 10 PC's samples.

2)UWP拥有自己的API来处理设备和
这是官方样本
怎么样工作中。注意此代码不仅适用于所有Windows 10设备上的PC。

2) UWP has its own API for working with devices and this is official sample how it is working. NOTE this code work on on all Windows 10 devices not only PCs.

现在如何使用.Net dll。

Now how to consume .Net dll.

1)您可以创建COM代理存根并将它们用作通信层
sample

1) You can create COM Proxy Stubs and work with them as communication layer sample.

2)创建C#console app消耗.dll,然后通过AppService与您的UWP应用程序通信,它与使用Desktop Bridge大致相同。 

2) Create C# console app consume .dll from it and then via AppService communicate with your UWP app, it is about the same as using Desktop Bridge. 

首先,您应该知道为什么需要选择UWP而不是经典桌面应用。如果您需要抄送所有Windows 10设备(PC,Mobile,XBOX,Holo),那么您需要UWP。但对于PC,您只能使用桌面桥。

First of all you should know why you need to choose UWP instead of Classic Desktop app. If you need to cower all Windows 10 devices (PC, Mobile, XBOX, Holo) then you need UWP. But for PC only you can use Desktop bridge.


这篇关于[UWP] [C#]从UWP应用程序调用c#dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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