Interface Marshaling
marshaling์ ๊ฐ๋
COM ์๋ฒ๋ ์์น ํฌ๋ช ์ฑ์ ์ง์ํ๋ค. ์ฆ COM ํด๋ผ์ด์ธํธ์ ๋์ผ ํ๋ก์ธ์ค ๋ด์ ์๋(in-process server), ๋์ผ ๋จธ์ ํ ํ๋ก์ธ์ค๋ก ์กด์ฌํ๋์ง(out-of-process server), remote ๋จธ์ ์ ์๊ฑด(remote server) ์๊ดํ์ง ์๋๋ค. ์ด๋ ๊ฐ๊ธฐ ๋ค๋ฅธ ๋งค์ปค๋์ฆ์ ํตํ ๋ฐ์ดํฐ ํต์ ์ ๋์ผํ ์ธํฐํ์ด์ค๋ก ์ด๋ฃฐ ์ ์๋๋ก ํด์ผํ๋ค๋ ์ด์ผ๊ธฐ. marshaling์ ์์ ์ธ ๊ฒฝ์ฐ ์ค ํ๋ก์ธ์ค ๊ฒฝ๊ณ๋ฅผ ๋์ด ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๋ out-of-process server, remote server๋ฅผ ์ํ ๋ฐ์ดํฐ ์ ์ก ๋งค์ปค๋์ฆ์ด๋ค.
marshaling์ ์ข ๋ฅ
- standard marshaling, Automation marshaling, custom marshaling์ ์ธ ๊ฐ์ง๊ฐ ์กด์ฌํ๋ฉฐ, automation marshaling์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๊ฐ ๊ต์ฐจ์ง์์ ์ํ ๊ฒ์ด๋ค.
- standard marshaling: MIDL ์ปดํ์ผ๋ฌ๋ IDL(Interface Definition Language) ์ฝ๋๋ฅผ ์ปดํ์ผํ์ฌ proxy์ stub๋ฅผ ๊ตฌํํ C ์ฝ๋๋ฅผ ์์ฑํ๋ค. proxy๋ COM client์, stub์ COM server์ ๊ฐ๊ฐ ๋ถ๋ ์์๊ฐ ๋ฐ์ดํฐ ์ ์ก์ ์ํ ๋ฉ์ปค๋์ฆ์ด๋ค.
- Automation marshaling: automation์ C++ ์ด์ธ์ ์ธ์ด(์ฃผ๋ก Visual Basic ๋๋ VBScript)๋ก ์์ฑ๋ ํด๋ผ์ด์ธํธ๊ฐ COM ์ปดํฌ๋ํธ์ ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก ํ๋ ๊ธฐ์ ์ด๋ค.ย
IDispatchย interface๋ฅผ ๊ตฌํํจ์ผ๋ก Automation marshaling์ ์ด๋ฃฌ๋ค. ์ฑ๋ฅ์ด standard marshaling์ ๋นํด ๋จ์ด์ง๋ ๋จ์ ์ด ์กด์ฌํ๋ค. - Custom marshaling: Standard marshaling์ด ์ ํฉํ์ง ์์ ๊ฒฝ์ฐ์ ์ฌ์ฉํ๋ค. IMarshal interface ๊ตฌํ์ ํตํด ์ด๋ฃจ๋ฉฐ, ๋ฉ๋ชจ๋ฆฌ ๊ณต์ , (์ฐธ์กฐ๊ฐ ์๋) ๊ฐ์ ์ํ marshaling, (๋น๋๊ธฐ ํธ์ถ ๋ฑ์ ๊ธฐ๋ฒ์ ํตํด ์ฑ๋ฅ ํฅ์์ ์ํ) Smart proxy, COM threading model ๋ฌด์ ๋ฑ์ ์ํด custom marshaling์ ์ฌ์ฉํ๋ค.
IDispatch inteface
- Automation์ ์ด๋ฃจ๊ธฐ ์ํ ํต์ฌ์ด๋ค. 4๊ฐ์ ๋ฉ์๋๋ฅผ ๊ฐ์ง๋ฉฐย Invoke()๋ฅผ ํตํด COM Server๊ฐ ๋ ธ์ถํ๋ ๋ฉ์๋์ ๊ฐ์ ํธ์ถ์ ๊ฐ๋ฅํ๊ฒ ํ๋ค.ย Invoke()์ ๋งค๊ฐ๋ณ์ ๋ฐ์ดํฐ ํ์ ์ผ๋ก๋ Automation ํธํ ๋ฐ์ดํฐ ํ์ , ์ฆย VARIANTย ํ์ . Visual Basic์ ์ํ Universal ํ์ ์ผ๋ก์, native ๋งค๊ฐ๋ณ์๋ ๋ณธ ํ์ ์ผ๋ก ๋ณํ๋์ด ์์๊ฐ์์ ์๋ค๋ฆฌ๊ฐ๋ค๋ฆฌํ๋ค.

GetTypeInfoCount()๋ COM ๊ฐ์ฒด๊ฐ ๋ ธ์ถํ๋TypeInfo์ธํฐํ์ด์ค์ ๊ฐ์๋ฅผ ๋ฐํํ๊ณ ,GetTypeInfo()๋ Type Library์์ Type ์ ๋ณด๋ฅผ ๋ฐํํ๋ฉฐ,GetIDsOfNames()๋ COM ๊ฐ์ฒด๊ฐ ๋ ธ์ถํ๋ ๋ฉ์๋์ string ํ์์ ์ด๋ฆ์,Invoke()๋ ๋งคํ๋ ๋ฉ์๋ ๋ฒํธ(DISPID)๋ฅผ ํตํด ํด๋น ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๋ฐ ์ฌ์ฉํ๋ค.
Type Library
- ์ฑ๋ฅ๊ณผ tradeoffํ automation์ ํธํ์ฑ์ ๊ทธ๋๋ก ๋ ์ฒด, ์ฑ๋ฅ์ ๋ ๋์ด๊ธฐ ์ํด ๋์จ ๊ตฌ์กฐ. ์ง์ ์ ์ผ๋ก COM ์ปดํฌ๋ํธ๊ฐ ๋ ธ์ถํ๋ inteface์(vtable์) ์ ๊ทผ ๊ฐ๋ฅํ๊ฒ ํ๋ ๋ฉ์ปค๋์ฆ์ด๋ค. ์ด๋ฅผ ์ํด์๋ interface method ๋งค๊ฐ๋ณ์์ ํ์ ๊ณผ ๊ฐ์๋ฅผ ์ฌ์ ์ ์๊ณ ์์ด์ผ ํ๋ฉฐ, ๋ฐ๋ก ์ด๋ค ์ฌํญ์ Type Library๊ฐ ์ ๊ณตํ๋ค. interface์ ๋ํ ์ค๋ช (description)์ ๋ฐ์ด๋๋ฆฌ ํํ-๋ก ๋ํ๋ด๋ Type Library๋ C++ ํค๋ ํ์ผ์ ์ธ์ด ๋ ๋ฆฝ์ ์ธ ์ปดํ์ผ๋ ๋ฒ์ ์ผ๋ก ๋ด๋ ๋ฌด๋ฐฉํ๋ค.
- IDL๋ก ๊ธฐ์ ๋ Type Library๋ฅผ MIDL ์ปดํ์ผ๋ฌ๊ฐ tlb ํ์ฅ์์ ํ์ผ๋ก ์์ฑํ๋ค. ์์ฑ๋ tlb ํ์ผ์ ์ข ์ข COM ์ปดํฌ๋ํธ๊ฐ ๋ด๊ธด dll ๋๋ exe ํ์ผ์ ์ฐ๊ฒฐ(link)๋๋ค.
- COM ํด๋ผ์ด์ธํธ๋ COM run-time ๋ผ์ด๋ธ๋ฌ๋ฅผ ํตํด registry์์ Type Library๋ฅผ ์ฐพ์ ์ ๊ทผํ๋ค. ๋ฐ๋ผ์ registry์๋ ํด๋น Type Library๊ฐ ๋ฑ๋ก๋์ด ์์ด์ผ ํ๋ค.

HKEY_CLASSES_ROOT\TypeLibํ์์ ์์นํ๋ Type Library ์์น์ ๋ณด๋ LIBID๋ก ๊ฐ Type Library๋ฅผ ์๋ณํ๊ณ ํด๋น ์ํธ๋ฆฌ ํ์์ win32 ์ํธ๋ฆฌ์ ํด๋น Type Library๊ฐ ์๋ ํ์ผ์ path๊ฐ ๋ด๊ธด๋ค.
Dual Interface
C++ ๋ฐ ๋น C++ ๊ธฐ๋ฐ COM ํด๋ผ์ด์ธํธ ๋ชจ๋๋ฅผ ๋ง์กฑ์ํค๋ dispatch ์ธํฐํ์ด์ค ๊ตฌํ ๋ฐฉ๋ฒ์ vtable์ IDispatch interface์ Invoke() ๋ฉ์๋ ๋ค๋ก ํด๋น COM ์ปดํฌ๋ํธ๊ฐ ๋
ธ์ถํ๋ ๋ฉ์๋๋ฅผ ์์น์ํค๋ ๊ฒ์ด๋ค. ์ด๋ฅผ ํตํด C++ ํด๋ผ์ด์ธํธ๋ ํด๋น ๋ฉ์๋๋ฅผ ์ง์ ํธ์ถํ๊ณ ๋น C++ ํด๋ผ์ด์ธํธ๋ Invoke()๋ฅผ ํตํด ํด๋น ๋ฉ์๋๋ฅผ ํธ์ถํ ์ ์๋ค. ์ด๋ฌํ ์ธํฐํ์ด์ค๋ฅผ ๊ฐ๋ฆฌ์ผ dual interface๋ผ ํ๋ค.
References
- Desktop Applications with Microsoft Visual C++ 6.0 MCSD Training Kit
- MSDN

Comments