SlideShare a Scribd company logo
1
INTERFACE
in COM
nonezerok@gmail.com
저자의 동의 없이 본 문서 일부 또는 전체의 무단복제를 불허합니다.
2
a.exe b.dll
it is possible
extern “C” void __stdcall Fx();
Dynamic Link Library
(Local Procedure Call)
3
a.exe b.dll
Is it possible ?
Invoking functions of an Object
4
a.exe b.dll
No !!!
encapsulated and information hidden
Invoking functions of an Object
5
a.exe b.dll
interface
however,
How to achieve it ?
make a window;
call it an interface
6
Virtual Function Technique
class A 
{ int d1;
int show() { cout << “A” << endl; };
} ;
class B: public A
{ int d2;
int show() { cout << “B” << endl; };
} ;
void main()
{ A  a, *pA;
B  b, *pB;
pA = &b;
pA‐>show(); // A or B ? What is your expectation ?
}
7
class A 
{ int d1;
virtual int show() { cout << “A” << endl; };
} ;
class B: public A
{ int d2;
int show() { cout << “B” << endl; };
} ;
void main()
{ A  a, *pA;
B  b, *pB;
pA = &b;
pA‐>show();
// before and after adding virtual
cout << sizeof(a) << endl;
}
How about adding another virtual function ?
virtual int draw() in the class A
8
vPtr
d1
d2
A::show()
B::show()
A::draw()
B::draw()
pA
(&b)
virtual function
table
dynamic binding
Note: we can invoke B’s functions using A
9
Conceptual View of Interface
a.exe b.dll
public
10
struct IX // pure abstract class (here, public class)
{ virtual void __stdcall Fx1() = 0; // pure virtual function
virtual void __stdcall Fx2() = 0; //  abstract class
};
class CA: public IX
{ void __stdcall Fx1() { cout << “Fx1” << endl; };
void __stdcall Fx2() { cout << “Fx2” << endl; };
};
void main()
{ CA* pA = new CA;
IX* pX = (IX*)pA;
pX‐>Fx1();
delete pA;
}
• Using the virtual function technique, we can
indirectly invoke the function of a COM object
• Public Pure Abstract Class
Definition of Interface
11
#define interface struct
interface IX // pure abstract class (here, public class)
{ virtual void __stdcall Fx1() = 0; // pure virtual function
virtual void __stdcall Fx2() = 0; //  abstract class
};
class CA: public IX
{ void __stdcall Fy1() { cout << “Fy1” << endl; };
void __stdcall Fy2() { cout << “Fy2” << endl; };
};
void main()
{ CA* pA = new CA;
IX* pX = (IX*)pA;
pX‐>Fx1();
delete pA;
}
Can this main function be a client-side code ?
12
interface IY
{ virtual void __stdcall Fy1() = 0;
virtual void __stdcall Fy2() = 0;
};
class CA: public IX, public IY
{ void __stdcall Fy1() { cout << “Fy1” << endl; };
void __stdcall Fy2() { cout << “Fy2” << endl; };
};
IX* CreateInstance()
{ CA* pA = new CA;
return pA;
}
void main()
{ IX* pX = CreateInstance();
pX‐>Fx1();
IY* pY = (IY*)pX; // ?
pY‐>Fy1(); // ?
delete pX;
}
What for adding another interface ?
13
interface IU { };
interface IX: IU { … };
interface IY: IU { … };
class CA: public IX, public IY
{ void __stdcall Fx1() { cout << “Fx1” << endl; };
void __stdcall Fx1() { cout << “Fx2” << endl; };
void __stdcall Fy1() { cout << “Fy1” << endl; };
void __stdcall Fy2() { cout << “Fy2” << endl; };
} ;
IU* CreateInstance()
{ CA* pA = new CA;
return (IX*)pA;
}
void main()
{ IU* pU = CreateInstance();
IX* pX = (IX*)pU;
pX‐>Fx1(); // ?
IY* pY = (IY*)pU; 
pY‐>Fy1();  // ?
delete pX;
}
14
interface IU 
{ virtual bool __stdcall QI(int id, void** ppv) = 0;
};
interface IX: IU { … };
interface IY: IU { … };
class CA: public IX, public IY
{ bool __stdcall QI(int id, void** ppv)
{ if (id == IID_IX) *ppv = (IX*) this;
else if (id == IID_IY) *ppv = (IY*) this;
else { *ppv = NULL; return false; };
return true;
}
};
void main()
{ IU* pU = CreateInstance();
IX* pX;  pU‐>QI(IID_IX, (void**)&pX);  pX‐>Fx1();
IY* pY;  pU‐>QI(IID_IY, (void**)&pY);  pY‐>Fy1(); 
delete pX;
}
15
Client for DLL Server
typedef IUnknown* (*FUNCPTR)();
void main()
{
HINSTANCE hDll;
hDll = LoadLibary(“d:comserver.dll”);
FUNCPTR CreateInstance 
= (FUNCPTR)::GetProcAddress (hDll, ʺCreateInstanceʺ);
IU* pU = CreateInstance();
IX* pX;  pU‐>QI(IID_IX, (void**)&pX);  pX‐>Fx1();
IY* pY;  pU‐>QI(IID_IY, (void**)&pY);  pY‐>Fy1(); 
delete pX;
FreeLibrary(hDll);
}
path
If the path is changed ?

More Related Content

PDF
Programming basics
PPT
Surprise! It's PHP :) (unabridged)
PPTX
What's new in c#7
PDF
Insecure coding in C (and C++)
PPTX
Programming in C
PDF
systems programming lab programs in c
PDF
Core Java Meetup #9 - Quiz Questions - 6th May
PDF
Solid C++ by Example
Programming basics
Surprise! It's PHP :) (unabridged)
What's new in c#7
Insecure coding in C (and C++)
Programming in C
systems programming lab programs in c
Core Java Meetup #9 - Quiz Questions - 6th May
Solid C++ by Example

What's hot (20)

PDF
C++ idioms by example (Nov 2008)
PPTX
Александр Куцан: "Static Code Analysis in C++"
PDF
C++ for Java Developers (JavaZone 2017)
PDF
How do i - create a native interface
PDF
Metaprogramming
PPTX
Kostiantyn Grygoriev "Wrapping C++ for Python"
PPTX
P/Invoke - Interoperability of C++ and C#
PDF
C++ The Principles of Most Surprise
PPTX
What static analyzers can do that programmers and testers cannot
PPTX
Summary of C++17 features
PDF
1 introducing c language
PDF
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
PPT
01 dll basics
PDF
PDF
Virtual Functions
PPT
C++ programming
TXT
Keypad program
PPTX
Python分享
KEY
Yapcasia2011 - Hello Embed Perl
PPTX
Pure virtual function and abstract class
C++ idioms by example (Nov 2008)
Александр Куцан: "Static Code Analysis in C++"
C++ for Java Developers (JavaZone 2017)
How do i - create a native interface
Metaprogramming
Kostiantyn Grygoriev "Wrapping C++ for Python"
P/Invoke - Interoperability of C++ and C#
C++ The Principles of Most Surprise
What static analyzers can do that programmers and testers cannot
Summary of C++17 features
1 introducing c language
DEF CON 23 - COLIN O'FLYNN - dont whisper my chips
01 dll basics
Virtual Functions
C++ programming
Keypad program
Python分享
Yapcasia2011 - Hello Embed Perl
Pure virtual function and abstract class
Ad

Similar to interface (20)

KEY
Your codebase sucks! and how to fix it
PDF
Scripting
PDF
polymorpisum-140106223024-phpapp01.pdf
PDF
Javascript Best Practices
PPTX
C ISRO Debugging
PDF
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
PPSX
Constructor and destructor
PDF
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
PDF
Oop Presentation
PDF
C++aptitude questions and answers
PDF
Inheritance and polymorphism
PDF
Declaring friend function with inline code
PDF
[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan
DOC
PPTX
Navigating the xDD Alphabet Soup
PDF
Kotlin Developer Starter in Android projects
PDF
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
PDF
JVM Mechanics: When Does the JVM JIT & Deoptimize?
PDF
Silicon Valley JUG: JVM Mechanics
Your codebase sucks! and how to fix it
Scripting
polymorpisum-140106223024-phpapp01.pdf
Javascript Best Practices
C ISRO Debugging
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Constructor and destructor
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Oop Presentation
C++aptitude questions and answers
Inheritance and polymorphism
Declaring friend function with inline code
[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan
Navigating the xDD Alphabet Soup
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android - STX Next Lightning Talks - Feb 12, 2016
JVM Mechanics: When Does the JVM JIT & Deoptimize?
Silicon Valley JUG: JVM Mechanics
Ad

More from jaypi Ko (20)

PDF
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
PDF
개념 이해가 쉬운 Variational Autoencoder (VAE)
PDF
[신경망기초]오류역전파알고리즘구현
PPTX
파이썬설치
PDF
객체지향 단어가 의미하는 것
PDF
C언어 들어가기
PDF
C언어 연산자에 대해 간과한 것
PDF
[확률통계]04모수추정
PDF
MFC 프로젝트 시작하기
PDF
01 윈도우프로그램 들어가기
PDF
13 사용자 메세지 처리
PDF
12 컨트롤에서의 메세지 처리
PDF
11 노티피케이션코드
PDF
10 컨트롤윈도우
PDF
09 윈도우스타일
PDF
08 부모윈도우 자식윈도우
PDF
07 윈도우 핸들
PDF
06 일반적 유형의 프로그램
PDF
05 윈도우 프로그램 유형
PDF
04 이벤트처리
CVPR 2022 Tutorial에 대한 쉽고 상세한 Diffusion Probabilistic Model
개념 이해가 쉬운 Variational Autoencoder (VAE)
[신경망기초]오류역전파알고리즘구현
파이썬설치
객체지향 단어가 의미하는 것
C언어 들어가기
C언어 연산자에 대해 간과한 것
[확률통계]04모수추정
MFC 프로젝트 시작하기
01 윈도우프로그램 들어가기
13 사용자 메세지 처리
12 컨트롤에서의 메세지 처리
11 노티피케이션코드
10 컨트롤윈도우
09 윈도우스타일
08 부모윈도우 자식윈도우
07 윈도우 핸들
06 일반적 유형의 프로그램
05 윈도우 프로그램 유형
04 이벤트처리

Recently uploaded (20)

PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Construction Project Organization Group 2.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
web development for engineering and engineering
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Sustainable Sites - Green Building Construction
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Mechanical Engineering MATERIALS Selection
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
Arduino robotics embedded978-1-4302-3184-4.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Construction Project Organization Group 2.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
web development for engineering and engineering
CYBER-CRIMES AND SECURITY A guide to understanding
Lecture Notes Electrical Wiring System Components
Sustainable Sites - Green Building Construction
bas. eng. economics group 4 presentation 1.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mechanical Engineering MATERIALS Selection
Structs to JSON How Go Powers REST APIs.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
UNIT 4 Total Quality Management .pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
Foundation to blockchain - A guide to Blockchain Tech

interface