这不是“如何从 C# 调用 C++ 函数”的重复
我知道如何为常规 PC 应用程序执行此操作,并且我尝试过并且可以正常工作:
这称为 P/Invoke
1.
Create a C++ dll project,
but you can't add the C++ dll project as a reference to the C# project.
Copy the dll from C++, and paste the dll to the C# exe folder
2.
in C# use [DllImport...]
in C++ use extern "C" __declspec(dllexport) ...
但是当我在 WindowsPhone 上执行此操作时,失败了。
有两种类型的非托管 C++ native dll 项目用于 Windows 手机,我都试过了
DLL (Windows Phone) <- WRT DLL 8.1
DLL (Windows Phone Silverlight 8.1)
我不知道在哪里放置dll文件。
因为finally exe是一个包。
我无法将 dll 与包放在同一文件夹中。
dll 应该在包中,作为包的一部分。
所以我尝试在 C# WP8.1 SL 项目中添加 dll 作为资源文件。
但是函数调用失败了。
那么我想知道的是,dll如何放置,dll如何与WP8.1 SL项目 Hook ?
以前有人试过吗?
谢谢你们的回答。
//------------------------------------------------ ------------
所以正确的方法是
对于 [C# WP8.1 SL] 项目,
我需要
create a [C++ Runtime Component DLL] <- as bridge
create a [C++ Native WP SL DLL] <- real dll
Add the [C++ Runtime Component DLL] as a reference to [C# WP8.1 SL]
And the [C++ Native WP SL DLL] as a reference to [C++ Runtime Component DLL]
最佳答案
无法在托管 Windows Phone 项目中引用非托管程序集。在解决方案中创建 Windows 运行时组件,作为 dll 的包装器。您可以将其他非托管 dll 链接到运行时组件。
请阅读以下链接了解更多详情:
Creating Windows Runtime Components
How to import C++ dll in Windows Phone Project
Consuming a C++ library project from a Windows Phone Store app
Windows Runtime Component Sample-WP8.0
关于c# - 如何从 [C# WP8.1 WRT/SL] 项目调用 [非托管 C++ DLL func],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29761538/