相对路径来DLL在平台调用声明 [英] Relative Path to DLL in Platform Invoke Statement

查看:258
本文介绍了相对路径来DLL在平台调用声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用VS 2008开发使用以P / Invoke的一个.dll的应用程序。我可以成功地使用DLL时,我使用绝对路径。例如,这是否工作:

I am using VS 2008 to develop an application that uses a .dll with P/Invoke. I can successfully use the dll when I use an absolute path. For example, this DOES work:

函数[DllImport(C:\\myDLL.dll)]
内部静态外部布尔的isReady();

[DllImport("C:\\myDLL.dll")] internal static extern bool isReady();

这不工作:

函数[DllImport(MYDLL.DLL)]
内部静态外部布尔的isReady();

[DllImport("myDLL.dll")] internal static extern bool isReady();

我曾尝试添加一个参考文件夹,并添加DLL项目文件夹,但没有工作。我需要部署在其他计算机上这个应用程序,并需要确保此.dll是包括在内。感谢您的帮助!

I have tried adding a reference folder and adding the dll to the project folder but neither work. I need to deploy this application on other computers and need to make sure this .dll is included. Thanks for the help!


我忘了提,当我尝试这样做,我得到这个错误:

I forgot to mention when I try to do that I get this error:

微软的Visual Studio
的引用为C:\Users\dlugokja\Documents\Visual工作室2008\Projects\ DinamapN.sln(1)\DinamapN\DinamapN\DinaWin.dll不能添加。请确保该文件是可访问的,而且它是一个有效的程序集或COM组件。
OK

Microsoft Visual Studio A reference to 'C:\Users\dlugokja\Documents\Visual Studio 2008\Projects\DinamapN.sln(1)\DinamapN\DinamapN\DinaWin.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component. OK

推荐答案

我们在工作中使用该解决方案如下:

The solution we use at work is the following:


  1. 将DLL添加到您的项目

  2. 编辑DLL的性质是内容和一直拷贝

  3. 基准的DLL在你的P / Invoke陈述@MYDLL.DLL

这篇关于相对路径来DLL在平台调用声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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