不能添加DLL引用?(后续) [英] Can't add DLL reference?(Follow up)
问题描述
跟进此
我也读过在其他一些问题上,但是我不明白会是什么会导致这种情况发生。权限?如何应用工作?什么是LAME?
我被定向到这个教程,并将它用于一个C#程序,以执行按钮点击。
但是我在这行上收到错误
[DllImport(ODBCCP32.dll)]
说明
无法找到类型或命名空间名称DllImport(您是否缺少使用目录或程序集引用?)
我已经尝试将该文件作为参考,但是我打了有这个错误
请确保文件是可访问的,它是一个有效的程序集或COM组件
我缺少需要导入的东西吗?
这是我代码的一部分。 using System;
使用System.Runtime.InteropServices;
命名空间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
}
}
解决方案似乎我只是有一些困惑。
我可以将.dll添加为资源而不是引用。
我还分配了一个新的字符串资源作为dll的名称,以备稍后使用。
所有这一切都是有效的。
命名空间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();
}
//处理创建的方法(将在按钮上单击)
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){
//调用添加用户方法
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屋!