SLIDE 6 6 COM IDL - C++ Mapping
#i #include nclude “dd.h “dd.h” #i #include nclude “dd.h “dd.h” ex extern c tern const I
ID ex extern c tern const I
ID IID_ IID_ICalcu ICalculator lator IID_ IID_ICalcu ICalculator lator; ; st struct ruct st struct ruct __ __declsp declspec(uui ec(uuid(“DEFA d(“DEFACED1 CED1 __ __declsp declspec(uui ec(uuid(“DEFA d(“DEFACED1 CED1-
229 0229 229-
2552 52 25 2552 52-
1D11 1D11 1D11-
ABBADABBAD0 ABBAD00”)) 0”)) ABBAD ABBADABBAD0 ABBAD00”)) 0”)) IC ICalcula alculator tor IC ICalcula alculator tor : public : public : public : public IDeskt IDesktopDevi
ce IDeskt IDesktopDevi
ce { { virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Cle YPE Clear(voi ar(void) = 0 d) = 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Cle YPE Clear(voi ar(void) = 0 d) = 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Add YPE Add(short (short n) = n) = 0; 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE Add YPE Add(short (short n) = n) = 0; 0; virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE YPE virtu virtual HRE al HRESULT ST SULT STDMETHO DMETHODCALLT DCALLTYPE YPE Get GetSum(sh Sum(short
Get GetSum(sh Sum(short
*pn pn pn pn) = 0; ) = 0; ) = 0; ) = 0; }; }; }; }; ex extern c tern const G
UID ex extern c tern const G
UID LIB LIBID_Cal ID_CalcTypes cTypes LIB LIBID_Cal ID_CalcTypes cTypes; ; co const II nst IID D co const II nst IID D IID_ IID_ICalcul ICalculator ator IID_ IID_ICalcul ICalculator ator = {0xDE {0xDEFACED1, FACED1, 0x022 0x0229, 0x2 9, 0x2552, 552, = {0xDE {0xDEFACED1, FACED1, 0x022 0x0229, 0x2 9, 0x2552, 552, { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; co const GU nst GUID ID co const GU nst GUID ID LIB LIBID_Calc ID_CalcTypes Types LIB LIBID_Calc ID_CalcTypes Types = {0xD = {0xDEFACED2 EFACED2, 0x02 , 0x0229, 0x 29, 0x2552, 2552, = {0xD = {0xDEFACED2 EFACED2, 0x02 , 0x0229, 0x 29, 0x2552, 2552, { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; }; { 0x1D, 0x1D, 0x11, 0x11, 0xAB, 0xAB, 0xBA, 0xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00 } x00 } }; };
CalcTypes.h CalcTypes.h CalcTypes_i.c CalcTypes_i.c
COM IDL – Java/VB Mapping
pa package ckage pa package ckage CalcTy CalcTypes pes CalcTy CalcTypes pes; // ; // libra library nam ry name ; // ; // libra library nam ry name /* /**@ *@ /* /**@ *@com. com.interf interface(iid ace(iid com. com.interf interface(iid ace(iid=DEFAC =DEFACED1 ED1 =DEFAC =DEFACED1 ED1-
0229 29 02 0229 29-
2552 2552 2552-
1D11 1D11 1D11-
ABBADABBAD00) BBAD00)*/ */ ABBADA ABBADABBAD00) BBAD00)*/ */ in interfac terface e in interfac terface e ICal ICalculator culator ICal ICalculator culator exten extends ds exten extends ds IDe IDesktopDe sktopDevice vice IDe IDesktopDe sktopDevice vice { { publ public voi ic void Clear d Clear( ); ( ); publ public voi ic void Clear d Clear( ); ( ); publ public voi ic void Add(s d Add(short n hort n); publ public voi ic void Add(s d Add(short n hort n); publ public voi ic void d publ public voi ic void d GetSu GetSum(shor m(short GetSu GetSum(shor m(short [] [] [] [] pn pn pn pn); // ); // array array of len
gth 1 ); // ); // array array of len
gth 1 publ public sta ic static tic publ public sta ic static tic com com.ms.co .ms.com._Gui m._Guid com com.ms.co .ms.com._Gui m._Guid iid iid iid iid = = ne new com. w com.ms.com. ms.com._Guid( _Guid(0xDEFA 0xDEFACED1, 0 CED1, 0x0229, x0229, 0x255 0x2552, 2, ne new com. w com.ms.com. ms.com._Guid( _Guid(0xDEFA 0xDEFACED1, 0 CED1, 0x0229, x0229, 0x255 0x2552, 2, 0x1D, 0x1D, 0x11, 0 0x11, 0xAB, 0 xAB, 0xBA, xBA, 0x1D, 0x1D, 0x11, 0 0x11, 0xAB, 0 xAB, 0xBA, xBA, 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00); x00); 0xDA, 0xDA, 0xBB, 0 0xBB, 0xAD, 0 xAD, 0x00); x00); } }
CalcTypes.java CalcTypes.java
Pu Public S blic Sub Cle ub Clear( ) ar( ) Pu Public S blic Sub Cle ub Clear( ) ar( ) Pu Public S blic Sub ub Pu Public S blic Sub ub Add Add(ByVal (ByVal Add Add(ByVal (ByVal n As I n As Integer nteger) n As I n As Integer nteger) Pu Public S blic Sub ub Pu Public S blic Sub ub Get GetSum(ByR Sum(ByRef ef Get GetSum(ByR Sum(ByRef ef pn pn pn pn As Int As Integer) eger) As Int As Integer) eger)
CalcTypes.cls CalcTypes.cls particular value particular value res res
Severity (31) Severity (31) Facility (27 Facility (27-
16) Code (15 Code (15-
0) 0 -
> Success 1 1 -
> Failure FACILITY_NULL FACILITY_NULL FACILITY_ITF FACILITY_ITF FACILITY_STORAGE FACILITY_STORAGE FACILITY_DISPATCH FACILITY_DISPATCH FACILITY_WINDOWS FACILITY_WINDOWS FACILITY_RPC FACILITY_RPC
COM And Error Handling
COM (today) doesn’t support typed C++ or Java-style exceptions All (remotable) methods must return a standard 32-bit error code called an HRESULT
- Mapped to exception in higher-level languages
- Overloaded to indicate invocation errors from proxies
small small long long hyper hyper IDL IDL C++ C++ Java Java short short char char long long __int64 __int64 byte byte int int long long short short short short Visual Basic Visual Basic N/A N/A Long Long N/A N/A Integer Integer unsigned small unsigned small unsigned long unsigned long unsigned hyper unsigned hyper unsigned short unsigned short unsigned char unsigned char unsigned long unsigned long unsigned __int64 unsigned __int64 byte byte int int long long unsigned short unsigned short short short Byte Byte N/A N/A N/A N/A N/A N/A float float double double float float double double float float double double Single Single Double Double char char unsigned char unsigned char char char unsigned char unsigned char char char byte byte N/A N/A Byte Byte wchar_t wchar_t wchar_t wchar_t char char Integer Integer Script Script No No Yes Yes No No Yes Yes No No No No No No No No Yes Yes Yes Yes No No Yes Yes No No
COM Data Types
byte byte boolean boolean VARIANT_BOOL VARIANT_BOOL IDL IDL C++ C++ Java Java BYTE BYTE unsigned char unsigned char long long VARIANT_BOOL VARIANT_BOOL char char int int boolean boolean unsigned char unsigned char byte byte Visual Basic Visual Basic N/A N/A Long Long Boolean Boolean Byte Byte BSTR BSTR VARIANT VARIANT BSTR BSTR java.lang.String java.lang.String VARIANT VARIANT com.ms.com.Variant com.ms.com.Variant String String Variant Variant CY CY long long int int Currency Currency DATE DATE enum enum double double double double enum enum int int Date Date Enum Enum Typed Typed ObjRef ObjRef IFoo IFoo * * interface interface IFoo IFoo IFoo IFoo struct struct struct struct final class final class Type Type union union C C-
style Array union union N/A N/A array array array array N/A N/A N/A N/A Script Script No No No No Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes No No No No No No
COM Data Types Reference counting
Leverage indirection through reference object
- Clients “Delete” each reference, not each object
Object checks references to it
- Objects track number of references and auto-delete
when count reaches zero
- Requires 100% compliance with ref. counting rules
Client obligations
- All operations that return interface pointers must
increment the interface pointer’s reference count
- Clients must inform object that a particular interface
pointer has been destroyed