无法添加DLL引用?(后续) [英] Can't add DLL reference?(Follow up)
问题描述
跟进到这
我也看过了在其它一些问题,但我不明白什么会导致这种情况发生。权限?如何围绕应用工作的?什么LAME?
我是针对的这的教程,并将它加工成C#程序按钮点击执行。
不过,我得到这个行误差
函数[DllImport(ODBCCP32.DLL)]
说明
类型或命名空间名称的DllImport找不到(是否缺少使用目录或程序集引用?)
我已经试过inporting该文件作为参考,但我然后打这个错误
请确认文件accessile,而且它是一个有效的集会或COM组件
我失去的东西,我需要进口?
这里是我的一段代码
使用系统。使用System.Runtime.InteropServices
;
命名空间DsnUtil {
公共部分Form1类:表格{
函数[DllImport(ODBCCP32.DLL)]
私人静态的extern BOOL SQLConfigDataSource(//等等等等)
公共Form1的(){
的button1_Click();
}
私人无效的button1_Click(对象发件人,EventArgs五){
// DoesWork
}
}
看起来,我刚做了一些事情混淆。
我能够.dll文件添加为资源而不是一个参考。
我也被分配一个新的字符串资源作为的情况下,该DLL我想以后使用它的名字。
这所有的一切是什么工作。
命名空间DSNUtility {
公共部分Form1类:表格{
函数[DllImport( ODBCCP32.DLL)]
私人静态的extern BOOL SQLConfigDataSource(IntPrt父母,INT请求串驱动器,字符串属性;
公开形式(){
的InitializeComponent();
}
//方法来处理创建(将被称为点击一个按钮)
公共BOOL AddUserDSN(){
返回SQLConfigDataSource((IntPrt)0, 1,SQL服务器,
DSN = Testing123\0Description = Testing123\0Network = blahblah\0Trusted_Connection = No\0Server = blahblahblah\0Database = XXXXXX\0);
}
私人无效Form1_Load的(对象发件人,EventArgs五){
}
私人无效的button1_Click(对象发件人,EventArgs五){
//调用添加用户方法
AddUserDSN();
}
}
Follow up to This I have also read up on some other questions but am not understanding what would cause this to happen. Permissions? How to apply a work around? Whats LAME?
I was directed to THIS tutorial and have worked it into a C# program to execute on Button Clicks.
However I get a error on this line
[DllImport("ODBCCP32.dll")]
stating
The type or namespace name "DllImport" could not be found (are you missing a using directory or an assembly reference?)
I have tried inporting that file as a reference but am then hit with this error
"Please make sure file is accessile, and that it is a valid assembly or COM component"
Am I missing something that I need imported? Here is a section of my code.
using System;
using System.Runtime.InteropServices;
namespace DsnUtil{
public partial class Form1 : Form{
[DllImport("ODBCCP32.dll")]
private static extern bool SQLConfigDataSource(//etc etc)
public Form1(){
button1_Click();
}
private void button1_Click(object sender, EventArgs e){
//DoesWork
}
}
It seemed that I just had some things confused. I was able to add the .dll as a Resource instead of a reference. I also assigned a new string resource as the name of the dll in case I would like to use it later.
All in all this is what worked.
namespace DSNUtility{
public partial class Form1 : Form{
[DllImport("odbccp32.dll")]
private static extern bool SQLConfigDataSource(IntPrt parent, int request, string driver, string attribute;
public form(){
InitializeComponent();
}
//Method to handle the creation(Will be called on a Button Click)
public bool AddUserDSN(){
return SQLConfigDataSource((IntPrt)0, 1, "SQL Server",
"DSN=Testing123\0Description=Testing123\0Network=blahblah\0Trusted_Connection=No\0Server=blahblahblah\0Database=XXXXXX\0");
}
private void Form1_Load(object sender, EventArgs e){
}
private void button1_Click(object sender, EventArgs e){
//Call the Add User Method
AddUserDSN();
}
}
这篇关于无法添加DLL引用?(后续)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!