如何在VC.Net中使用C#创建地Dll,,,急问

各位大虾,我是一个VC.Net的初学者,请问如何在VC.Net中使用C#创建地Dll,最好能给个这方面的例子,我的邮箱是[email protected],谢谢

---------------------------------------------------------------

给你一个例子:

using System;
using System.Data;
using System.Data.OleDb;
namespace MycMdb
{
public class Mdbc
{
private string ConnStr;
private int Index;
public Mdbc(string PathName)
{
ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+PathName;
}
public OleDbDataReader GetDataReader(string SelectSQL)
{
OleDbConnection Conn;
OleDbCommand Cmd;
OleDbDataReader myDataReader;
Conn= new OleDbConnection(ConnStr);
Cmd = new OleDbCommand(SelectSQL, Conn);
Conn.Open();
myDataReader=Cmd.ExecuteReader();
return myDataReader;
}
public DataView GetDataView(string SelectSQL)
{
OleDbConnection Conn;
OleDbDataAdapter Cmd;
DataSet ds;
string TableName;
Conn= new OleDbConnection(ConnStr);
Cmd = new OleDbDataAdapter(SelectSQL, Conn);
Index+=1;
TableName ="Table"+Index;
ds=new DataSet();
Cmd.Fill(ds, TableName);
return(new DataView(ds.Tables[TableName]));
}
public void ExecuteSQL(string ActionQuery)
{
OleDbCommand Cmd;
OleDbConnection Conn= new OleDbConnection(ConnStr);
Cmd = new OleDbCommand(ActionQuery, Conn);
Conn.Open();
Cmd.ExecuteNonQuery();
}
}
}

输入代码后,就是编译了:
csc /t:library /r:System.Data.dll /r:System.Xml.dll Mdbc.cs
编译完成后将生成的.dll文件放到项目的bin目录下即可
---------------------------------------------------------------

Here is the method:

1. C# code like this, and build it to mylib.dll

using System;

namespace mylib
{

public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public string Name()
{
return "Here is my name";
}
}
}

2. In Managed C++, add the following statements

#using "/path/to/mylib.dll"

using namespace mylib;

int _tmain(void)
{
Class1 *cls = new Class1();
Console::WriteLine(cls->Name());
}

3. Put mylib.dll and C++ exe file in the same directory.

Published At
Categories with Web编程
Tagged with
comments powered by Disqus