일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Series
- LSTM
- Splunk
- E-P1
- RNN
- pip
- ipad
- keras
- Button
- javascript
- pandas
- index
- 알고리즘
- mariadb
- Python
- pycharm
- SPL
- SciPy
- install
- 삼성소프트웨어멤버십
- Numpy
- CNN
- dataframe
- Lotto
- DFS
- mean
- GitHub
- synology
- imread
- GT-S80
- Today
- Total
잠토의 잠망경
C#에서 Dll 동적 로딩하기 본문
C#에서 Dll 동적 로딩하기
밑에서 참고 하여 발전 개선 진행함
http://whiteberry.egloos.com/viewer/1953059
나는 이중에서 delegate 방식이 가장 좋았던 것 같다.
Dll 부분 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace TestDll { public class Class1 {
public void swap(ref int num1, ref int num2) { int temp = num1; num1 = num2; num2 = temp; } } }
|
Dll 이용하는 Code – 1번 delegate 이용 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
using System.Reflection;
namespace TestAppUsingDll { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
delegate void TheMethodDelegate(ref int a, ref int b);
private void button1_Click(object sender, EventArgs e) { //http://whiteberry.egloos.com/viewer/1953059
Assembly u = Assembly.LoadFile(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\TestDll\TestDll\bin\Debug\TestDll.dll");
Module[] modules = u.GetModules();
Type t = modules[0].GetType("TestDll.Class1");
MethodInfo minfo = t.GetMethod("swap");
//http://msdn.microsoft.com/ko-kr/library/53cz7sc6(v=vs.110).aspx
TheMethodDelegate testMethod = (TheMethodDelegate)Delegate.CreateDelegate(typeof(TheMethodDelegate), minfo);
int a = 10; int b = 11;
testMethod(ref a, ref b);
} } }
|
Dll 이용하는 Code – 2번 Invoke 이용 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
using System.Reflection;
namespace TestAppUsingDll { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
delegate void TheMethodDelegate(ref int a, ref int b);
private void button1_Click(object sender, EventArgs e) { Assembly u = Assembly.LoadFile(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\TestDll\TestDll\bin\Debug\TestDll.dll");
Module[] modules = u.GetModules();
Type t = modules[0].GetType("TestDll.Class1");
MethodInfo minfo = t.GetMethod("swap");
object[] parameter = { 10, 11 };
minfo.Invoke(minfo, parameter);
} } }
|
Dll 이용하는 Code – 3번 Invoke 이용 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
using System.Reflection;
namespace TestAppUsingDll { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
delegate void TheMethodDelegate(ref int a, ref int b);
private void button1_Click(object sender, EventArgs e) { Assembly u = Assembly.LoadFile(@"C:\Users\Administrator\Documents\Visual Studio 2013\Projects\TestDll\TestDll\bin\Debug\TestDll.dll");
object instanceObject = u.CreateInstance("TestDll.Class1");
object[] parameter = {10, 11};
instanceObject.GetType().GetMethod("swap").Invoke(instanceObject,parameter);
} } } |