[英]How to import C++ Legacy DLL in C# UWP application without Windows Runtime Component
We have a requirement to import a C++ legacy dll inside C# UWP application and access the methods inside the c++ classes. We have a requirement to import a C++ legacy dll inside C# UWP application and access the methods inside the c++ classes. We don't have the source code with us, So not able to do with the Windows Run time component.我们没有源代码,因此无法使用 Windows 运行时组件。
Please let me know how can I import the c++ dll inside the Visual C# universal windows application.请让我知道如何在 Visual C# 通用 Z0F4137ED1502B5055D6083AA2ZB 应用程序中导入 c++ dll。
I am able to add the dll as a reference in visual C++ application, But not able to do it in visual C# uwp application.我可以在视觉 C++ 应用程序中添加 dll 作为参考,但无法在视觉 C# ZD0836D7D5DBADA3AF4 应用程序中做到这一点。 I have tried the dllimport but it is throwing dll not found exception.我已经尝试了 dllimport,但它抛出了 dll not found 异常。
Firstly, UWP can't import a legacy C++ dll just by DLLImport.首先,UWP 不能仅通过 DLLImport 导入旧版 C++ dll。
If you want to import legacy c++ functions to C#, the first suggestion is to wrap that C++ logic using a WinRT component.如果要将旧版 c++ 函数导入 C#,第一个建议是使用 WinRT 组件包装该 C++ 逻辑。
And if you want to PInvoke the dll, you can follow these steps (You can refer to this thread ): First, add dll into your UWP project making sure to set its type as ' content '.如果您想 PInvoke dll,您可以按照以下步骤操作(您可以参考此线程):首先,将 dll 添加到您的 UWP 项目中,确保将其设置为“内容”。 Then in the proper cs file, using DllImport to PInvoke the dll.然后在正确的 cs 文件中,使用 DllImport PInvoke dll。
In addition, you need to make sure your dll is not using prohibited APIs in WinRT.此外,您需要确保您的 dll 没有在 WinRT 中使用禁止的 API。 You can check this by using /ZW compile option for the dll.您可以使用 dll 的 /ZW 编译选项来检查这一点。 There is a similar thread , you can refer to it.有一个类似的线程,你可以参考它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.