ole automation 主講人:虞台文. content bstr string data type in ole variant & variantarg...
DESCRIPTION
OLE Automation BSTR String data type in OLETRANSCRIPT
![Page 1: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/1.jpg)
OLE Automation
主講人:虞台文
![Page 2: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/2.jpg)
Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL
![Page 3: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/3.jpg)
OLE Automation
BSTR String data type in OLE
![Page 4: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/4.jpg)
BSTR A BSTR is a Basic STRing 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
![Page 5: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/5.jpg)
BSTR APIs
String Manipulation Functions
Descriptions
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.
![Page 6: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/6.jpg)
BSTR in MFC
BSTR CString::AllocSysString ( ) const;
throw( CMemoryException );
BSTR CString::SetSysString ( BSTR* pbstr ) const;
![Page 7: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/7.jpg)
OLE AutomationVARIANT
&VARIANTARG
![Page 9: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/9.jpg)
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 };};
![Page 10: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/10.jpg)
The VARIANT System Functions
Variant Manipulation Functions Descriptions
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.
![Page 11: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/11.jpg)
Data Type Conversion APIs
HRESULT VariantChangeType( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, unsigned short wFlags, VARTYPE vt );
HRESULT VariantChangeTypeEx( VARIANTARG *pvargDest, VARIANTARG *pvarSrc, LCID lcid, unsigned short wFlags, VARTYPE vt);
![Page 12: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/12.jpg)
Data Type Conversion APIs
![Page 13: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/13.jpg)
VARIANT in MFCCOleVariant::COleVariantCOleVariant( );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 );
![Page 14: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/14.jpg)
OLE Automation
IDispatch
![Page 15: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/15.jpg)
IDispatchinterface 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;};
![Page 16: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/16.jpg)
Creation of Dispatch API Functions
Functions DescriptionCreateDispTypeInfo 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.
![Page 17: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/17.jpg)
OLE Automation
Create COM Objects Using ATL
![Page 18: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/18.jpg)
Step 1: Running the ATL COM Wizard
![Page 19: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/19.jpg)
Step 1: Running the ATL COM Wizard
![Page 20: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/20.jpg)
Step 1: Running the ATL COM Wizard
![Page 21: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/21.jpg)
Step 1: Running the ATL COM Wizard
Practice and view the files generated by the wizard.
![Page 22: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/22.jpg)
Step 2: Creating a new ATL object
![Page 23: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/23.jpg)
Step 2: Creating a new ATL object
![Page 24: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/24.jpg)
Step 2: Creating a new ATL object
![Page 25: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/25.jpg)
Step 2: Creating a new ATL object
![Page 26: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/26.jpg)
Step 2: Creating a new ATL object
![Page 27: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/27.jpg)
Step 2: Creating a new ATL object
Practice and view the files generated by the wizard.
![Page 28: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/28.jpg)
Step 3: Adding a method
![Page 29: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/29.jpg)
Step 3: Adding a method
![Page 30: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/30.jpg)
Step 3: Adding a method
![Page 31: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/31.jpg)
Step 3: Adding a method
![Page 32: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/32.jpg)
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;}
![Page 33: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/33.jpg)
Step 4: Compiling the DLL
![Page 34: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/34.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 35: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/35.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 36: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/36.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 37: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/37.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 38: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/38.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 39: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/39.jpg)
Step 5: Testing the COM Server with Visual Basic
![Page 40: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/40.jpg)
Step 6: Testing the COM Server with Visual C++
View Source Code
![Page 41: OLE Automation 主講人:虞台文. Content BSTR String data type in OLE VARIANT & VARIANTARG IDispatch Create COM Objects Using ATL](https://reader036.vdocuments.site/reader036/viewer/2022081422/5a4d1b037f8b9ab059987935/html5/thumbnails/41.jpg)
Exercises
1. Implement inprocess sever of CalculatorMemory via ATL.
2. Implement CalculatorMemory’s clients using VB and VC.