home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / OLE.ZIP / OLECLNTE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  6.5 KB  |  158 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2. //
  3. // oleclnte.cpp
  4.  
  5. // see comments in oleclnte.h for a description of classes.
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <process.h>
  10. #include <ole.h>
  11. #pragma hdrstop
  12.  
  13. #include "oleclnte.h"
  14.  
  15. LPSTR TOleStatusTrans::Default() { return "Not a Status Message"; }
  16. LPSTR TOleStatusTrans::Ok() { return "OLE_OK"; }
  17. LPSTR TOleStatusTrans::WaitForRelease() { return "OLE_WAIT_FOR_RELEASE"; }
  18. LPSTR TOleStatusTrans::Busy() { return "OLE_BUSY"; }
  19. LPSTR TOleStatusTrans::ErrorProtectOnly() { return "OLE_ERROR_PROTECT_ONLY"; }
  20. LPSTR TOleStatusTrans::ErrorMemory() { return "OLE_ERROR_MEMORY"; }
  21. LPSTR TOleStatusTrans::ErrorStream() { return "OLE_ERROR_STREAM"; }
  22. LPSTR TOleStatusTrans::ErrorStatic() { return "OLE_ERROR_STATIC"; }
  23. LPSTR TOleStatusTrans::ErrorBlank()   { return "OLE_ERROR_BLANK"; }
  24. LPSTR TOleStatusTrans::ErrorDraw()    { return "OLE_ERROR_DRAW"; }
  25. LPSTR TOleStatusTrans::ErrorMetafile() { return "OLE_ERROR_METAFILE"; }
  26. LPSTR TOleStatusTrans::ErrorAbort()   { return "OLE_ERROR_ABORT"; }
  27. LPSTR TOleStatusTrans::ErrorClipboard() { return "OLE_ERROR_CLIPBOARD"; }
  28. LPSTR TOleStatusTrans::ErrorFormat()  { return "OLE_ERROR_FORMAT"; }
  29. LPSTR TOleStatusTrans::ErrorObject() { return "OLE_ERROR_OBJECT"; }
  30. LPSTR TOleStatusTrans::ErrorOption() { return "OLE_ERROR_OPTION"; }
  31. LPSTR TOleStatusTrans::ErrorProtocal() { return "OLE_ERROR_PROTOCOL"; }
  32. LPSTR TOleStatusTrans::ErrorAddress() { return "OLE_ERROR_ADDRESS"; }
  33. LPSTR TOleStatusTrans::ErrorNotEqual() { return "OLE_ERROR_NOT_EQUAL"; }
  34. LPSTR TOleStatusTrans::ErrorHandle()    { return "OLE_ERROR_HANDLE"; }
  35. LPSTR TOleStatusTrans::ErrorGeneric() { return "OLE_ERROR_GENERIC"; }
  36. LPSTR TOleStatusTrans::ErrorClass()    { return "OLE_ERROR_CLASS"; }
  37. LPSTR TOleStatusTrans::ErrorSyntax() { return "OLE_ERROR_SYNTAX"; }
  38. LPSTR TOleStatusTrans::ErrorDataType() { return "OLE_ERROR_DATATYPE"; }
  39. LPSTR TOleStatusTrans::ErrorPalette() { return "OLE_ERROR_PALETTE"; }
  40. LPSTR TOleStatusTrans::ErrorNotLink() { return "OLE_ERROR_NOT_LINK"; }
  41. LPSTR TOleStatusTrans::ErrorNotEmpty() { return "OLE_ERROR_NOT_EMPTY"; }
  42. LPSTR TOleStatusTrans::ErrorSize() { return "OLE_ERROR_SIZE"; }
  43. LPSTR TOleStatusTrans::ErrorDrive() { return "OLE_ERROR_DRIVE"; }
  44. LPSTR TOleStatusTrans::ErrorNetwork() { return "OLE_ERROR_NETWORK"; }
  45. LPSTR TOleStatusTrans::ErrorName() { return "OLE_ERROR_NAME"; }
  46. LPSTR TOleStatusTrans::ErrorTemplate() { return "OLE_ERROR_TEMPLATE"; }
  47. LPSTR TOleStatusTrans::ErrorNew() { return "OLE_ERROR_NEW"; }
  48. LPSTR TOleStatusTrans::ErrorEdt() { return "OLE_ERROR_EDIT"; }
  49. LPSTR TOleStatusTrans::ErrorOpen() { return "OLE_ERROR_OPEN"; }
  50. LPSTR TOleStatusTrans::ErrorNotOpen() { return "OLE_ERROR_NOT_OPEN"; }
  51. LPSTR TOleStatusTrans::ErrorLaunch() { return "OLE_ERROR_LAUNCH"; }
  52. LPSTR TOleStatusTrans::ErrorComm() { return "OLE_ERROR_COMM"; }
  53. LPSTR TOleStatusTrans::ErrorTerminate() { return "OLE_ERROR_TERMINATE"; }
  54. LPSTR TOleStatusTrans::ErrorCommand() { return "OLE_ERROR_COMMAND"; }
  55. LPSTR TOleStatusTrans::ErrorShow() { return "OLE_ERROR_SHOW"; }
  56. LPSTR TOleStatusTrans::ErrorDoverb() { return "OLE_ERROR_DOVERB"; }
  57. LPSTR TOleStatusTrans::ErrorAdviseNatvie() { return "OLE_ERROR_ADVISE_NATIVE"; }
  58. LPSTR TOleStatusTrans::ErrorAdvisePict() { return "OLE_ERROR_ADVISE_PICT"; }
  59. LPSTR TOleStatusTrans::ErrorAdviseRename() { return "OLE_ERROR_ADVISE_RENAME"; }
  60. LPSTR TOleStatusTrans::ErrorPokeNative() { return "OLE_ERROR_POKE_NATIVE"; }
  61. LPSTR TOleStatusTrans::ErrorRequestNative() { return "OLE_ERROR_REQUEST_NATIVE"; }
  62. LPSTR TOleStatusTrans::ErrorRequestPict() { return "OLE_ERROR_REQUEST_PICT"; }
  63. LPSTR TOleStatusTrans::ErrorServerBlocked() { return "OLE_ERROR_SERVER_BLOCKED"; }
  64. LPSTR TOleStatusTrans::ErrorRegistration() { return "OLE_ERROR_REGISTRATION"; }
  65. LPSTR TOleStatusTrans::ErrorAlreadyRegistered() { return "OLE_ERROR_ALREADY_REGISTERED"; }
  66. LPSTR TOleStatusTrans::ErrorTask() { return "OLE_ERROR_TASK"; }
  67. LPSTR TOleStatusTrans::ErrorOutOfDate() { return "OLE_ERROR_OUTOFDATE"; }
  68. LPSTR TOleStatusTrans::ErrorCantUpdateClient() { return "OLE_ERROR_CANT_UPDATE_CLIENT"; }
  69. LPSTR TOleStatusTrans::ErrorUpdate() { return "OLE_ERROR_UPDATE"; }
  70. LPSTR TOleStatusTrans::ErrorSetdataFormat() { return "OLE_ERROR_SETDATA_FORMAT"; }
  71. LPSTR TOleStatusTrans::ErrorStaticFromOtherOs() { return "OLE_ERROR_STATIC_FROM_OTHER_OS"; }
  72. LPSTR TOleStatusTrans::WarnDeleteData() { return "OLE_WARN_DELETE_DATA"; }
  73.  
  74. typedef LPSTR ( TOleStatusTrans::*ConFP )();
  75. typedef LPSTR ( *FP)();
  76.  
  77. /* _DDVTdispathNULL is a function in the RTL.  There are two versions,
  78. one for far vtables, one for near.  They both return a pointer to a
  79. pointer to the address of the DDVT function, or NULL if one is not found.
  80. */
  81.  
  82. #ifdef FARVTBL
  83.  
  84. #define GetVptr(thisPtr)    (*(void far **)(thisPtr))
  85. FP far * _DDVTdispatchNULL(void far *, int);
  86.  
  87. #else
  88.  
  89. #define GetVptr( thisPtr)   (*(void near **)(thisPtr))
  90. FP far * _DDVTdispatchNULL(void near *, int);
  91.  
  92. #endif
  93.  
  94.  
  95. LPSTR TOleStatusTrans::Trans( OLESTATUS x )
  96. {
  97.     ConFP theDDVTfoo;              // final location for DDVT foo
  98.     union {
  99.         FP    fp;                   // since the RTL returns a basic
  100.         ConFP memberFP;             // function pointer address, we
  101.     } temp;                         // use a union to transform to
  102.                     // member function pointer.
  103.  
  104.     FP fp = *_DDVTdispatchNULL( GetVptr( this ) , x );
  105.     if ( fp )
  106.     {
  107.         temp.fp = fp;
  108.         theDDVTfoo = temp.memberFP;
  109.     }
  110.     else theDDVTfoo = &TOleStatusTrans::Default;
  111.  
  112.     return (this->*theDDVTfoo)();
  113. }
  114.  
  115.  
  116.  
  117. void CheckOleError( OLESTATUS x , unsigned  line , char * file )
  118. // If the message is not OleOk, it gets it translated into the
  119. // appropiate string and pops up a message box giving the file
  120. // and line number.  If The user says no, it exits.
  121. //
  122. {
  123.     static TOleStatusTrans OleStatusTrans;
  124.  
  125.     if ( x != OLE_OK ) {
  126.         char cap[80];
  127.         char mes[80];
  128.         sprintf( mes , "%s ( %d )  Ok to Proceed?" , OleStatusTrans.Trans( x ) , x );
  129.         sprintf( cap , "OleError - File: %s  Line: %d", file, line );
  130.         if ( IDNO == MessageBox( GetFocus() ,
  131.              mes ,
  132.              cap ,
  133.              MB_YESNO ) )
  134.         {
  135.             exit( x );
  136.         }
  137.     }
  138. }
  139.  
  140. void WaitOleNotBusy( OLESTATUS oleStatus, LPOLEOBJECT lpObject ,
  141.             unsigned line, char * file )
  142. {
  143.     MSG msg;
  144.     if ( oleStatus == OLE_WAIT_FOR_RELEASE )
  145.     {
  146.         while ( ( oleStatus = OleQueryReleaseStatus( lpObject )) == OLE_BUSY )
  147.         {
  148.             if ( GetMessage( &msg , NULL, NULL, NULL ))
  149.             {
  150.                 TranslateMessage( &msg );
  151.                 DispatchMessage(  &msg );
  152.             }
  153.         }
  154.         if ( oleStatus == OLE_OK || oleStatus == OLE_ERROR_OBJECT ) return;
  155.     }
  156.     CheckOleError( oleStatus, line, file );
  157. }
  158.