如何从 [C# WP8.1 WRT/SL] 项目中调用 [Unmanaged C++ DLL func]

How to Call [Unmanaged C++ DLL func] from [C# WP8.1 WRT/SL] project

这不是 "how to call C++ function from 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 上执行此操作时,失败了。

windows phone 有 2 种类型的非托管 C++ 本机 dll 项目,我都试过了

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项目挂钩?

有人试过吗?

谢谢大家的回答。

//---------------------------------------- ------------------

所以正确的做法是 对于 [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 的包装器。您可以 link 其他非托管 dll 到 运行 时间组件。

请阅读以下link了解更多详情:

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