No Slide Title

Similar documents
COM 컴포넌트를만드는방법은다양하다. 사람이라는것이간사해서한번맛들인방법을끝까지고집하게된다. 그래서 ATL을사용해본사람은절대다른방법으로하려고하지않는다. 하지만, ATL은 COM을완벽하게지원하지않는다는걸알아야한다. 그렇다고 ATL에서지원하는것이상만들자신도없지만말이다. 그래

그리고 난절대 COM과관련된프로그래밍을하지않아 라고장담하는사람들조차도자신도모르게사용하고있다는것을알고있는지모르겠다. 쉘이바로그대표적인예이다. 단축아이콘을만들고, 아이콘트레이를사용하고하는것에서실제코딩에는 COM과관련된부분이없을지라도내부적으로 COM을사용한다는것을말이다. 바

PowerPoint 프레젠테이션

Dialog Box 실행파일을 Web에 포함시키는 방법

PCServerMgmt7

rmi_박준용_final.PDF

Interstage5 SOAP서비스 설정 가이드

01-OOPConcepts(2).PDF


untitled

2015 경제ㆍ재정수첩

untitled

PowerPoint 프레젠테이션

thesis

Something that can be seen, touched or otherwise sensed

1

Modern Javascript

<4D F736F F F696E74202D20BECBC6C420BAEDB7A3B5F9C0BB20C0FBBFEBC7D F7720C7CAC5CD20B9D720C0CCB9CCC1F620C7DAB5E9B8B55F >

C# Programming Guide - Types

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

chap10.PDF

untitled

신림프로그래머_클린코드.key

tr02.doc

05-class.key

Deok9_Exploit Technique

MPLAB C18 C

12-file.key

스마트폰 모바일 랩 세미나

Domino Designer Portal Development tools Rational Application Developer WebSphere Portlet Factory Workplace Designer Workplace Forms Designer

03장.스택.key

디지털포렌식학회 논문양식

final_thesis

No Slide Title

The_IDA_Pro_Book

vm-웨어-앞부속

교육2 ? 그림

Microsoft PowerPoint - 04-UDP Programming.ppt


I T C o t e n s P r o v i d e r h t t p : / / w w w. h a n b i t b o o k. c o. k r

PowerPoint 프레젠테이션

디지털포렌식학회 논문양식

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

Chap7.PDF

Lab10

thesis

5.스택(강의자료).key

<32382DC3BBB0A2C0E5BED6C0DA2E687770>

LXR 설치 및 사용법.doc

강의10

초보자를 위한 C# 21일 완성

09-interface.key

Week13

thesis

NoSQL

본책- 부속물

UML

<C3CA3520B0FAC7D0B1B3BBE7BFEB202E687770>

歯9장.PDF

Ç¥Áö

JMF3_심빈구.PDF

C++-¿Ïº®Çؼ³10Àå

13 Who am I? R&D, Product Development Manager / Smart Worker Visualization SW SW KAIST Software Engineering Computer Engineering 3

歯이시홍).PDF

Microsoft Word - ExecutionStack

2. GCC Assembler와 AVR Assembler의차이 A. GCC Assembler 를사용하는경우 i. Assembly Language Program은.S Extension 을갖는다. ii. C Language Program은.c Extension 을갖는다.

½ºÅ丮ÅÚ¸µ3_³»Áö

272*406OSAKAÃÖÁ¾-¼öÁ¤b64ٽÚ

PART

£01¦4Àå-2

Part Part

chap7.PDF

歯7장.PDF

PowerPoint 프레젠테이션

ch09

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V


Multi Channel Analysis. Multi Channel Analytics :!! - (Ad network ) Report! -! -!. Valuepotion Multi Channel Analytics! (1) Install! (2) 3 (4 ~ 6 Page

1217 WebTrafMon II

282서비스업관리-마트

양성내지b72뼈訪?303逞



자식농사웹완

chungo_story_2013.pdf

*중1부

2

Çѱ¹ÀÇ ¼º°øº¥Ã³µµÅ¥

...._



전반부-pdf

표1.4출력

003-p.ps

<4D F736F F F696E74202D20312E20B0E6C1A6C0FCB8C15F3136B3E2C7CFB9DDB1E25F325FC6ED28C0BA292E >

_

12월월간보고서내지편집3

중앙도서관소식지겨울내지33

에너지포커스 2007년 가을호


Transcription:

Copyright, 2001 Multimedia Lab., CH 3. COM object (In-process server) Eun-sung Lee twoss@mmlab.net Multimedia Lab. Dept. of Electrical and Computer Eng. University of Seoul Seoul, Korea

0. Contents 1. Main Objectives 2. Overview 3. How to create DLL 4. Let s s make a DLL 5. Reference 2004-10-15 Eun-sung Lee DirectShow -2

1. Main Objectives COM COM Class (In-Process server) 2004-10-15 Eun-sung Lee DirectShow -3

2. Overview COM Library COM Client Server Application API. CLSID,. Co Ex) CoInitialize, CoCreateInstance COMPOBJ.DLL 2004-10-15 Eun-sung Lee DirectShow -4

2. Overview COM Object 1. COM Component Regsvr32 Ex) regsvr32 addback.dll dll 2. COM Library [CoInitialize] 3. Interface COM Object CLSID 4. COM Object Instance [CoCreateInstance] 5. Interface Pointer 6. method, 7. COM Library [CoUnInitailize] 2004-10-15 Eun-sung Lee DirectShow -5

3. How to Create a DLL 1. CoCreateInstance(clsid clsid, iid, ) 2. CoGetClassObject() HKEY_CLASSES_ROOT CLSID clsid CLSID InprocServer32(in InprocServer32(in- process) COM. 3. CoLoadLibrary() dll load 4.DllGetClassObject DllGetClassObject() clsid COM Class Factory IClassFactory pointer IClassFactory iid pointer ->CoCreateInstance IClassFactory IClassFactory:: ::CreateInstance 2004-10-15 Eun-sung Lee DirectShow -6

3. How to Create a DLL CoCreateInstance( CLSID_FilterGraph FilterGraph,//** [In] Class Identifier(CLSID) of the object NULL, //** [In] Pointer to controlling IUnknown CLSCTX_INPROC,//** [In] Server Context IID_IGraphBuilder IGraphBuilder,//** [In] Reference to the identifier of the interface (void **)&pgraph );//** //** [Out] Address of pointer variable that receives the interface pointer requested in riid. 2004-10-15 Eun-sung Lee DirectShow -7

Use Case Client CoInitialize(); CoCreateInstance(CLSID, IID); CoUninitialize(); Dllmain() DllGetClassObject() DllCanUnloadNow() SetRegKeyValue() DllRegisterServer() DllUnRegisterServer() Class Factory Create Instance IClassFactory DLL (IN-process Server) New COM object CAddBack IInterface Linear 4G memory(one Process Own) COM Library CoCreateInstance(CLSID, IID); System registry CoGetClassObject CoLoadlibrary DLL (IN-process) DLL (IN-process) DLL (IN-process) DLL (IN-process) DLL (IN-process) DLL (IN-process) DLL (IN-process) 2004-10-15 Eun-sung Lee DirectShow -8

3. How to Create a DLL - Class Factory Class Factory COM Class Instance COM Class IClassFactory Interface. IClassFactory Interface COM Interface IUnKnown Interface. ClassFactory provides two methods : CreateInstance,, creates an uninitialized object of a specified CLSID LockServer,, locks the object's server in memory, allowing new objects to be created more quickly 2004-10-15 Eun-sung Lee DirectShow -9

3. How to Create a DLL - CreateInstance IClassFactory:: ::CreateInstance Creates an uninitialized object. : CLSID. UNKNOWN.H (CoGetClassObject() CLSID) HRESULT CreateInstance( IUnknown * punkouter ); punkouter, //Pointer to whether object is or isn't part of an aggregate REFIID riid, //Reference to the identifier of the void ** ppvobject ppvobject //Address of output variable that the interface pointer requested in riid interface receives 2004-10-15 Eun-sung Lee DirectShow -10

3. How to Create a DLL - LockServer IClassFactory :: LockServer( ( ) Client IClassFactory Interface Pointer Client COM Object Dll Unload. HRESULT stdcall CFAddBack:: ::LockServer(BOOL block) { if(block block) ++g_clocks clocks; else --g_ g_clocks; } return S_OK; 2004-10-15 Eun-sung Lee DirectShow -11

3. How to Create a DLL - DLL Functions DLL Functions DllMain: The DLL entry point. The name DllMain is a placeholder for the library- defined function name. DllMain DllGetClassObject: Creates a class factory instance. DllCanUnloadNow: Queries whether the DLL can safely be unloaded. DllGetClassObject DllCanUnloadNow DllRegisterServer: Creates registry entries for the DLL. Call by regsvr32.exe DllRegisterServer DllUnregisterServer: Removes registry Removes registry entries for the DLL. Call by regsvr32.exe 2004-10-15 Eun-sung Lee DirectShow -12

3. How to Create a DLL - DllGetClassObject DllGetClassObject COM class instance, COM class Class Factory COM class Instance. ICalssFactory interface pointer client. In_process server DllGetClassObject. 2004-10-15 Eun-sung Lee DirectShow -13

3. How to Create a DLL STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { HRESULT hr = CLASS_E_CLASSNOTAVAILABLE; IUnknown* punk = NULL; if(rclsid == CLSID_AddBack) { hr = E_OUTOFMEMORY; punk = new CFAddBack; } } if(punk!= NULL) { hr = punk->queryinterface(riid, ppv); //IClassFactory pointer if(failed(hr)) delete punk; } return hr; 2004-10-15 Eun-sung Lee DirectShow -14

3. How to Create a DLL DllRegisterServer/DllUnregisterServer DllUnregisterServer In_process srever REGSVR32.exe Dll DllRegisterServer export. Ex. >> regsvr32 <name.dll dll> DllUnregisterServer export. Ex. >> regsvr32 /u <name.dll dll> 2004-10-15 Eun-sung Lee DirectShow -15

3. How to Create a DLL module-definition definition (.def) file If you are not using the declspec declspec(dllexport) keyword to export the DLL s s functions, then the DLL requires a.def file : export all the DLL functions except for the entry-point function. The following is an example *.def file. Ex> LIBRARY "AddBack" AddBack.Dll" EXPORTS DllCanUnloadNow @1 PRIVATE DllGetClassObject @2 PRIVATE DllRegisterServer @3 PRIVATE DllUnregisterServer @4 PRIVATE 2004-10-15 Eun-sung Lee DirectShow -16

3. How to Create a DLL DllCanUnloadNow CoFreeUnusedLibraries COM Library API DLL Unload STDAPI DllCanUnloadNow(void) { if(g_ g_cobjects == 0 && g_clocks == 0) return S_OK; return S_FALSE; } g_cobject cobject 2004-10-15 Eun-sung Lee DirectShow -17

4. Let s s make a DLL AddBack.Dll IAddEnd IAdd CAddBack COM Class IClassFactory DllMain ( ) CFAddBack DllGetClassObject( ( ) DllCanUnloadNow ( ) DllRegisterServer ( ) Class Factory COM Class 2004-10-15 Eun-sung Lee DirectShow -18

4. Let s s make a DLL - IDL 1) Definition Interface (IAddEnd( IAddEnd,IAdd) 2004-10-15 Eun-sung Lee DirectShow -19

4. Let s s make a DLL Ex) interface IAddEnd [ uuid(c6f96d90-9fcf-11d1-b20a-0060970a3516), object ] interface IAddEnd : IUnknown { import "unknwn.idl"; HRESULT GetAddEnd([out] short* result); HRESULT SetAddEnd([in] short addend); HRESULT GetSum([out] short* result); HRESULT Clear(void); }; 2004-10-15 Eun-sung Lee DirectShow -20

4. Let s s make a DLL In Addback.h #if defined( cplusplus) &&!defined(cinterface) interface DECLSPEC_UUID("C6F96D90-9FCF-11d1-B20A- 0060970A3516") IAddEnd : public IUnknown { public: virtual HRESULT STDMETHODCALLTYPE GetAddEnd( /* [out] */ short RPC_FAR *result) = 0; virtual HRESULT STDMETHODCALLTYPE SetAddEnd( /* [in] */ short addend) = 0; virtual HRESULT STDMETHODCALLTYPE GetSum( /* [out] */ short RPC_FAR *result) = 0; virtual HRESULT STDMETHODCALLTYPE Clear( void) = 0 }; 2004-10-15 Eun-sung Lee DirectShow -21

4. Let s s make a DLL In Addback_i.c const IID IID_IAddEnd IAddEnd = {0xC6F96D90,0x9FCF,0x11d1,{0xB2,0x0A,0x 00,0x60,0x97,0x0A,0x35,0x16}}; 2004-10-15 Eun-sung Lee DirectShow -22

4. Let s s make a DLL 2. In_process_server Client Files LockServer( ) 2004-10-15 Eun-sung Lee DirectShow -23

4. Let s s make a DLL Relationship 2004-10-15 Eun-sung Lee DirectShow -24

5. Reference http://www.microsoft.com/com ATL COM Inside COM Essential COM 2004-10-15 Eun-sung Lee DirectShow -25