C# COM Interoperability Late Binding

Slides:



Advertisements
Similar presentations
Component Object Model
Advertisements

Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation.
COM vs. CORBA.
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.
AP 01/01 Asynchronous Calls Standard COM+ model is completely synchronous –Emulates standard procedure calls –Problematic in distributed scenarios with.
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
CHAPTER 3 The Component Object Model and DirectX © 2008 Cengage Learning EMEA.
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
Kalpesh Padia Reflection in.Net. OVERVIEW 9/19/
 Michael Bernstein Principal Software Design Engineer Microsoft Corporation.
COM/DCOM Implementation Basics of: Object creation and access Object Reuse Interface referencing.
COM and DCOM CS 562 February 27, Motivation Data Analyzer Resource Monitor int compute (…) { } int compute (…) { } Data Analyzer int compute (…)
A COM implementation of the KSpace A ‘Knowledge Space prototype’ by Santhosh CST
Bruce Armstrong TeamSybase
Ni.com Understanding COM/ActiveX Jeff Paulter Staff Software Engineer Thurs Aug 17 10:15-11:30 a.m., 1:45-3:00 p.m. Ash (10A) Jeff Paulter Staff Software.
In the name of Allah The Proxy Pattern Elham moazzen.
Web Services On Devices In Windows Vista Dave Roth Program Manager Windows Device Experience Group Microsoft Corporation.
Implementing COM Objects 主講人:虞台文. Content Types of COM Servers Objects with Single interface – Example  Enumerators Objects with Multiple interfaces.
CS551 - Lecture 15 1 CS551 Object Oriented Middleware (IV) Dynamic Requests (Chap. 6 of EDO) Yugi Lee STB #555 (816)
Presented By:- Sudipta Dhara Roll Table of Content Table of Content 1.Introduction 2.How it evolved 3.Need of Middleware 4.Middleware Basic 5.Categories.
Obsydian Component Model Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
Seminarium on Component-based Software Engineering Feraaz Imami LIACS – Leiden University Fall 2005 Component Object Model (COM)
OLE Automation 主講人:虞台文. Content BSTR  String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL.
CS551 - Lecture 12 1 CS551 Object Oriented Middleware (IV) Dynamic Requests (Chap. 6 of EDO) Yugi Lee STB #555 (816)
DEV394.NET Framework: Migrating To Managed Code Adam Nathan QA Lead Richard Lander Program Manager Microsoft Corporation.
Type Information 主講人:虞台文. Content Overview The Type Library Building Type Library Type Library Deployment Loading and Using a Type Library Objects with.
Functions Functions, locals, parameters, and separate compilation.
.NET Mobile Application Development XML Web Services.
COM Connection Points 主講人:虞台文. Content The Client-Object-Sink Relationship IConnectionPointContainer & IConnectionPoint Implementation using ATL/COM.
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Component Object Model
Component Object Model
Jim Fawcett CSE775 – Distributed Objects Spring 2004
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
Putting the Distributed into COM
Static data members Constructors and Destructors
Microsoft Distributed COM & Microsoft Transaction Server 資四B 張克家
ActiveX Control Recipe
Jim Fawcett CSE791 – Distributed Objects Spring 2001
Native / Managed Interop
Interface Definition Language
Functions, locals, parameters, and separate compilation
Out-of-Process Components
Jim Fawcett CSE775 – Distributed Objects Spring 2007
COM: A Brief Introduction
Jim Fawcett CSE775 – Distributed Objects Spring 2003
COM: A Brief Introduction
CSE 451: Operating Systems Winter 2006 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Interpreter Style Examples
CSE 451: Operating Systems Autumn 2003 Lecture 16 RPC
DCOM-CORBA Comparison
CSE 451: Operating Systems Winter 2007 Module 20 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Method Overloading in JAVA
Bond-Jini Interoperability
CSE 451: Operating Systems Winter 2004 Module 19 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Spring 2012 Module 22 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Autumn 2009 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
Out-of-Process Components
CSE 451: Operating Systems Autumn 2010 Module 21 Remote Procedure Call (RPC) Ed Lazowska Allen Center
CSE 451: Operating Systems Winter 2003 Lecture 16 RPC
Active Template Library
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Jim Fawcett CSE775 – Distributed Objects Spring 2004
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Jim Fawcett CSE775 – Distributed Objects Spring 2007
C# COM Interoperability
Automation and IDispatch
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Jim Fawcett CSE681 – Software Modeling and Analysis Fall 2007
CSE 451: Operating Systems Messaging and Remote Procedure Call (RPC)
Presentation transcript:

C# COM Interoperability Late Binding Vijay Appadurai with small revisions by Jim Fawcett CSE775 – Distributed Objects Spring 2005

Types of Binding There are two kinds of Binding from C# to COM – Early Binding and Late Binding. Early Binding can be done by creating a runtime callable wrapper, which the C# client can use for invoking COM objects. That’s what happens when you make a reference in a C# client to a COM server. Late Binding can be done even without the creation of a runtime callable wrapper. We will see how.

Late Binding Late Binding is done with the help of the C# Reflection APIs. The Type class and the Activator class of the C# Reflection API is used for this purpose. The C# client only needs to know the server’s Program ID for runtime invocation. The following code shows how to accomplish that.

Using C# Reflection for Late Binding //Get IDispatch Interface from the COM Server. Here the Server’s Program ID is “Component.InsideDCOM” Type objType = Type.GetTypeFromProgID(“Component.InsideDCOM”); //Create an instance of the COM object from the type obtained object objSum = Activator.CreateInstance(objType); object c; object[] myArgument = {100,200}; //Invoke a Method on the COM Server which implements IDispatch Interface and get the result c = objType.InvokeMember("Sum", BindingFlags.InvokeMethod, null, objSum, myArgument); //Print the result Console.WriteLine(“Sum of 100 and 200 is “ + c);

Making COM Server Support Late Binding To support Late Binding, the COM Server should implement the IDispatch Interface. This can be done in two ways: THE PURE AUTOMATION INTERFACE Use the dispinterface statement shown here when you are designing a pure automation interface: [uuid(10000001 – 0000 – 0000 – 0000 - 000000000001)] dispinterface ISum { properties: methods: [ id(1)] int Sum(int x, int y); };

Dual Interfaces Using the dispinterface is not recommended since doing so restricts a client to using only the IDispatch interface. Making dual interfaces is preferred. Here’s the IDL syntax required to indicate support for both IDispatch and custom interface. [object, uuid(10000001 – 0000 – 0000 – 0000 -000000000001), dual] interface ISum : IDispatch { [id(1)] HRESULT Sum (int x, int y, [out, retval] int* retval); }

Modifying Outproc3a and 3b to Support Dual Interface Implement all four functions of IDispatch: // IDispatch HRESULT __stdcall GetTypeInfoCount(UINT* pCountTypeInfo); HRESULT __stdcall GetTypeInfo(UINT iTypeInfo, LCID lcid, ITypeInfo** ppITypeInfo); HRESULT __stdcall GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId); HRESULT __stdcall Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);

Modifying Ouproc3a and 3b Modify QueryInterface so that it returns IDispatch* when queried for IID_IDispatch Get Type Information about the ISum interface in the CFactory::CreateInstance function. HRESULT CFactory::CreateInstance(IUnknown *pUnknownOuter, REFIID riid, void **ppv) { … ITypeLib* pTypeLib; LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib) HRESULT hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, m_pTypeInfo); pTypeLib->Release(); }

Using ATL to support Dual Interfaces Its simple. Just choose the Interface as Dual as shown.

References: Inside Distributed COM, Guy Eddon and Henry Eddon, Microsoft Press, 1998