OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
From: Arvind K. Gangal (arvind_gangalINAME.COM)
Date: Fri Jan 04 2002 - 08:50:19 CST

  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    Hello Gurus,

    I am writing a ATL COM DLL which in turn uses an another 3rd party normal
    dll.

    In my FinalConstruct i initialize the 3rd party dll toolkit and also
    Register the Interface in the GIT.
    While using the third party dll i also provide it with my own callback
    function “DisplayPercentage”.

    Now when the VB call a Write() function on my Interface I in turn call the
    functions of the 3rd party dll which in turn call my call back function
    say “DisplayPercentage” which is a global function.

    Now in this DisplayPercentage funtion I need to fire events to the VB. I am
    doing a work around. I call function FireEvents on IMedia interface. Which
    in turn call Fire_…().

    The problem is that when in my Write() function on my Interface I create
    another thread and call the third party function call. It calls my
    DisplayPercentage function but when I try to get the Interface from the GIT
    it fails with HRESULT stating catastrophic failure.

    Here are some excerpts from the code at your disposal.

    HRESULT CMedia::FinalConstruct()
    {
     HRESULT hRes = E_FAIL;

     try
     {
      IMedia* pIMedia;

      hRes = this->QueryInterface(__uuidof
    (IMedia),reinterpret_cast<void**>(&pIMedia));
      if(hRes != S_OK)
       return hRes;

      hRes = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
                                NULL,
                                CLSCTX_INPROC_SERVER,
                                IID_IGlobalInterfaceTable,
                                (void **)&g_pGIT);
      if(g_pGIT == NULL)
       return E_FAIL;

      hRes = g_pGIT->RegisterInterfaceInGlobal(pIMedia, __uuidof
    (IMedia),&g_dwCookie);

      if(g_dwCookie == 0 || hRes != S_OK)
       return E_FAIL;

      l_UserFunctions.PercFunction = DisplayPercentage;

      if( !InitialiseToolkit())
       return E_FAIL;

      if( !InitialiseGenerator())
       return E_FAIL;

      if(!InitialiseRecorder())
       return E_FAIL;

      //g_pMedia = this;
      hRes = S_OK;
     }
     catch(...)
     {
      hRes = E_FAIL;
     }

     return hRes;
    }
    ...

    .....
    void __stdcall
    DisplayPercentage (void *FreeUserPtr, TK_INT iPercentageValue, TK_INT
    iPercentageType)
    {
      IMedia* pIMedia;
     IGlobalInterfaceTable* pGIT = NULL;
     HRESULT hRes;

    hRes = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
                                NULL,
                                CLSCTX_INPROC_SERVER,
                                IID_IGlobalInterfaceTable,
                                (void **)&pGIT);
     if(pGIT == NULL)
      return;

     hRes = pGIT->GetInterfaceFromGlobal(g_dwCookie, __uuidof(IMedia),
    reinterpret_cast<void**>(&pIMedia));

     if(pIMedia == NULL)
      return;

     switch (iPercentageType)
     {
     case UI_PERC_VOLUME_WRITE:
     case UI_PERC_VOLUME_ESTIMATE:
     case UI_PERC_VOLUME_VERIFY_IMAGE:
     case UI_PERC_VOLUME_MAKE_PHYSICAL:
     case UI_PERC_VOLUME_VERIFY_AFTER_WRITE:
     case UI_PERC_DISC_READ:
     case UI_PERC_CYCLIC_BUFFER:
      // Ignored here
      if (iPercentageValue == -1)
      {
      // display_somewhere ("");
      }
      else
      {
        if(g_iBufferProgress != iPercentageValue)
        {
         g_iBufferProgress = iPercentageValue;
         ATLTRACE("Buffer Progress Percent %d \n",
    iPercentageValue);
         pIMedia->FireEvent(UI_PERC_CYCLIC_BUFFER,
    g_iBufferProgress);
        }
      }
      break;
     case UI_PERC_DISC_FIXATION:
      if (iPercentageValue == -1)
      {
      // display_somewhere ("");
      }
      else
      {
        if(g_iTotalProgress != iPercentageValue)
        {
         g_iTotalProgress = iPercentageValue;
         ATLTRACE("Total Progress Percent %d \n",
    iPercentageValue);
         pIMedia->FireEvent(UI_PERC_DISC_FIXATION,
    g_iTotalProgress);
        }
      }
      break;
     case UI_PERC_DISC_ERASE:
     case UI_PERC_TRACK_WRITE:
     case UI_PERC_TRACK_ESTIMATE:
     case UI_PERC_TRACK_VERIFY_IMAGE:
     case UI_PERC_TRACK_MAKE_PHYSICAL:
     case UI_PERC_TRACK_VERIFY_AFTER_WRITE:
     case UI_PERC_TRACK_READ:
      if (iPercentageValue == -1)
      {
      // display_somewhere ("");
      }
      else
      {
        if(g_iTrackProgress != iPercentageValue)
        {
         g_iTrackProgress = iPercentageValue;
         ATLTRACE("Track Progress Percent %d \n",
    iPercentageValue);
         pIMedia->FireEvent(UI_PERC_TRACK_READ,
    g_iTrackProgress);
        }
      }
      break;
     default:
      break;
     }

     pIMedia->Release();
    }

    ----------------------------------------------------------------
    Users Guide http://discuss.microsoft.com/archives/mailfaq.asp
    contains important info. Save time, search the archives at
    http://discuss.microsoft.com/archives/index.html .
    To unsubscribe, mailto:DCOM-signoff-requestDISCUSS.MICROSOFT.COM