这不是“如何从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++本地DLL项目适用于Windows Phone,我尝试了两种。
DLL (Windows Phone) <- WRT DLL 8.1
DLL (Windows Phone Silverlight 8.1)
我不知道将dll文件放在哪里才合适,因为最终的exe是一个包。我不能将dll放在与包相同的文件夹中。dll应该作为包的一部分放在包内。
所以我尝试将dll添加为C# WP8.1 SL项目中的资源文件。
但是函数调用失败了。
所以我想知道的是,如何放置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]