LRESULT IEDiagnosticsAdapter::OnMessageFromIE(UINT nMsg, WPARAM wParam, LPARAM lParam, _Inout_ BOOL& /*bHandled*/)
{
    CString message;

    // Scope for the copied data
    {
        // Take ownership of the copydata struct memory
        unique_ptr<COPYDATASTRUCT, void(*)(COPYDATASTRUCT*)> spParams(reinterpret_cast<PCOPYDATASTRUCT>(lParam), ::FreeCopyDataStructCopy);

        // Get the string message from the structure
        CopyDataPayload_StringMessage_Data* pMessage = reinterpret_cast<CopyDataPayload_StringMessage_Data*>(spParams->lpData);
        LPCWSTR lpString = reinterpret_cast<LPCWSTR>(reinterpret_cast<BYTE*>(pMessage)+pMessage->uMessageOffset);
        message = lpString;
    }

    HWND proxyHwnd = reinterpret_cast<HWND>(wParam);
    if (m_proxyConnections.find(proxyHwnd) != m_proxyConnections.end())
    {
        string utf8;
        int length = message.GetLength();
        LPWSTR buffer = message.GetBuffer();

        // Convert the message into valid UTF-8 text
        int utf8Length = ::WideCharToMultiByte(CP_UTF8, 0, buffer, length, nullptr, 0, nullptr, nullptr);
        if (utf8Length == 0)
        {
            message.ReleaseBuffer();
            ATLENSURE_RETURN_HR(false, ::GetLastError());
        }

        utf8.resize(utf8Length);
        utf8Length = ::WideCharToMultiByte(CP_UTF8, 0, buffer, length, &utf8[0], static_cast<int>(utf8.length()), nullptr, nullptr);
        message.ReleaseBuffer();
        ATLENSURE_RETURN_HR(utf8Length > 0, ::GetLastError());

        // Forward the message to the websocket
        try
        {
            m_server.send(m_proxyConnections[proxyHwnd], utf8, websocketpp::frame::opcode::text);
        }
        catch (const std::exception & e)
        {
            std::cout << "Execption during send: " << e.what() << std::endl;
        }
        catch (websocketpp::lib::error_code e)
        {
            std::cout << "Error during send: " << e.message() << std::endl;
        }
        catch (...)
        {
            std::cout << "Unknown exception during send" << std::endl;
        }
    }

    return 0;
}
Exemplo n.º 2
0
STDMETHODIMP CMmShUndAtom::CalcAllOptions(IMmShUndColl* collUndColl,
										  EtsCalcModelTypeEnum enCalcModel,
										  VARIANT_BOOL bUseTheoVolatility,
										  VARIANT_BOOL bUseTheoVolaNoBid,
										  VARIANT_BOOL bUseTheoVolaBadMarket,
										  DOUBLE dUndPriceTolerance,
										  enum EtsPriceRoundingRuleEnum enPriceRoundingRule,
										  LONG nCalcSleepFreq,
										  LONG nCalcSleepAmt,
										  ICalculationParametrs* Params)
{
	try
	{
		IUnknownPtr spUnk;
		_variant_t varItem;
		ULONG nFetched = 0L;
		HRESULT hr;

		EtsReplacePriceStatusEnum enMidPriceStatus = enRpsNone;
		DOUBLE dSpotPriceMid = m_spUndPriceProfile->GetUndPriceMid(m_dPriceBid, m_dPriceAsk, m_dPriceLast, dUndPriceTolerance, enPriceRoundingRule, &enMidPriceStatus, FALSE);

		IMmShUndCollPtr spUndColl(collUndColl);
		ICalculationParametrsPtr spParams(Params);

		IMmShOptAtomPtr spOption;
		_CHK(m_spOpt->get__NewEnum(&spUnk), _T("Fail to get options collection."));

		IEnumVARIANTPtr spOptionEnum(spUnk);
		_CHK(spOptionEnum->Reset(), _T("Fail to reset options collection."));

		while((hr = spOptionEnum->Next(1L, &varItem, &nFetched)) == S_OK)
		{
			ATLASSERT(varItem.vt == VT_DISPATCH);
			spOption = varItem;
			if(nFetched > 0 && spOption != NULL)
			{
				_CHK(CalcOptionGreeks(spUndColl, spOption, dSpotPriceMid,
						enCalcModel, bUseTheoVolatility, 
						bUseTheoVolaNoBid, bUseTheoVolaBadMarket,
						dUndPriceTolerance, enPriceRoundingRule,
						spParams),
						_T("Fail to calculate option greeks."));

				_CalcSleep(nCalcSleepFreq, nCalcSleepAmt);
			}
		}
	}
	catch(const _com_error& e)
	{
		return Error((PTCHAR)CComErrorWrapper::ErrorDescription(e), IID_IMmShUndAtom, e.Error());
	}


	return S_OK;
}
LRESULT IEDiagnosticsAdapter::OnCopyData(UINT nMsg, WPARAM wParam, LPARAM lParam, _Inout_ BOOL& /*bHandled*/)
{
    PCOPYDATASTRUCT pCopyDataStruct = reinterpret_cast<PCOPYDATASTRUCT>(lParam);

    // Copy the data so that we can post message to ourselves and unblock the SendMessage caller
    unique_ptr<COPYDATASTRUCT, void(*)(COPYDATASTRUCT*)> spParams(::MakeCopyDataStructCopy(pCopyDataStruct), ::FreeCopyDataStructCopy);

    PCOPYDATASTRUCT pParams = spParams.release();
    BOOL succeeded = this->PostMessageW(WM_PROCESSCOPYDATA, wParam, reinterpret_cast<LPARAM>(pParams));
    if (!succeeded)
    {
        // Take ownership if the post message fails so that we can correctly clean up the memory
        HRESULT hr = ::AtlHresultFromLastError();
        spParams.reset(pParams);
        FAIL_IF_NOT_S_OK(hr);
    }

    return 0;
}