CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Location
    Czech Republic
    Posts
    78

    Return value of an ATL event

    Hi, I have a problem getting a return value from an ATL event.

    I my definition of the connection point interface I have this method:
    Code:
    [id(1), helpstring("method PageFormatted")] HRESULT PageFormatted([in] long pageNumber, [out, retval] BOOL* bRet);
    The "interesting part" of the wizard-generated Fire_PageFormatted method is this:
    Code:
    CComVariant avarParams[1];
    avarParams[0] = pageNumber;
    avarParams[0].vt = VT_I4;
    CComVariant varResult;
    if(bRet)
    {
    varResult.byref = bRet;
    varResult.vt = VT_BOOL|VT_BYREF;
    }
    DISPPARAMS params = { avarParams, NULL, 1, 0 };
    hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, NULL);
    In the object which handles this event I have defined this handler:
    Code:
    	BOOL __stdcall OnPageFormatted( long pageNumber );
    And its _ATL_FUNC_INFO:
    Code:
    _ATL_FUNC_INFO OnPageFormattedInfo = {CC_STDCALL, VT_BOOL, 1, {VT_I4}};
    I fire the event this way:
    Code:
    BOOL bRet = TRUE;
    Fire_PageFormatted( (long) pgNum, &bRet );
    But no matter what I return from the handler, the value of bRet is not updated.

    Any thoughts what might be wrong?

  2. #2
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: Return value of an ATL event

    Code:
    CComVariant varResult;
    ///if(bRet)
    ///{
    ///varResult.byref = bRet;
    ///varResult.vt = VT_BOOL|VT_BYREF;
    ///}
    DISPPARAMS params = { avarParams, NULL, 1, 0 };
    hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, NULL);
    
    if (SUCCEEDED(hr) && SUCCEEDED(hr = varResult.ChangeType(VT_BOOL))) {
      *bRet = varResult.boolVal;
    }
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured