项目 ——属性——输出类型——类库这样你写的 就是 DLL定义函数 个别人调用,,,就是 PUBLIC 在需要引用的项目——引用——添加引用——浏览——找到你的DLL然后在需要写代码的地方using xxx(命名空间) Class1 A = new Class1() A.Method();//调用函数
第一步:做dll 新建项目,点击解决方案,添加新项目-类库using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ClassLibrary1 { public class Class1 //注意类和方法都要用public,他人才能调用 { public string Example() { return "Hello World!"; } } }ClassLibrary1项目上右键-生成, 在ClassLibrary1项目的debug文件下有一个ClassLibrary1.dll第2步:调用: 将ClassLibrary1.dll复制到你要调用的项目的debug文件下, 再在项目引用-添加引用-浏览-找到ClassLibrary1.dll-确定 我以控制台应用程序为例:using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace Test { class Program { static void Main(string[] args) { //调用dll ClassLibrary1.Class1 ex = new ClassLibrary1.Class1(); string s = ex.Example(); //调用dll的方法 Console.WriteLine(s); Console.ReadKey(); //输出:Hello World! } } }
第一步:做dll 新建项目,点击解决方案,添加新项目-类库 C# codeusing System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ClassLibrary1 { public class Class1 //注意类和方法都要用public,他人才能调用 { public string Example() { return "Hello World!"; } } } ClassLibrary1项目上右键-生成, 在ClassLibrary1项目的debug文件下有一个ClassLibrary1.dll第2步:调用: 将ClassLibrary1.dll复制到你要调用的项目的debug文件下, 再在项目引用-添加引用-浏览-找到ClassLibrary1.dll-确定 我以控制台应用程序为例: C# codeusing System; using System.Collections.Generic; using System.Linq; using System.Text;namespace Test { class Program { static void Main(string[] args) { //调用dll ClassLibrary1.Class1 ex = new ClassLibrary1.Class1(); string s = ex.Example(); //调用dll的方法 Console.WriteLine(s); Console.ReadKey(); //输出:Hello World! } } }
在需要引用的项目——引用——添加引用——浏览——找到你的DLL然后在需要写代码的地方using xxx(命名空间)
Class1 A = new Class1()
A.Method();//调用函数
.net的?
.NET的建一个类库项目就好了.
做个类比,以儿童牛奶为例:如果你要在美国销售儿童牛奶,那么你必须符合美国关于此食品的标准。你可以在国内用皮革做牛奶,然后再掺点三聚氰胺,但是你要拿到美国市场,就不行了,人家不认,在程序中的表现就是:你皮革奶编译不过去。(此类比环境下)从某种意义上讲:我们在谈儿童牛奶时,一个硬性的标准是“它必须符合美国食品安全标准”,其次才谈是哪个国家的,有什么特点(比如A牛奶加冰后更好喝,B牛奶冷冻后更好喝)
DLL也是如此,除了人为规定以外,它们都一样(非功能)。
2.基于COM的,《Delphi程序调用C#.Net编译的DLL并打开窗体(详解)|C/S框架网|》http://www.csframework.com/archive/2/arc-2-20110408-1307.htm
用Reflector反编译一个DLL就会了。
新建项目,点击解决方案,添加新项目-类库using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ClassLibrary1
{
public class Class1 //注意类和方法都要用public,他人才能调用
{
public string Example()
{
return "Hello World!";
}
}
}ClassLibrary1项目上右键-生成,
在ClassLibrary1项目的debug文件下有一个ClassLibrary1.dll第2步:调用:
将ClassLibrary1.dll复制到你要调用的项目的debug文件下,
再在项目引用-添加引用-浏览-找到ClassLibrary1.dll-确定
我以控制台应用程序为例:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Test
{
class Program
{
static void Main(string[] args)
{
//调用dll
ClassLibrary1.Class1 ex = new ClassLibrary1.Class1();
string s = ex.Example(); //调用dll的方法
Console.WriteLine(s);
Console.ReadKey();
//输出:Hello World!
} }
}
新建项目,点击解决方案,添加新项目-类库
C# codeusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ClassLibrary1
{
public class Class1 //注意类和方法都要用public,他人才能调用
{
public string Example()
{
return "Hello World!";
}
}
}
ClassLibrary1项目上右键-生成,
在ClassLibrary1项目的debug文件下有一个ClassLibrary1.dll第2步:调用:
将ClassLibrary1.dll复制到你要调用的项目的debug文件下,
再在项目引用-添加引用-浏览-找到ClassLibrary1.dll-确定
我以控制台应用程序为例:
C# codeusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Test
{
class Program
{
static void Main(string[] args)
{
//调用dll
ClassLibrary1.Class1 ex = new ClassLibrary1.Class1();
string s = ex.Example(); //调用dll的方法
Console.WriteLine(s);
Console.ReadKey();
//输出:Hello World!
} }
}