如何从[C#WP8.1 WRT / SL]项目叫[非托管C ++ DLL FUNC] [英] How to Call [Unmanaged C++ DLL func] from [C# WP8.1 WRT/SL] project

查看:186
本文介绍了如何从[C#WP8.1 WRT / SL]项目叫[非托管C ++ DLL FUNC]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不是如何调用C ++从C#功能的副本



我知道如何做到这一点的普通PC的应用程序,我试图和它的作品:



这就是所谓的p / Invoke

  1。 
创建一个C ++ dll项目,
,但你不能添加C ++的dll项目作为对C#项目的引用。
复制从C ++的DLL,并粘贴在C#中使用DLL到C#的EXE文件夹

2.
函数[DllImport ...]
在C ++中使用extern C__declspec(dllexport)的...

不过,我做这在WindowsPhone的时候,失败了。



有2型非托管C ++的Windows Phone的原生dll项目,我都试过

  DLL(Windows手机)LT;  -  WRT DLL 8.1 
DLL(的Windows Phone的Silverlight 8.1)

我不知道在哪里放置的DLL文件。
,因为最终的exe是一个包。
我不能把该dll与封装相同的文件夹中。
中的DLL应在包装,作为包装的一部分。



于是,我就在DLL添加为C#WP8一个resorce文件。 1 SL项目。



不过,函数调用失败。



所以,我想知道的是,如何放置DLL,如何连接与WP8.1 SL项目中的dll?



有没有任何一个尝试过吗?



感谢你们的回答。



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



所以,正确的做法是
对于[C#WP8.1 SL]项目,
我需要

 创建[C ++运行时组件DLL<  - 桥梁
创建[C ++本地WP SL DLL< - 真正的dll

添加[C ++运行时组件DLL]作为作为一个参考参考[C#WP8.1 SL]
和[C ++本地WP SL DLL] [C ++运行时组件DLL]


解决方案

非托管程序集不能被管理的Windows Phone项目中引用。创建Windows解决方案,它作为该dll的包装内运行时组件。你可以链接其他非托管的DLL的运行时组件



请阅读有关详细信息,以下链接:



创建Windows运行时组件



如何导入C ++ DLL中的Windows Phone项目



消费从Windows Phone应用商店应用一个C ++库项目



Windows运行时组件采样WP8。 0


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]

解决方案

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

这篇关于如何从[C#WP8.1 WRT / SL]项目叫[非托管C ++ DLL FUNC]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆