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

℡╲_俬逩灬. 提交于 2019-12-07 08:27:08

问题


This is not a duplicate of "how to call C++ function from C#"

I know how to do it for regular PC app and I tried and it works:

This is called 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) ...

But when I do this on WindowsPhone, failed.

There are 2 type of unmanaged c++ native dll project for windows phone, I tried both

DLL (Windows Phone) <- WRT DLL 8.1
DLL (Windows Phone Silverlight 8.1)

I don't know where to place the dll file. Because the finally exe is a package. I can't place the dll in the same folder with the package. The dll should be in the package, as a part of the package.

So I tried to add the dll as a resorce file in the C# WP8.1 SL project.

But the function call failed.

So what I want to know is, how to place the dll, how to hook up the dll with the WP8.1 SL project?

Is there any one try that before?

Thank you guys for the answer.

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

So the correct way is For a [C# WP8.1 SL] project, I need to

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]

回答1:


Unmanaged assembly cannot be referenced in managed windows phone project. Create windows run time component inside your solution which acts as a wrapper for the dll. You can link other unmanaged dll to the run time component.

Please read the following links for more details:

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



来源:https://stackoverflow.com/questions/29761538/how-to-call-unmanaged-c-dll-func-from-c-wp8-1-wrt-sl-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!