<div><br></div> <div> <div>1. Win32 DLL 프로젝트로 작성된 클래스</div> <div><br></div> <div> <div style="color:#333333;font-family:Verdana, Helvetica, Arial, sans-serif;font-size:medium;line-height:normal;overflow:auto;width:auto;border-style:solid;border-color:#808080;border-width:.1em .1em .1em .8em;padding:.2em .6em;background:#202020;"><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#999999;font-style:italic;">// MyClass.h</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">class</span> <span style="color:#447fcf;">__declspec</span><span style="color:#d0d0d0;">(dllexport)</span> <span style="color:#d0d0d0;">CMyClass</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">public:</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">Func1(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">a,</span> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">b);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">void</span> <span style="color:#447fcf;">Func2</span><span style="color:#d0d0d0;">(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">*a);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">};</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#999999;font-style:italic;">// MyClass.cpp</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">CMyClass::Func1(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">a,</span> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">b)</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">return</span> <span style="color:#d0d0d0;">(a</span> <span style="color:#d0d0d0;">+</span> <span style="color:#d0d0d0;">b);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">CMyClass::Func2(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">*a)</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">*a++;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">}</span></pre></div></div> <div><br></div> <div>해당 DLL의 클래스는 C++에서 바로 사용이 가능하지만</div> <div>C#에서는 사용이 힘들다 (가능할것같지만 너무 어려워서 포기)</div> <div><br></div> <div><br></div> <div>2. Class Library로 작성된 클래스</div> <div><br></div> <div> <div style="color:#333333;font-family:Verdana, Helvetica, Arial, sans-serif;font-size:medium;line-height:normal;overflow:auto;width:auto;border-style:solid;border-color:#808080;border-width:.1em .1em .1em .8em;padding:.2em .6em;background:#202020;"><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#999999;font-style:italic;">// MyClassWrapper.h</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#cd2828;font-weight:bold;">#include "MyClass.h"</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">namespace</span> <span style="color:#d0d0d0;">Wrapper</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">public</span> <span style="color:#d0d0d0;">ref</span> <span style="color:#6ab825;font-weight:bold;">class</span> <span style="color:#447fcf;text-decoration:underline;">CMyClassWrapper</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">private:</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">CMyClass</span> <span style="color:#d0d0d0;">*m_MyClass;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">public:</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span class="Apple-tab-span" style="white-space:pre;"> </span> <span style="color:#d0d0d0;">CMyClassWrapper();</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">virtual</span> <span style="color:#d0d0d0;">~CMyClassWrapper();</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">public:</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#447fcf;">Func1</span><span style="color:#d0d0d0;">(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">a,</span> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">b);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">void</span> <span style="color:#447fcf;">Func2</span><span style="color:#d0d0d0;">(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">%a);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">};</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#999999;font-style:italic;">// MyClassWrapper.cpp</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">namespace</span> <span style="color:#d0d0d0;">Wrapper</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">CMyClassWrapper::CMyClassWrapper()</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">m_MyClass</span> <span style="color:#d0d0d0;">=</span> <span style="color:#6ab825;font-weight:bold;">new</span> <span style="color:#d0d0d0;">CMyClass;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">CMyClassWrapper::~CMyClassWrapper()</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">if</span><span style="color:#d0d0d0;">(m_MyClass</span> <span style="color:#d0d0d0;">!=</span> <span style="color:#3677a9;">0</span><span style="color:#d0d0d0;">)</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">delete</span> <span style="color:#d0d0d0;">m_MyClass;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">CMyClassWrapper::Func1(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">a,</span> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">b)</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">return</span> <span style="color:#d0d0d0;">m_MyClass->Func1(a,</span> <span style="color:#d0d0d0;">b);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">void</span> <span style="color:#d0d0d0;">CMyClassWrapper::Func2(</span><span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">%a)</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">temp;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">m_MyClass->Func2(&temp);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">a</span> <span style="color:#d0d0d0;">=</span> <span style="color:#d0d0d0;">temp;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">}</span></pre></div></div> <div><br></div> <div>원래 클래스의 함수를 호출시켜주기만 하는 단순한 클래스인데</div> <div>다만 포인터를 매개변수로 받는 함수들은 좀 까다로움 ㅜㅜ</div> <div>구글검색해보면 문자열이나 콜백함수포인터들을 받아서 처리하는방법도 볼수있지만 어렵네요 ㅋㅋ</div> <div>CLI문법은 참 특이하네요.. %를 나머지연산할때빼고 저렇게 쓰는건 첨봄;;</div> <div><br></div> <div><br></div> <div>3. C#에서 사용</div> <div>Wrapper에서 빌드해 나온 DLL을 참조추가만 하면 <span style="font-size:9pt;line-height:1.5;">바로 사용이 가능.</span></div> <div>[DllImport(...)] 따위 안써도 되는 편의성! (단지 이거하나때문에...)</div> <div><br></div> <div> <div style="color:#333333;font-family:Verdana, Helvetica, Arial, sans-serif;font-size:medium;line-height:normal;overflow:auto;width:auto;border-style:solid;border-color:#808080;border-width:.1em .1em .1em .8em;padding:.2em .6em;background:#202020;"><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">using</span> <span style="color:#d0d0d0;">MyClassWrapper;</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#6ab825;font-weight:bold;">namespace</span> <span style="color:#d0d0d0;">TestProject</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">public</span> <span style="color:#6ab825;font-weight:bold;">class</span> <span style="color:#447fcf;text-decoration:underline;">Test</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">CMyClassWrapper</span> <span style="color:#d0d0d0;">obj</span> <span style="color:#d0d0d0;">=</span> <span style="color:#6ab825;font-weight:bold;">new</span> <span style="color:#d0d0d0;">CMyClassWrapper();</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">private</span> <span style="color:#6ab825;font-weight:bold;">void</span> <span style="color:#447fcf;">foo</span><span style="color:#d0d0d0;">()</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">{</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#6ab825;font-weight:bold;">int</span> <span style="color:#d0d0d0;">value</span> <span style="color:#d0d0d0;">=</span> <span style="color:#d0d0d0;">obj.Func1(</span><span style="color:#3677a9;">10</span><span style="color:#d0d0d0;">,</span> <span style="color:#3677a9;">5</span><span style="color:#d0d0d0;">);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#999999;font-style:italic;">// value == 15</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">obj.Func2(ref</span> <span style="color:#d0d0d0;">value);</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#999999;font-style:italic;">// value == 16</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"> <span style="color:#d0d0d0;">}</span></pre><pre style="margin-top:0px;margin-bottom:0px;line-height:16.25px;"><span style="color:#d0d0d0;">}</span></pre></div></div> <div><br></div> <div><br></div> <div><br></div> <div>저번에 관련 질문 올렸을때 답변달아주신 분들 감사합니다.</div> <div><br></div> <div>이제 가능성 여부 테스트가 끝났으니 개발을 시작 ㅋㅋㅋ</div></div> <div><br></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.