简体   繁体   English

How to import C++ Legacy DLL in C# UWP application without Windows Runtime Component

[英]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.

相关问题 UWP C# 和 Windows 运行时组件 C++ 打开文件时出现权限被拒绝错误 - UWP C# and Windows Runtime Component C++ Permission Denied error when opening file 如何在用 c# 编写的 UWP 应用程序中从 Windows 运行时组件 (c#) 调用函数? - How do you call functions from a Windows Runtime Component (c#) in a UWP app written in c#? Windows运行时组件C ++结构/类返回到UWP - Windows Runtime Component C++ Struct/Classes Returned to UWP C#中的C ++运行时导入失败的非托管DLL - C++ Unmanaged DLL in C# runtime import failure 如何在Windows Phone中调试C ++代码(8)运行时组件或VS 2013中的C ++ DLL - How to debug C++ code in a Windows Phone (8) Runtime Component or C++ DLL in VS 2013 如何在C ++运行时组件中的Windows Phone 8.1 XAML应用程序中使用C ++ DLL - How to use a C++ dll in Windows Phone 8.1 XAML App within C++ Runtime Component 从C#.NET Windows应用程序调用C ++ dll时出现运行时错误 - runtime error when calling a C++ dll from C# .NET windows application 如何从 c++/cx uwp 项目调用 windows 运行时组件? - How to call windows runtime component from c++/cx uwp project? 在C#应用程序中导入和使用C ++ DLL函数 - Import and use C++ DLL functions in C# application C#和C ++之间的Windows(电话)运行时组件流 - Windows (Phone) Runtime Component stream between C# and C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM