右击"引用",点"添加",再浏览选择你的DLL;在程序中using即可;
解决方案 »
- 求解:StreamWriter将流写入文件后导致的文件体积变大问题!!!
- log4net 用于sqlserver2008 express 不成功
- VS2008 CrystalReport的教程
- 如何触发某个键,使LABEL控件中的数字累加一次
- ActiveReport打印问题求教!用A3的纸横向打印,无论如何都要多打一张白纸出来(预览时有那条红线)?
- 如何判断Process.StandardOutput.ReadLine()已经为空?
- 有关C#的例子
- c#的开方函数是什么啊 急啊 再线等
- Web页面中的小问题!请大家进来看看!
- 怎样打印输出,以及打印预揽
- 关于动态加载dll的问题 ?
- 动态引用dll问题?
1) IBizLogic is an interface I created.
2) AssemblyPath is the asimbly I'm going to load, it implements IBizLogic interface.
Private _BizLogic As IBizLogic
Private _ObjType As Type = NothingProtected Function LoadBizLogicAssembly(ByVal AssemblyPath As String) As Boolean
Dim ass As System.Reflection.Assembly = Nothing Try
ass = System.Reflection.Assembly.LoadFrom(AssemblyPath)
Dim AllTypes() As Type = ass.GetTypes()
If Not ass Is Nothing Then
_ObjType = ass.GetType(AllTypes(0).FullName)
If Not _ObjType Is Nothing Then
_BizLogic = CType(Activator.CreateInstance(_ObjType), IBizLogic)
Return True
End If
End If
Return False
Catch ex As Exception
myEventLog.WriteLog(ex)
Return False
End Try
End Function
这在C#中非常简单.
using System;namespace MyLib
{
public class MyMathClass
{
public static bool IsEven(int n)
{
return((n%2)==0);
}
}
}
using System;
using MyLib;class UseMyLib
{
public static void Main()
{
int n = 33;
bool bIsEven = MyMathClass.IsEven(n);
if(bIsEven) Console.WriteLine("{0} is an even number", n);
else Console.WriteLine("{0} is an odd number", n);
}
}
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dllusing System;
using System.Reflection;
public class LoadInvoke
{
public static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(args[0]);
Type[] mytypes = a.GetTypes();
BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly); foreach(Type t in mytypes)
{
MethodInfo[] mi = t.GetMethods(flags);
Object obj = Activator.CreateInstance(t); foreach(MethodInfo m in mi)
{
m.Invoke(obj, null);
}
}
}
}
[C++]
// LoadInvoke loads MyAssembly.dll and invokes the MyMethod1 method.
// After compiling this class, run LoadInvoke.exe with MyAssembly.dll
// as the command line argument, as shown below:
// LoadInvoke Myassembly.dll#using <mscorlib.dll>using namespace System;
using namespace System::Reflection;int main() {
String* args[] = Environment::GetCommandLineArgs();
Assembly* a = Assembly::LoadFrom(args[0]);
Type* mytypes[] = a->GetTypes();
BindingFlags flags = static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Public |
BindingFlags::Static | BindingFlags::Instance | BindingFlags::DeclaredOnly); System::Collections::IEnumerator* myEnum = mytypes->GetEnumerator();
while (myEnum->MoveNext()) {
Type* t = __try_cast<Type*>(myEnum->Current); MethodInfo* mi[] = t->GetMethods(flags);
Object* obj = Activator::CreateInstance(t); System::Collections::IEnumerator* myEnum = mi->GetEnumerator();
while (myEnum->MoveNext()) {
MethodInfo* m = __try_cast<MethodInfo*>(myEnum->Current);
m->Invoke(obj, 0);
}
}
}
[Visual Basic]
' Use this class with the LoadInvoke program.
' Compile this class using vbc /t:library MyAssembly.vb
' to obtain MyAssembly.dll.
Imports System
Imports Microsoft.VisualBasicPublic Class MyAssembly
Public Sub MyMethod1()
Console.WriteLine("Invoking MyAssembly.MyMethod1")
End Sub 'MyMethod1
End Class 'MyAssembly
[C#]
// Use this class with the LoadInvoke program.
// Compile this class using csc /t:library MyAssembly.cs
// to obtain MyAssembly.dll.
using System;public class MyAssembly
{
public void MyMethod1()
{
Console.WriteLine("Invoking MyAssembly.MyMethod1");
}
}