简体   繁体   中英

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 don't have the source code with us, So not able to do with the Windows Run time component.

Please let me know how can I import the c++ dll inside the Visual C# universal windows application.

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. I have tried the dllimport but it is throwing dll not found exception.

Firstly, UWP can't import a legacy C++ dll just by DLLImport.

If you want to import legacy c++ functions to C#, the first suggestion is to wrap that C++ logic using a WinRT component.

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 '. Then in the proper cs file, using DllImport to PInvoke the dll.

In addition, you need to make sure your dll is not using prohibited APIs in WinRT. You can check this by using /ZW compile option for the dll. There is a similar thread , you can refer to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM