DOCUMENT:Q171559 16-FEB-1999 [mspress] TITLE :Inside COM Corrections and Comments PRODUCT :Microsoft Press PROD/VER: OPER/SYS:WINDOWS KEYWORDS:kbother ====================================================================== ---------------------------------------------------------------------- The information in this article applies to: - Inside COM ---------------------------------------------------------------------- SUMMARY ======= This article contains comments, corrections, and information about known errors relating to the Microsoft Press book "Inside COM," ISBN 1-57231-349- 8. The following topics are covered: - Page 19: Text correction - Page 21: Sidebar Update - Pages 30-33: vtbl Pointers & Instance Data corrections - Page 53: Typo in code - Pages 77-80: (SUCCEEDED)hr)) Should Be (SUCCEEDED(hr)) - Page 92/Figure 5-2: Correction - Page 104: HRESULT has 3 fields - Page 107: Typographical Error - Page 111: Code Sample Change - Pages 122 & 170: Miscellaneous corrections - Page 149: Code change - Page 178: Code error - Pages 178, 217, 219: Miscellaneous corrections - Page 178 & page 290: Code errors - Page 221: Code correction - Pages 257, 261, 280, 307: Miscellaneous corrections - Page 285: Text Incorrect - Miscellaneous typos: pg. 53, 78, 217, 218, 297, 331 MORE INFORMATION ================ Page 19: Text correction ------------------------ Correction: Page 19, paragraph 2: Change: "Inheriting from a pure abstract base class is called interface inheritance..." To: "Inheriting publicly from a pure abstract base class is called interface inheritance..." Page 21: Sidebar Update ----------------------- Page 21, sidebar: Replace sidebar text as follows: [Start replacement] The __stdcall or Pascal Calling Convention You might have noticed the word __stdcall above. __stdcall is a Microsoft-specific extension to the compiler. (You knew there had to be one.) Any compiler that supports the development of Win32 applications will have this or an equivalent option. Compilers from Borland, Symantec, and Watcom have this option. A function marked with __stdcall uses the standard calling convention. Functions using the standard calling convention remove the parameters from the stack before they return to the caller. Pascal functions handle stack clean up the same way. In the normal C/C++ calling convention, the caller cleans up the stack instead of the function. Most other languages, such as Visual Basic, use the standard calling convention by default. The standard calling convention is so named because all Win32 API functions, except the few that take variable arguments, use it. Variable argument functions continue to use the C calling convention, or __cdecl. Windows adopted the standard calling convention because it reduces the size of code and because the original versions of Windows had to run on 640-KB systems. Virtually all functions offered by COM interfaces on Microsoft platforms use the standard calling convention. Functions with variable numbers of arguments use the C calling convention. People will expect you to use those conventions. However, using them is not an absolute requirement of COM. You may use another calling convention, but you should definitely document that fact, and you should be aware that clients written in some other languages might not be able to use your interfaces. If you prefer a word that is easier to remember than __stdcall, use pascal. It is defined in WINDEF.H as #define pascal __stdcall Or if you think putting the word pascal in your code makes you a wimp, you can use the following definition from OBJBASE.H: #define STDMETHODCALLTYPE __stdcall [End text replacement] Note that the footnote remains the same in both the original and updated versions of this sidebar. Pages 30-33: vtbl Pointers & Instance Data corrections ----------------------------------------------------- The following corrections are needed to improve the clarity and accuracy of the section describing vtbl pointers and instance data: Page 30, code fragment changes: - Line 7, change "{cout << m_Fx2 << end1 ;}" to "{cout << m_data1 << end1 ;}" - Line 8, change "{cout << m_Fx3 << end1 ;}" to "{cout << m_data2 << end1 ;}" - Line 9, change "{cout << m_Fx4 << end1 ;}" to "{cout << m_data3 << end1 ;}" - Line 13, change ": m_Fx2(d*d), m_Fx3(d*d*d), m_Fx4(d*d*d*d)" to ": m_data1(d*d), m_data2(d*d*d), m_data3(d*d*d*d)" Page 31, top code fragment changes: - Line 2, change "double m_Fx2 ;" to "double m_data1 ;" - Line 3, change "double m_Fx3 ;" to "double m_data2 ;" - Line 4, change "double m_Fx4 ;" to "double m_data3 ;" Page 31, figure 2-5: - Remove the bottom three arrows between the vtbl pointer box to the Virtual Function Table box. (Be sure to leave the top pointer from vtbl pointer to &Fx1) - In the vtbl pointer box: Change "&m_Fx2" to "m_data1" Change "&m_Fx3" to "m_data2" Change "&m_Fx4" to "m_data3" Page 32, figure 2-6: - In both upper and lower vtbl pointer boxes: Change "&m_Fx2" to "m_data1" Change "&m_Fx3" to "m_data2" Change "&m_Fx4" to "m_data3" Page 33, paragraph 1, sentence 3: Change "I drew the instance data as a dotted box since, " To "I didn't draw the instance data since, " Page 33, figure 2-7: - Remove the bottom three arrows between the top vtbl pointer box to the Virtual Function Table box. (Be sure to leave the top pointer from vtbl pointer to &Fx1) - Remove the bottom three arrows between the bottom vtbl pointer box to the Virtual Function Table box. (Be sure to leave the top pointer from vtbl pointer to &Fx1) - Remove both the upper and lower empty regions below each vtbl pointer box. Each vtbl pointer should look similar to figure 2-4 on page 29. Page 53: Typo in code --------------------- Correction: Page 53, function SameComponents code, line 4: Change: IUnknown pI1 = NULL; IUnknown pI2 = NULL; To: IUnknown* pI1 = NULL; IUnknown* pI2 = NULL; Pages 77-80: (SUCCEEDED)hr)) Should Be (SUCCEEDED(hr)) ------------------------------------------------------ Page 77, 79, 80, code samples: Change: if (SUCCEEDED)hr)) To: if (SUCCEEDED(hr)) Page 92/Figure 5-2: Correction ------------------------------ Correction: Page 92, figure 5-2: Change: GUIDS.CCP To: GUIDS.CPP Page 104: HRESULT has 3 fields ------------------------------ Correction: Page 104, paragraph 4, sentence 6: Change: "An HRESULT is a 32-bit value divided into four different fields." To: "An HRESULT is a 32-bit value divided into three different fields." Page 107: Typographical Error ----------------------------- Page 107, paragraph 1, sentence 1: Change: "...with the order HRESULTS." To: "...with the other HRESULTS." Page 111: Code Sample Change ---------------------------- Page 111, code sample 1: Change code sample to read as follows: MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 512); MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_ITF, 513); Pages 122 & 170: Miscellaneous corrections ------------------------------------------ Correction: Page 122, Figure 6-5: Change value of the CurVer key from: "Helicopter.TailRotor" To: "Helicopter.TailRotor.1" Page 170, first code sample: Change line 14 from: IUnknown* m_pInnerUnknown To: IUnknown* m_pUnknownInner Page 149: Code change --------------------- Correction: Page 149, code line 37: Change: CFactory* pFactory = new CFactory ; // No AddRef in constructor To: CFactory* pFactory = new CFactory ; // Reference count set to 1 in // constructor Page 178: Code error -------------------- Correction: Page 178, sample code: Change: IUnknown* pOuterUnknown = this; To: IUnknown* pUnknownOuter = this; Pages 178, 217, 219: Miscellaneous corrections ---------------------------------------------- Corrections: Page 178, paragraph 3, sentence 1: Change "Notice also that the fourth parameter..." To: "Notice also that the fifth parameter..." Page 217, code fragment, line 4: Change: "CLSID_COMPONENT1" To: "CLSID_Component1" Page 219, code sample 2, line 4: Change: "spIX = pIX ;" To: "spIX = pIX1 ;" Page 178 & page 290: Code errors -------------------------------- Correction: Page 178, code line 9 should read if (FAILED(hr)) Page 290, code line 1 should read typedef struct tagVARIANT { Page 221: Code correction ------------------------- Correction: Page 221, 10th code line: Change: IY *pIY = interface_cast(this); To: IY *pIY = interface_cast(this); Pages 257, 261, 280, 307: Miscellaneous corrections --------------------------------------------------- Corrections: Page 257, paragraph 3, sentence 2: Change: "...in the first parameter, psizeOut." To: "...in the first parameter, psizeInOut." Page 257, paragraph 3, sentence 4: Change: "It then sets psizeOut..." To: "It then sets psizeInOut..." Page 261, paragraph 2: Delete last sentence. Page 280, paragraph 6, sentence 4: Change: "...contains the interface pointer it wants to call?" To: "...contains the function pointer it wants to call?" Page 307, item 5: Change: "...passing it your ICreateErrorInfo interface pointer..." To: "...passing it your IErrorInfo interface pointer..." Page 285: Text Incorrect ------------------------ Page 285, paragraph 4: Change: "when something sounds to good to be true" To: "when something sounds too good to be true" Miscellaneous typos: pg. 53, 78, 217, 218, 297, 331 --------------------------------------------------- Corrections: Page 53, code fragment 2, line 6: Change "QueryInteface" to "QueryInterface" New line should read: HRESULT hr = pIX -> QueryInterface(IID_IX, (void**)&pIX2) ; Page 78, paragraph 2, sentence 3: Change: "If the life of pIX2 were not contained in the life of pIX1..." To: "If the life of pIX2 were not contained in the life of pIX..." Page 217, code fragment: spIX.iid() should have comma after it; code should read as follows: HRESULT HR = ::CoCreateInstance(CLSID_Component1, NULL, CLSCTX_ALL, spIX.iid(), (void**)&spIX) ; Page 218, code fragment 1: Missing parenthesis; code should read as follows: return CoCreateInstance(clsid, pI, clsctx, *piid, (void**)&m_pI) ; Page 218, code fragement 2: Missing comma and parenthesis; code should read: HRESULT hr = spIX.CreateInstance(CLSID_Component1, NULL, CLSCTX_INPROC_SERVER) ; Page 297, paragraph 1, sentence 1: Change: "A method in a dispinterface can also can have..." To: "A method in a dispinterface can also have..." Page 331, paragraph 1, sentence 1: Change: "...queries the component it creates for a its IX interface..." To: "...queries the component it creates for its IX interface..." Microsoft Press is committed to providing informative and accurate books. All comments and corrections listed above are ready for inclusion in future printings of this book. If you have a later printing of this book, it may already contain most or all of the above corrections. Additional query words: mspress ms_press press bookbug com automation ====================================================================== Keywords : kbother Platform : WINDOWS ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 1999.