OLE Automation 主講人:虞台文. Content BSTR  String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL.

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

Chapter6 LISTS AND STRINGS. Outline 1. List Specifications 2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked.
Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Things to Remember When Developing 64-bit Software OOO "Program Verification Systems"
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Elementary Data Structures: Part 2: Strings, 2D Arrays, Graphs
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.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
1 Java Object Model Part 1. 2 Type Definition: set of values – a set of values and set of operations –a set of operations that can be applied to those.
Starting out with C++1 Chapter 9 – Pointers Getting the address of a Variable Why do we have pointers? Indirection – difference between –Will you go out.
Data Types.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
Obsydian OLE Automation Ranjit Sahota Chief Architect Obsydian Development Ranjit Sahota Chief Architect Obsydian Development.
Variable, Expressions, Statements and Operators By: Engr. Faisal ur Rehman CE-105 Fall 2007.
POINTERS. 1.a) POINTER EXPRESSIONS Pointer variables can be used in expression If p1 and p2 are properly declared and initialized pointers then following.
Announcements  I will discuss the labtest and the written test #2 common mistakes, solution, etc. in the next class  not today as I am still waiting.
C Tokens Identifiers Keywords Constants Operators Special symbols.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
COM and DCOM CS 562 February 27, Motivation Data Analyzer Resource Monitor int compute (…) { } int compute (…) { } Data Analyzer int compute (…)
1 Homework HW6 due class 22 K&R 6.6 K&R 5.7 – 5.9 (skipped earlier) Finishing up K&R Chapter 6.
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.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
CISC105 – General Computer Science Class 9 – 07/03/2006.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Implementing COM Objects 主講人:虞台文. Content Types of COM Servers Objects with Single interface – Example  Enumerators Objects with Multiple interfaces.
ECE 103 Engineering Programming Chapter 47 Dynamic Memory Alocation Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Mixing integer and floating point numbers in an arithmetic operation.
CS551 - Lecture 15 1 CS551 Object Oriented Middleware (IV) Dynamic Requests (Chap. 6 of EDO) Yugi Lee STB #555 (816)
Homework Finishing up K&R Chapter 6 today Also, K&R 5.7 – 5.9 (skipped earlier)
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
Chapter 6 LISTS AND STRINGS 1. List Definition 2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Doubly Linked 3. Linked.
Microsoft Windows Script Interfaces-Introduction 主講人:虞台文.
Sahar Mosleh California State University San MarcosPage 1 Character String.
CS551 - Lecture 12 1 CS551 Object Oriented Middleware (IV) Dynamic Requests (Chap. 6 of EDO) Yugi Lee STB #555 (816)
Type Information 主講人:虞台文. Content Overview The Type Library Building Type Library Type Library Deployment Loading and Using a Type Library Objects with.
Characters and Strings
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
COM Connection Points 主講人:虞台文. Content The Client-Object-Sink Relationship IConnectionPointContainer & IConnectionPoint Implementation using ATL/COM.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Object Oriented Programming Lecture 2: BallWorld.
Java Programming Language Lecture27- An Introduction.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
The C++ Data Types Fundamental Data Types
Interface Definition Language
Interface Definition Language
C# COM Interoperability Late Binding
DATA HANDLING.
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
An Introduction to Java – Part I, language basics
Programming Language C Language.
Active Template Library
Automation and IDispatch
Variables and Constants
Presentation transcript:

OLE Automation 主講人:虞台文

Content BSTR  String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL

OLE Automation BSTR  String data type in OLE

BSTR A BSTR is a B asic STR ing in which the string is stored as a DWORD count of characters followed by the characters themselves char count characters \0 Number of bytes equal to the count LPTSTR psz

BSTR APIs String Manipulation FunctionsDescriptions SysAllocString Creates and initializes a string. SysAllocStringByteLen Creates a zero-terminated string of a specified length (32-bit only). SysAllocStringLen Creates a string of a specified length. SysFreeString Frees a previously created string. SysReAllocString Changes the size and value of a string. SysReAllocStringLen Changes the size of an existing string. SysStringByteLen Returns the length of a string in bytes (32-bit only). SysStringLen Returns the length of a string.

BSTR in MFC BSTR CString::AllocSysString ( ) const; throw( CMemoryException ); BSTR CString::AllocSysString ( ) const; throw( CMemoryException ); BSTR CString::SetSysString ( BSTR* pbstr ) const;

OLE Automation VARIANT & VARIANTARG

VARIANT

VARIANT & VARIANTARG struct tagVARIANT { VARTYPE vt; WORD wReserved1; WORD wReserved2; WORD wReserved3; union { // C++ Type Union Name Type Tag Basic Type // long lVal; // VT_I4 ByVal Long unsigned char bVal; // VT_UI1 ByVal Byte short iVal; // VT_I2 ByVal Integer float fltVal; // VT_R4 ByVal Single double dblVal; // VT_R8 ByVal Double VARIANT_BOOL boolVal; // VT_BOOL ByVal Boolean SCODE scode; // VT_ERROR CY cyVal; // VT_CY ByVal Currency DATE date; // VT_DATE ByVal Date BSTR bstrVal; // VT_BSTR ByVal String IUnknown *punkVal; // VT_UNKNOWN IDispatch *pdispVal; // VT_DISPATCH ByVal Object SAFEARRAY *parray; // VT_ARRAY|* ByVal array // A bunch of other types that don't matter here... VARIANT *pvarVal; // VT_BYREF|VT_VARIANT ByRef Variant void * byref; // Generic ByRef }; struct tagVARIANT { VARTYPE vt; WORD wReserved1; WORD wReserved2; WORD wReserved3; union { // C++ Type Union Name Type Tag Basic Type // long lVal; // VT_I4 ByVal Long unsigned char bVal; // VT_UI1 ByVal Byte short iVal; // VT_I2 ByVal Integer float fltVal; // VT_R4 ByVal Single double dblVal; // VT_R8 ByVal Double VARIANT_BOOL boolVal; // VT_BOOL ByVal Boolean SCODE scode; // VT_ERROR CY cyVal; // VT_CY ByVal Currency DATE date; // VT_DATE ByVal Date BSTR bstrVal; // VT_BSTR ByVal String IUnknown *punkVal; // VT_UNKNOWN IDispatch *pdispVal; // VT_DISPATCH ByVal Object SAFEARRAY *parray; // VT_ARRAY|* ByVal array // A bunch of other types that don't matter here... VARIANT *pvarVal; // VT_BYREF|VT_VARIANT ByRef Variant void * byref; // Generic ByRef };

The VARIANT System Functions Variant Manipulation FunctionsDescriptions VariantChangeType Converts a variant to another type. VariantChangeTypeEx Converts a variant to another type, using a locale identifier (LCID). VariantClear Releases resources and sets a variant to VT_EMPTY. VariantCopy Copies a variant. VariantCopyInd Copies variants that may contain a pointer. VariantInit Initializes a variant.

Data Type Conversion APIs HRESULT VariantChangeType( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, unsigned short wFlags, VARTYPE vt ); HRESULT VariantChangeType( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, unsigned short wFlags, VARTYPE vt ); HRESULT VariantChangeTypeEx( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, LCID lcid, unsigned short wFlags, VARTYPE vt ); HRESULT VariantChangeTypeEx( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, LCID lcid, unsigned short wFlags, VARTYPE vt );

Data Type Conversion APIs

VARIANT in MFC COleVariant::COleVariant COleVariant( ); COleVariant( const VARIANT& varSrc ); COleVariant( const COleVariant& varSrc ); COleVariant( LPCVARIANT pSrc ); COleVariant( LPCTSTR lpszSrc ); COleVariant( LPCTSTR lpszSrc, VARTYPE vtSrc ); COleVariant( CString& strSrc ); COleVariant( BYTE nSrc ); COleVariant( short nSrc, VARTYPE vtSrc = VT_I2 ); COleVariant( long lSrc, VARTYPE vtSrc = VT_I4 ); COleVariant( const COleCurrency& curSrc ); COleVariant( float fltSrc ); COleVariant( double dblSrc ); COleVariant( const COleDateTime& dateSrc ); COleVariant( const CByteArray& arrSrc ); COleVariant( const CLongBinary& lbSrc ); COleVariant::COleVariant COleVariant( ); COleVariant( const VARIANT& varSrc ); COleVariant( const COleVariant& varSrc ); COleVariant( LPCVARIANT pSrc ); COleVariant( LPCTSTR lpszSrc ); COleVariant( LPCTSTR lpszSrc, VARTYPE vtSrc ); COleVariant( CString& strSrc ); COleVariant( BYTE nSrc ); COleVariant( short nSrc, VARTYPE vtSrc = VT_I2 ); COleVariant( long lSrc, VARTYPE vtSrc = VT_I4 ); COleVariant( const COleCurrency& curSrc ); COleVariant( float fltSrc ); COleVariant( double dblSrc ); COleVariant( const COleDateTime& dateSrc ); COleVariant( const CByteArray& arrSrc ); COleVariant( const CLongBinary& lbSrc );

OLE Automation IDispatch

interface IDispatch : public IUnknown { virtual ULONG GetTypeInfoCount(unsigned int FAR* pctinfo) = 0; virtual HRESULT GetTypeInfo(unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo ) = 0; virtual ULONG GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgDispId ) = 0; virtual ULONG Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr ) = 0; }; interface IDispatch : public IUnknown { virtual ULONG GetTypeInfoCount(unsigned int FAR* pctinfo) = 0; virtual HRESULT GetTypeInfo(unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo ) = 0; virtual ULONG GetIDsOfNames(REFIID riid, OLECHAR FAR* FAR* rgszNames, unsigned int cNames, LCID lcid, DISPID FAR* rgDispId ) = 0; virtual ULONG Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pDispParams, VARIANT FAR* pVarResult, EXCEPINFO FAR* pExcepInfo, unsigned int FAR* puArgErr ) = 0; };

Creation of Dispatch API Functions FunctionsDescription CreateDispTypeInfo Creates simplified type information for an object. CreateStdDispatch Creates a standard IDispatch implementation for an object. DispGetIDsOfNames Converts a set of names to DISPIDs. DispGetParam Retrieves and coerces elements from a DISPPARAMS structure. DispInvoke Calls a member function of an IDispatch interface.

OLE Automation Create COM Objects Using ATL

Step 1: Running the ATL COM Wizard

Practice and view the files generated by the wizard.

Step 2: Creating a new ATL object

Practice and view the files generated by the wizard.

Step 3: Adding a method

STDMETHODIMP CFirst_ATL::AddNumbers(long Num1, long Num2, long *ReturnVal) { // TODO: Add your implementation code here *ReturnVal = Num1 + Num2; return S_OK; } STDMETHODIMP CFirst_ATL::AddNumbers(long Num1, long Num2, long *ReturnVal) { // TODO: Add your implementation code here *ReturnVal = Num1 + Num2; return S_OK; }

Step 4: Compiling the DLL

Step 5: Testing the COM Server with Visual Basic

Step 6: Testing the COM Server with Visual C++ View Source Code

Exercises 1. Implement inprocess sever of CalculatorMemory via ATL. 2. Implement CalculatorMemory ’s clients using VB and VC.