OLEVTBL.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:9k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * OLEVTBL.C
  3.  *
  4.  * Creates or frees the procedure instances for the server, document,
  5.  * and object VTBLs.  There are two functions for each table:  one
  6.  * to initialize the table, the other to free the instances in the table.
  7.  *
  8.  * Copyright(c) Microsoft Corp. 1992-1994 All Rights Reserved
  9.  * Win32 version, January 1994
  10.  */
  11. #ifdef MAKEOLESERVER
  12. #include <windows.h>
  13. #include <ole.h>
  14. #include "cosmo.h"
  15. #include "oleglobl.h"
  16. #ifdef MSC
  17. /*
  18.  * This disables Microsoft VC++ 1.x warnings we get from assigning
  19.  * functions with our app-specific prototypes to the fixed prototypes
  20.  * in the VTBL structures.  The functionality of this application was
  21.  * verified before adding this pragma.
  22.  */
  23. #pragma warning(disable:4028)
  24. #ifndef WIN32
  25. #pragma warning(disable:4113)
  26. #endif
  27. #endif
  28. /*
  29.  * FOLEVtblInitServer
  30.  *
  31.  * Purpose:
  32.  *  Creates procedure instances for all the OLE methods required
  33.  *  by the server library for standard server methods.
  34.  *
  35.  * Parameters:
  36.  *  hInst           HINSTANCE of the application instance.
  37.  *  pvt             LPOLESERVERVTBL to the VTBL to initialize.
  38.  *
  39.  * Return Value:
  40.  *  None
  41.  *
  42.  * Customization:
  43.  *  None required.
  44.  */
  45. BOOL WINAPI FOLEVtblInitServer(HINSTANCE hInst, LPOLESERVERVTBL pvt)
  46.     {
  47.     BOOL        fRet=TRUE;
  48.    #ifdef WIN32
  49.     pvt->Create            =ServerCreate;
  50.     pvt->CreateFromTemplate=ServerCreateFromTemplate;
  51.     pvt->Edit              =ServerEdit;
  52.     pvt->Execute           =ServerExecute;
  53.     pvt->Exit              =ServerExit;
  54.     pvt->Open              =ServerOpen;
  55.     pvt->Release           =ServerRelease;
  56.    #else
  57.     pvt->Create            =(LPVOID)MakeProcInstance(ServerCreate,             hInst);
  58.     pvt->CreateFromTemplate=(LPVOID)MakeProcInstance(ServerCreateFromTemplate, hInst);
  59.     pvt->Edit              =(LPVOID)MakeProcInstance(ServerEdit,               hInst);
  60.     pvt->Execute           =(LPVOID)MakeProcInstance(ServerExecute,            hInst);
  61.     pvt->Exit              =(LPVOID)MakeProcInstance(ServerExit,               hInst);
  62.     pvt->Open              =(LPVOID)MakeProcInstance(ServerOpen,               hInst);
  63.     pvt->Release           =(LPVOID)MakeProcInstance(ServerRelease,            hInst);
  64.     fRet =(NULL!=pvt->Create);
  65.     fRet&=(NULL!=pvt->CreateFromTemplate);
  66.     fRet&=(NULL!=pvt->Edit);
  67.     fRet&=(NULL!=pvt->Execute);
  68.     fRet&=(NULL!=pvt->Exit);
  69.     fRet&=(NULL!=pvt->Open);
  70.     fRet&=(NULL!=pvt->Release);
  71.    #endif
  72.     return fRet;
  73.     }
  74. /*
  75.  * OLEVtblFreeServer
  76.  *
  77.  * Purpose:
  78.  *  Frees all procedure instances in the server VTBL.
  79.  *
  80.  * Parameters:
  81.  *  pvt             LPOLESERVERVTBL to the VTBL to free.
  82.  *
  83.  * Return Value:
  84.  *  none
  85.  *
  86.  * Customization:
  87.  *  None required.
  88.  */
  89. void WINAPI OLEVtblFreeServer(LPOLESERVERVTBL pvt)
  90.     {
  91.    #ifndef WIN32
  92.     FreeProcInstance(pvt->Create);
  93.     FreeProcInstance(pvt->CreateFromTemplate);
  94.     FreeProcInstance(pvt->Edit);
  95.     FreeProcInstance(pvt->Exit);
  96.     FreeProcInstance(pvt->Open);
  97.     FreeProcInstance(pvt->Release);
  98.    #endif
  99.     return;
  100.     }
  101. /*
  102.  * FOLEVtblInitDocument
  103.  *
  104.  * Purpose:
  105.  *  Creates procedure instances for all the OLE methods required
  106.  *  for document methods.
  107.  *
  108.  * Parameters:
  109.  *  hInst           HINSTANCE of the application instance.
  110.  *  pvt             LPOLESERVERDOCVTBL to the VTBL to initialize.
  111.  * 
  112.  * Return Value:
  113.  *  None
  114.  *
  115.  * Customization:
  116.  *  None required.
  117.  */
  118. BOOL WINAPI FOLEVtblInitDocument(HINSTANCE hInst, LPOLESERVERDOCVTBL pvt)
  119.     {
  120.     BOOL        fRet=TRUE;
  121.    #ifdef WIN32
  122.     pvt->Close           =DocClose;
  123.     pvt->GetObject       =DocGetObject;
  124.     pvt->Execute         =DocExecute;
  125.     pvt->Release         =DocRelease;
  126.     pvt->Save            =DocSave;
  127.     pvt->SetColorScheme  =DocSetColorScheme;
  128.     pvt->SetDocDimensions=DocSetDocDimensions;
  129.     pvt->SetHostNames    =DocSetHostNames;
  130.    #else
  131.     pvt->Close           =(LPVOID)MakeProcInstance(DocClose,            hInst);
  132.     pvt->GetObject       =(LPVOID)MakeProcInstance(DocGetObject,        hInst);
  133.     pvt->Execute         =(LPVOID)MakeProcInstance(DocExecute,          hInst);
  134.     pvt->Release         =(LPVOID)MakeProcInstance(DocRelease,          hInst);
  135.     pvt->Save            =(LPVOID)MakeProcInstance(DocSave,             hInst);
  136.     pvt->SetColorScheme  =(LPVOID)MakeProcInstance(DocSetColorScheme,   hInst);
  137.     pvt->SetDocDimensions=(LPVOID)MakeProcInstance(DocSetDocDimensions, hInst);
  138.     pvt->SetHostNames    =(LPVOID)MakeProcInstance(DocSetHostNames,     hInst);
  139.     fRet =(NULL!=pvt->Close);
  140.     fRet&=(NULL!=pvt->GetObject);
  141.     fRet&=(NULL!=pvt->Execute);
  142.     fRet&=(NULL!=pvt->Release);
  143.     fRet&=(NULL!=pvt->Save);
  144.     fRet&=(NULL!=pvt->SetColorScheme);
  145.     fRet&=(NULL!=pvt->SetDocDimensions);
  146.     fRet&=(NULL!=pvt->SetHostNames);
  147.    #endif
  148.     return fRet;
  149.     }
  150. /*
  151.  * OLEVtblFreeDocument
  152.  *
  153.  * Purpose:
  154.  *  Frees all procedure instances in the document VTBL.
  155.  *
  156.  * Parameters:
  157.  *  pvt             LPOLESERVERDOCVTBL to the VTBL to free.
  158.  *
  159.  * Return Value:
  160.  *  none
  161.  *
  162.  * Customization:
  163.  *  None required.
  164.  */
  165. void WINAPI OLEVtblFreeDocument(LPOLESERVERDOCVTBL pvt)
  166.     {
  167.    #ifndef WIN32
  168.     FreeProcInstance(pvt->Close);
  169.     FreeProcInstance(pvt->GetObject);
  170.     FreeProcInstance(pvt->Release);
  171.     FreeProcInstance(pvt->Save);
  172.     FreeProcInstance(pvt->SetColorScheme);
  173.     FreeProcInstance(pvt->SetDocDimensions);
  174.     FreeProcInstance(pvt->SetHostNames);
  175.    #endif
  176.     return;
  177.     }
  178. /*
  179.  * FOLEVtblInitObject
  180.  *
  181.  * Purpose:
  182.  *  Creates procedure instances for all the OLE methods required
  183.  *  for object methods.
  184.  *
  185.  * Parameters:
  186.  *  hInst           HINSTANCE of the application instance.
  187.  *  pvt             LPOLEOBJECTVTBL to free.
  188.  * 
  189.  * Return Value:
  190.  *  None
  191.  *
  192.  * Customization:
  193.  *  Your application might not use global variables for srvrvtbl,
  194.  *  docvtbl, and objvtbl.
  195.  */
  196. BOOL WINAPI FOLEVtblInitObject(HINSTANCE hInst, LPOLEOBJECTVTBL pvt)
  197.     {
  198.     BOOL        fRet=TRUE;
  199.     /*
  200.      * Local variables are used here just to make this one assignment
  201.      * more readable since it requires some typecasting to compile clean
  202.      * at warning level 3.
  203.      */
  204.    #ifdef WIN32
  205.     pvt->QueryProtocol  =ObjQueryProtocol;
  206.     pvt->DoVerb         =ObjDoVerb;
  207.     pvt->EnumFormats    =ObjEnumFormats;
  208.     pvt->GetData        =ObjGetData;
  209.     pvt->Release        =ObjRelease;
  210.     pvt->SetBounds      =ObjSetBounds;
  211.     pvt->SetColorScheme =ObjSetColorScheme;
  212.     pvt->SetData        =ObjSetData;
  213.     pvt->SetTargetDevice=ObjSetTargetDevice;
  214.     pvt->Show           =ObjShow;
  215.    #else
  216.     pvt->QueryProtocol  =(LPVOID)MakeProcInstance((FARPROC)ObjQueryProtocol, hInst);;
  217.     pvt->DoVerb         =(LPVOID)MakeProcInstance(ObjDoVerb, hInst);
  218.     pvt->EnumFormats    =(LPVOID)MakeProcInstance(ObjEnumFormats, hInst);
  219.     pvt->GetData        =(LPVOID)MakeProcInstance(ObjGetData, hInst);
  220.     pvt->Release        =(LPVOID)MakeProcInstance(ObjRelease, hInst);
  221.     pvt->SetBounds      =(LPVOID)MakeProcInstance(ObjSetBounds, hInst);
  222.     pvt->SetColorScheme =(LPVOID)MakeProcInstance(ObjSetColorScheme, hInst);
  223.     pvt->SetData        =(LPVOID)MakeProcInstance(ObjSetData, hInst);
  224.     pvt->SetTargetDevice=(LPVOID)MakeProcInstance(ObjSetTargetDevice, hInst);
  225.     pvt->Show           =(LPVOID)MakeProcInstance(ObjShow, hInst);
  226.     fRet =(NULL!=pvt->QueryProtocol);
  227.     fRet&=(NULL!=pvt->DoVerb);
  228.     fRet&=(NULL!=pvt->EnumFormats);
  229.     fRet&=(NULL!=pvt->GetData);
  230.     fRet&=(NULL!=pvt->Release);
  231.     fRet&=(NULL!=pvt->SetBounds);
  232.     fRet =(NULL!=pvt->SetColorScheme);
  233.     fRet&=(NULL!=pvt->SetData);
  234.     fRet&=(NULL!=pvt->SetTargetDevice);
  235.     fRet&=(NULL!=pvt->Show);
  236.    #endif
  237.     return fRet;    //TRUE by default in Win32
  238.     }
  239. /*
  240.  * OLEVtblFreeObject
  241.  *
  242.  * Purpose:
  243.  *  Frees all procedure instances in the object VTBL.
  244.  *
  245.  * Parameters:
  246.  *  pvt             LPOLEOBJECTVTBL to the VTBL to free.
  247.  *
  248.  * Return Value:
  249.  *  none
  250.  *
  251.  * Customization:
  252.  *  None required.
  253.  */
  254. void WINAPI OLEVtblFreeObject(LPOLEOBJECTVTBL pvt)
  255.     {
  256.    #ifndef WIN32
  257.     FreeProcInstance(pvt->DoVerb);
  258.     FreeProcInstance(pvt->EnumFormats);
  259.     FreeProcInstance(pvt->GetData);
  260.     FreeProcInstance((FARPROC)pvt->QueryProtocol);
  261.     FreeProcInstance(pvt->Release);
  262.     FreeProcInstance(pvt->SetBounds);
  263.     FreeProcInstance(pvt->SetColorScheme);
  264.     FreeProcInstance(pvt->SetData);
  265.     FreeProcInstance(pvt->SetTargetDevice);
  266.     FreeProcInstance(pvt->Show);
  267.    #endif
  268.     return;
  269.     }
  270. #endif //MAKEOLESERVER