[英]DLLImport path C#
I would like to import my DLL inside my C# class but instead of this: 我想将我的DLL导入我的C#类中,而不是这样:
[DllImport(@"C:\Users\user\Documents\Visual Studio 2010\Projects\KeyDll\Debug\DLLWrap.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?DivSet@MyCall@MyFunc@@SAPADPAD@Z")]
I would like to locate the path within the project like so: 我想像这样在项目中找到路径:
[DllImport(@"...\Debug\DLLWrap.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?DivSet@MyCall@MyFunc@@SAPADPAD@Z")]
So that it looks in the local folder the solution is in. 使它看起来在解决方案所在的本地文件夹中。
Any suggestions?? 有什么建议么??
Regards 问候
You can simply use relative urls like: 您可以简单地使用相对网址,例如:
[DllImport("DLLWrap.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?DivSet@MyCall@MyFunc@@SAPADPAD@Z")]
Your application will search working directory (your local folder) for the file by default. 默认情况下,您的应用程序将在工作目录(您的本地文件夹)中搜索该文件。
In Winforms, you can always ensure it uses your Working Directory by 在Winforms中,您始终可以通过以下方式确保它使用您的工作目录:
[DllImport(Application.StartupPath + "\\DLLWrap.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?DivSet@MyCall@MyFunc@@SAPADPAD@Z")]
Edit the properties of the DLL to be 'Content' and 'Copy Always' 将DLL的属性编辑为“内容”和“始终复制”
Reference the DLL in your P/Invoke statements as @"DLLWrap.dll" 在P / Invoke语句中将DLL引用为@“ DLLWrap.dll”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.