Introduction to COM by Mark Bartosik August 2001 Introduction to COM Prerequisites: –A small experience in at least one programming language, ideally C,

Slides:



Advertisements
Similar presentations
Introduction to .NET Framework
Advertisements

Tahir Nawaz Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a.
COM vs. CORBA.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Intro to COM What is it and how do I use it?. Objectives Teach the fundamentals of COM. Understand the reason for using it. Learn to make a simple in-process.
OPC - OLE For Process Control Paul C. Shafer Bently Nevada Corp.
1 JBus, A Platform Independent Publish/Subscribe Bus for CWave 2000 M.S. Thesis Defense Joseph W. Longson March 30, 2000.
Web Services Members Troy Tony Ellen Vincent. Web Services What is it Why is it useful What have been solved Demo Alternative technologies Question.
CSE3030Lecture 11 Know Your User The First Slogan.
Computers: Tools for an Information Age
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
.NET Mobile Application Development Remote Procedure Call.
Introduction 01_intro.ppt
Chapter 7 Designing Classes. Class Design When we are developing a piece of software, we want to design the software We don’t want to just sit down and.
Intro to COM What is it and what can it do for me?
DCOM Technology. What is DCOM? DCOM is just COM with a longer wire DCOM is just COM with a longer wire DCOM extends COM to support communication among.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
ACCU Conference 2003, © Mark Bartosik, 1 An Introduction to Native Postmortem Debugging This talk contains x86 and OS and compiler specific.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
1 Modular Software/ Component Software 2 Modular Software Code developed in modules. Modules can then be linked together to produce finished product/program.
Visual Basic: An Object Oriented Approach 12 – Creating and using ActiveX objects.
Design-Making Projects Work (Chapter7) n Large Projects u Design often distinct from analysis or coding u Project takes weeks, months or years to create.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
COM vs. CORBA Computer Science at Azusa Pacific University September 19, 2015 Azusa Pacific University, Azusa, CA 91702, Tel: (800) Department.
Mr C Johnston ICT Teacher BTEC IT Unit 06 - Lesson 01 Introduction to Computer Programming.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
COM/DCOM Implementation Basics of: Object creation and access Object Reuse Interface referencing.
COMCOM omponent bject odel After this presentation, you will: Be Able To: Conceptual understanding of COM How it works, What it’s used for Decode Acronyms.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
Java Introduction to JNI Prepared by Humaira Siddiqui.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Introduction to COM and ActiveX Controls. What is an object? In the Fayad sense of the word.
CIT 590 Intro to Programming First lecture on Java.
Component Technology. Challenges Facing the Software Industry Today’s applications are large & complex – time consuming to develop, difficult and costly.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
National Diploma Unit 4 Introduction to Software Development Introduction to Programming Languages.
Module 4 Part 2 Introduction To Software Development : Programming & Languages Introduction To Software Development : Programming & Languages.
GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.
Remote Procedure Call RPC
Threading in COM What is an Apartment and Why Do I Care?
Computer Science Lecture 3, page 1 CS677: Distributed OS Last Class: Communication in Distributed Systems Structured or unstructured? Addressing? Blocking/non-blocking?
Georgia Institute of Technology Speed part 1 Barb Ericson Georgia Institute of Technology May 2006.
Text Introduction to.NET Framework. CONFIDENTIAL Agenda .NET Training – Purpose  What is.NET?  Why.NET?  Advantages  Architecture  Components: CLR,
Introduction to ASP.NET development. Background ASP released in 1996 ASP supported for a minimum 10 years from Windows 8 release ASP.Net 1.0 released.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
A S P. Outline  The introduction of ASP  Why we choose ASP  How ASP works  Basic syntax rule of ASP  ASP’S object model  Limitations of ASP  Summary.
Jim Fawcett CSE775 - Distributed Objects Spring 2014
Component Object Model(COM)
CSE791 - Distributed Objects, Spring 2002
CSE775 - Distributed Objects, Spring 2006
Learning to Program D is for Digital.
Chapter 1 Introduction to Computers, Programs, and Java
Introduction to .NET Framework Ch2 – Deitel’s Book
Out-of-Process Components
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Programming COMP104: Fundamentals and Methodology Introduction.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Interpreter Style Examples
Introduction to .NET By : Mr. V. D. Panchal Content :
Object Oriented Practices
Lecture 4: RPC Remote Procedure Call CDK: Chapter 5
Tonga Institute of Higher Education IT 141: Information Systems
COMPONENTS – WHY? Object-oriented source-level re-use of code requires same source code language. Object-oriented source-level re-use may require understanding.
Out-of-Process Components
Tonga Institute of Higher Education IT 141: Information Systems
Presented By Justas Raslanas
Last Class: Communication in Distributed Systems
Presentation transcript:

Introduction to COM by Mark Bartosik August 2001 Introduction to COM Prerequisites: –A small experience in at least one programming language, ideally C, C++ or VB. –Aim: Understand the need for COM and basically what it does. We will just be scratching the surface.

Introduction to COM by Mark Bartosik August 2001 A quick survey Hands up if you can program in C C++ Visual Basic C# Java Ada Assembler Java script, VB script What about threading? Who thinks they can write multithreaded code?

Introduction to COM by Mark Bartosik August 2001 The problem You are a project manager. You have a project that is best written as: 1/3 C++ (half of which is multi-threaded) 1/3 Visual Basic 1/3 Third party code, in unknown language How do you integrate all this?

Introduction to COM by Mark Bartosik August 2001 COM Component Object Model COM is the “glue” or the “protocol” to glue components and objects together to form a cohesive product.

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions –Accessing data –Requesting services –Packaging code –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Let’s look at how to call a function int func0(int a, int b) { return 0; } int main(int, char * []) { return func0(6, 7); } This computer does not understand this. A ‘C’ compiler does. The ‘C’ compiler translates the ‘C’ to assembler or machine code. The CPU then executes the machine code.

Introduction to COM by Mark Bartosik August 2001 Calling a function The caller must pass to the callee the function parameters or arguments. The callee must pass the result to the caller. e.g. int subtract(int arg1, int arg2); What does this return? subtract(7, 4);

Introduction to COM by Mark Bartosik August 2001 A binary contract The CPU only understands raw bytes not ‘C’ or any other language. So in practice the caller and callee must have a common agreement on what the assembler looks like. The problem comes when the caller is written by Jane in VB and the callee by Jim in C++.

Introduction to COM by Mark Bartosik August 2001 So what does the assembler look like? You do not need to understand the assembler - the point is there is no standard. extern “C” int func0(int, int); push7 push6 call_func0 addesp, 8

Introduction to COM by Mark Bartosik August 2001 So what does the assembler look like? You do not need to understand the assembler - the point is there is no standard. struct object_t { int func1(int, int); }; push7 push6 leaeax, DWORD PTR _obj$[ebp] pusheax

Introduction to COM by Mark Bartosik August 2001 So what does the assembler look like? You do not need to understand the assembler - the point is there is no standard. struct object_t { int func1(int, int); }; push7 push6 leaeax, DWORD PTR _obj$[ebp] pusheax addesp, 12

Introduction to COM by Mark Bartosik August 2001 So what does the assembler look like? You do not need to understand the assembler - the point is there is no standard. struct object_t { int func1(int, int); }; push7 movedx, 6 leaecx, DWORD PTR _obj$[ebp]

Introduction to COM by Mark Bartosik August 2001 Everyone has their own standard! Each language can have its own conventions. Each vendor of a language may have a different standard. Even with one vendor and one language there can be different standards between different compiler versions. Even with the same language, same vendor, and same compiler version, and same platform (OS and CPU), there can be different contracts for different functions, e.g. __stdcall, __cdecl, __fastcall In addition there are different naming conventions: _func0,

Introduction to COM by Mark Bartosik August 2001 Enter COM COM is language neutral COM specifies a tight binary contract

Introduction to COM by Mark Bartosik August 2001 Here’s a small part of the contract

Introduction to COM by Mark Bartosik August 2001 Here’s the assembler You do not need to understand the assembler push7 push6 moveax, DWORD PTR _COMobj$[ebp] movedx, DWORD PTR [eax] movecx, DWORD PTR _COMobj$[ebp] callDWORD PTR [edx+12] If you know assembler, you will see that this is not efficient. But it is well defined.

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data –Requesting services –Version control –Packaging code –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Accessing data You thought that calling functions was problematic! Accessing data is far worse! There are many more ways to represent data than there are ways to call functions. Jim must not be allowed to access Jane’s data. Jane’s data should be private to Jane.

Introduction to COM by Mark Bartosik August 2001 Accessing data Global variables are bad. What is the first rule of object orientation? –Encapsulate

Introduction to COM by Mark Bartosik August 2001 Encapsulation struct employee_t { std::string name; unsigned number; };

Introduction to COM by Mark Bartosik August 2001 Encapsulation function call

Introduction to COM by Mark Bartosik August 2001 Encapsulation There is no accessible data There are only functions

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data  –Requesting services –Version control –Packaging code –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Creating an instance of a class (without COM) VB: dim bartosik as CEmployee dim bartolotta as CEmployee C++ (without COM) CEmployee bartosik;

Introduction to COM by Mark Bartosik August 2001 How can VB create a C++ object? What is a CEmployee is VB may not be the same as a CEmployee in C++. What is needed is a language neutral means to say a “new instance of CEmployee”. Under the covers (sometimes) CoCreateInstance

Introduction to COM by Mark Bartosik August 2001 Language bindings VB

Introduction to COM by Mark Bartosik August 2001 Language bindings C++ (native)

Introduction to COM by Mark Bartosik August 2001 Language bindings C++ (via #import)

Introduction to COM by Mark Bartosik August 2001 Language bindings Java script

Introduction to COM by Mark Bartosik August 2001 Language bindings VB script

Introduction to COM by Mark Bartosik August 2001 Language bindings C Forget it. It’s too complicated, and impractical!

Introduction to COM by Mark Bartosik August 2001 Everything is an object!

Introduction to COM by Mark Bartosik August 2001 How to create an object VB

Introduction to COM by Mark Bartosik August 2001 How to create an object C++

Introduction to COM by Mark Bartosik August 2001 How to create an object Java script

Introduction to COM by Mark Bartosik August 2001 How to create an object VB script

Introduction to COM by Mark Bartosik August 2001 What are these long numbers ? The long numbers are called GUIDs. Globally Unique Identifiers, also called UUIDs (universally unique identifiers). They are pseudo random 128 bit numbers this is about 3x10 38 or 300,000,000,000,000,000,000,000,000,000,000,000,000 That’s more than there are particles on this planet, so they can be considered totally unique.

Introduction to COM by Mark Bartosik August 2001 What’s a class If we want to model a company we might have a class “CEmployee”, from which we create multiple instances of employees. The class models the concept of an employee and the objects of that class represent individual employees.

Introduction to COM by Mark Bartosik August 2001 Creating a COM object VB: dim bartosik as CEmployee dim bartolotta as CEmployee C++

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data  –Requesting services  - this is really creating objects –Version control –Packaging code –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Version control Now our company evolves and we want to change how an instance of “CEmployee” behaves. What do we do: A) Change every component in the system that uses a CEmployee? B) Restrict the changes to only compatible changes? C) Create a CEmployee2 class? D) Extend CEmployee to support the old and new interfaces.

Introduction to COM by Mark Bartosik August 2001 Answer With COM you can do any of the above, sort of. VB limits us to options A, B, & C. C++ an do any of the above. When a client creates an instance of a class using CoCreateInstance it uses a GUID to specify to Windows that it means the CEmployee class. Once it has a CEmployee class it asks the object for a specific interface (old or new), it uses a GUID to specify which interface (the old GUID or the new GUID). QueryInterface (if you know C++ think of dynamic_cast)

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data  –Requesting services  - this is really creating objects –Version control  –Packaging code –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Sharing objects You’ve got two pieces of code (maybe in different languages) that both want to access the employee object. How do they ensure that they don’t leak employee objects. AddRef Release

Introduction to COM by Mark Bartosik August 2001 Native support Visual Basic, C#, integrate seamlessly with COM, it is hard to tell the difference between a COM object and a native language object. C++ can be extended through classes to integrate with COM, or it can have native compiler support. In VC5 and VC6 it is moderate compiler support, in VC7 (.NET) it has extensive compiler support. VB script and Microsoft Java script have limited support. C has no support

Introduction to COM by Mark Bartosik August 2001 Packaging code This is simple. Either a.dll or.exe is created. The dll must implement a fixed number of functions: DllCanUnloadNow <- beyond this talk DllGetClassObject <- how to create an object DllRegisterServer <- how to install DllUnregisterServer <- how to uninstall The.exe must call specified functions in startup to install, uninstall or expose object creation.

Introduction to COM by Mark Bartosik August 2001 What’s ActiveX Buzz-word ActiveX DLL (a COM.dll provides services) ActiveX server (a COM.exe provide services) ActiveX control (a.ocx same as COM.dll, but provides a GUI, like a custom push button).

Introduction to COM by Mark Bartosik August 2001 Installing a package Regsvr32 your.dll Regsvr32 your.ocx Regsvr32 /u your.dll your.exe -install These install data into the machine’s registry. A GUID identifying each class that the DLL implements.

Introduction to COM by Mark Bartosik August 2001 The chain of events To create an object: dim bartosik as CEmployee VB translates CEmployee to {0222A94E A-7A788DEE911C} VB calls CoCreateInstance using the GUID Windows looks in the registry to find which DLL implements the class represented by the GUID. Windows loads that dll (or exe) and calls a function in it to request a new instance of that class. CoCreateInstance returns a pointer to the new employee object to VB. VB allows that pointer to be accessed via the variable ( bartosik ). VB allows the functions of the employee to be called, using the COM standards.

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data  –Requesting services  - this is really creating objects –Version control  –Packaging code  –Working with threads (or not)

Introduction to COM by Mark Bartosik August 2001 Threads this is really complex There are two styles of writing code: –Single threaded –Multithreaded In general single threaded code, is only happy being called by single threaded code (i.e. in a single thread). Multithreaded code can be called by either. So single threaded code needed to be protected or isolated from access by multiple threads.

Introduction to COM by Mark Bartosik August 2001 Apartments Apartments isolate different threading models. Apartments control how these two types of code interact. Anything else to too complex for today.

Introduction to COM by Mark Bartosik August 2001 Before COM There was no standard for… –Calling functions  –Accessing data  –Requesting services  - this is really creating objects –Version control  –Packaging code  –Working with threads (or not) 

Introduction to COM by Mark Bartosik August 2001 Summary COM allows us to Mix code from different languages, compilers, vendors, threading models, etc. Solves many version control issues. Encourages encapsulation (protects data through use of interfaces).

Introduction to COM by Mark Bartosik August 2001 Don’t believe the hype Not everything is an object! COM can be very inefficient (so can VB). Can be thousands of times slower than raw C++. COM solves some problems and causes other problems. There is no silver bullet - be a little skeptical. Be skeptical. There is no good do it all solution. C, C++, Java, C#, VB, Ada all have strengths and weaknesses. So does COM, but what COM does is give you more flexibility in choosing the right language for the task by providing some glue.

Introduction to COM by Mark Bartosik August 2001 Where next?.NET ?.NET is the successor to COM, but integrates tightly with COM. Hype? 1 year ago, the industry leaders were saying that COM+ was the way forward, now they say COM is dead long live.NET. The industry leads need to sell more courses, software, and books, and hype is a good selling technique. Books: Effective COM, Don Box -- but this is not for beginners!