home *** CD-ROM | disk | FTP | other *** search
/ Developing for Microsoft …tive Animated Characters / DEV_AGENTA.ISO / Examples / c / hello2 / Notify.cpp < prev    next >
C/C++ Source or Header  |  1997-08-19  |  5KB  |  276 lines

  1. #include "Notify.h"
  2.  
  3.  
  4. //==========================================================================
  5. //
  6. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  7. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  8. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  9. //  PURPOSE.
  10. //
  11. //  Copyright (C) 1997 Microsoft Corporation.  All Rights Reserved.
  12. //
  13. //--------------------------------------------------------------------------
  14. //
  15. // AgentNotifySink
  16. //
  17. //        Boilerplate IDispatch implementation with stubs for all 
  18. //        IAgentNotifySink methods except for RequestComplete.
  19. //
  20. //==========================================================================
  21.  
  22.  
  23. extern long g_lDone;
  24.  
  25.  
  26. // IUnknown methods
  27.  
  28. STDMETHODIMP AgentNotifySink::QueryInterface (REFIID riid, LPVOID *ppv) {
  29.  
  30.     *ppv = NULL;
  31.  
  32.     if ((riid == IID_IUnknown) || (riid == IID_IAgentNotifySink))
  33.         *ppv = this;
  34.  
  35.     if (*ppv == NULL)
  36.         return E_NOINTERFACE;
  37.  
  38.     ((LPUNKNOWN)*ppv)->AddRef();
  39.  
  40.     return NOERROR;
  41. }
  42.  
  43.  
  44. STDMETHODIMP_ (ULONG) AgentNotifySink::AddRef() {
  45.  
  46.     return ++m_cRefs;
  47. }
  48.  
  49.  
  50. STDMETHODIMP_(ULONG) AgentNotifySink::Release() {
  51.  
  52.     if (--m_cRefs != 0)
  53.         return m_cRefs;
  54.  
  55.     delete this;
  56.     return 0;
  57. }
  58.  
  59.  
  60. // IDispatch methods
  61.  
  62. STDMETHODIMP AgentNotifySink::GetTypeInfoCount(UINT *pctInfo) {
  63.  
  64.     *pctInfo = 1;
  65.     return NOERROR;
  66. }
  67.  
  68.  
  69. STDMETHODIMP AgentNotifySink::GetTypeInfo(UINT itInfo, LCID lcid, ITypeInfo **ppTypeInfo) {
  70.  
  71.     HRESULT hRes;
  72.     ITypeLib *pLib;
  73.  
  74.     *ppTypeInfo = NULL;
  75.  
  76.     if (itInfo != 0)
  77.         return TYPE_E_ELEMENTNOTFOUND;
  78.  
  79.     if (ppTypeInfo == NULL)
  80.         return E_POINTER;
  81.  
  82.     if ((PRIMARYLANGID(lcid) != LANG_NEUTRAL) && 
  83.         (PRIMARYLANGID(lcid) != LANG_ENGLISH))
  84.         return DISP_E_UNKNOWNLCID;
  85.  
  86.     hRes = LoadRegTypeLib(LIBID_AgentServerObjects, 
  87.                           1, 
  88.                           0,
  89.                           PRIMARYLANGID(lcid), 
  90.                           &pLib);
  91.     if (FAILED(hRes))
  92.         return hRes;
  93.  
  94.     hRes = pLib->GetTypeInfoOfGuid(IID_IAgentNotifySink, ppTypeInfo);
  95.         
  96.     pLib->Release();
  97.  
  98.     if (FAILED(hRes))
  99.         return hRes;
  100.  
  101.     (*ppTypeInfo)->AddRef();
  102.  
  103.     return NOERROR;
  104. }
  105.  
  106.  
  107. STDMETHODIMP AgentNotifySink::GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID) {
  108.  
  109.     HRESULT hRes;
  110.     ITypeInfo *pInfo;
  111.  
  112.     // REFIID must be NULL
  113.  
  114.     if (riid != IID_NULL)
  115.         return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
  116.  
  117.     // Get the TypeInfo for the specified lcid
  118.  
  119.     hRes = GetTypeInfo(0, lcid, &pInfo);
  120.  
  121.     if (FAILED(hRes))
  122.         return hRes;
  123.  
  124.     // Use the TypeInfo to get the DISPIDs of the specified names.
  125.     // That's the whole point here.  Let TypeInfo do the work so
  126.     // we don't have to.
  127.  
  128.     hRes = pInfo->GetIDsOfNames(rgszNames, cNames, rgDispID);
  129.  
  130.     pInfo->Release();
  131.  
  132.     return hRes;
  133. }
  134.  
  135.  
  136. STDMETHODIMP AgentNotifySink::Invoke(DISPID dispID, REFIID riid, LCID lcid, 
  137.                                      unsigned short wFlags, DISPPARAMS *pDispParams, 
  138.                                      VARIANT *pVarResult, EXCEPINFO *pExcepInfo, 
  139.                                      UINT *puArgErr) {
  140.  
  141.     HRESULT hRes;
  142.     ITypeInfo *pInfo;
  143.  
  144.     // The riid parameter is always supposed to be IID_NULL
  145.  
  146.     if (riid != IID_NULL)
  147.         return DISP_E_UNKNOWNINTERFACE;
  148.  
  149.     // Get the type info for the specified lcid
  150.  
  151.     hRes = GetTypeInfo(0, lcid, &pInfo);
  152.  
  153.     if (FAILED(hRes))
  154.         return hRes;
  155.  
  156.     // Clear exceptions
  157.  
  158.     SetErrorInfo(0L, NULL);
  159.  
  160.     hRes = pInfo->Invoke(this, 
  161.                          dispID, 
  162.                          wFlags, 
  163.                          pDispParams, 
  164.                          pVarResult, 
  165.                          pExcepInfo, 
  166.                          puArgErr);
  167.  
  168.  
  169.     pInfo->Release();
  170.  
  171.     return hRes;
  172. }
  173.  
  174.  
  175. // IAgentNotifySink methods
  176.  
  177. STDMETHODIMP AgentNotifySink::Command(long dwCommandID, IUnknown * punkUserInput) {
  178.  
  179.     return NOERROR;
  180. }
  181.  
  182.  
  183. STDMETHODIMP AgentNotifySink::ActivateInputState(long dwCharID, long bActivated) {
  184.  
  185.     return NOERROR;
  186. }
  187.  
  188.  
  189. STDMETHODIMP AgentNotifySink::Restart() {
  190.  
  191.     return NOERROR;
  192. }
  193.  
  194.  
  195. STDMETHODIMP AgentNotifySink::Shutdown() {
  196.  
  197.     return NOERROR;
  198. }
  199.  
  200.  
  201. STDMETHODIMP AgentNotifySink::VisibleState(long dwCharID, long bVisible, long lCause) {
  202.  
  203.     return NOERROR;
  204. }
  205.  
  206.  
  207. STDMETHODIMP AgentNotifySink::Click(long dwCharID, short fwKeys, long X, long Y) {
  208.  
  209.     return NOERROR;
  210. }
  211.  
  212.  
  213. STDMETHODIMP AgentNotifySink::DblClick(long dwCharID, short fwKeys, long X, long Y) {
  214.  
  215.     return NOERROR;
  216. }
  217.  
  218.  
  219. STDMETHODIMP AgentNotifySink::DragStart(long dwCharID, short fwKeys, long X, long Y) {
  220.  
  221.     return NOERROR;
  222. }
  223.  
  224.  
  225. STDMETHODIMP AgentNotifySink::DragComplete(long dwCharID, short fwKeys, long X, long Y) {
  226.  
  227.     return NOERROR;
  228. }
  229.  
  230.  
  231. STDMETHODIMP AgentNotifySink::RequestStart(long dwRequestID) {
  232.  
  233.     return NOERROR;
  234. }
  235.  
  236.  
  237. STDMETHODIMP AgentNotifySink::RequestComplete(long dwRequestID, long hrStatus) {
  238.  
  239.     // When we get g_lDone exit the sample app
  240.  
  241.     if (dwRequestID == g_lDone)
  242.         PostQuitMessage(0);
  243.  
  244.     return NOERROR;
  245. }
  246.  
  247.  
  248. STDMETHODIMP AgentNotifySink::BookMark(long dwBookMarkID) {
  249.  
  250.     return NOERROR;
  251. }
  252.  
  253.  
  254. STDMETHODIMP AgentNotifySink::Idle(long dwCharID, long bStart) {
  255.  
  256.     return NOERROR;
  257. }
  258.  
  259.  
  260. STDMETHODIMP AgentNotifySink::Move(long dwCharID, long X, long Y, long lCause) {
  261.  
  262.     return NOERROR;
  263. }
  264.  
  265.  
  266. STDMETHODIMP AgentNotifySink::Size(long dwCharID, long lWidth, long lHeight) {
  267.  
  268.     return NOERROR;
  269. }
  270.  
  271.  
  272. STDMETHODIMP AgentNotifySink::BalloonVisibleState(long dwCharID, long bVisible) {
  273.  
  274.     return NOERROR;
  275. }
  276.