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

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

问题描述

这不是如何从C#调用C ++函数的重复



我知道如何做常规电脑应用程序,我试过,它的工作原理:



这称为P / Invoke

  1。 
创建一个C ++ dll项目,
,但是你不能将C ++ dll项目添加为C#项目的引用。
复制C ++中的dll,并将dll粘贴到C#exe文件夹中

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

但是当我在WindowsPhone上执行此操作失败。 / p>

有两种类型的非托管c ++本地dll项目windows phone,我试过

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


b $ b

我不知道在哪里放置dll文件。
因为最后的exe是一个包。
我无法将dll放在包的同一文件夹中。
dll应该在包中,作为包的一部分。



所以我试图添加dll作为resorce文件在C#WP8。 1 SL项目。



但是函数调用失败。



所以我想知道的是,放置dll,如何使用WP8.1 SL项目挂接dll?



之前有没有尝试过?



谢谢你们的回答。



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



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

 创建一个[C ++ Runtime Component DLL]<  -  as bridge 
创建一个[C ++ Native WP SL DLL]< - real dll

添加[C ++ Runtime组件DLL]作为对[C#WP8.1 SL]的引用
和[C ++ Native WP SL DLL]作为对[C ++运行时组件DLL]的引用


解决方案

无法在托管Windows Phone项目中引用非托管程序集。在您的解决方案中创建Windows运行时组件,作为dll的包装器。您可以将其他非托管dll与运行时组件相关联。



请阅读以下链接了解详情:



创建Windows运行时组件



如何导入Windows Phone专案中的C ++ dll



从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函数]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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