0

I found this solution to make the login part in QuickFIX via C++ with Username and Password.

Working with Visual Studio 2012 Express I had to make an additional include in order to avoid "error C2680: 'FIX44::Logon &' : invalid target type for dynamic_cast" to show Visual Studio 2012 Express how to dynamic cast:

#include "../../include/quickfix/fix44/Logon.h"     // for dynamic_cast in Visual C++
void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
    if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
    {
        FIX44::Logon& logon_message = dynamic_cast<FIX44::Logon&>(message);
        logon_message.setField(FIX::Username("xxx"));
        logon_message.setField(FIX::Password("yyy"));
    }
} 

With this include, no compile time errors occur - but at run time, I get: "Microsoft C++ exception: std::bad_cast at memory location 0x02A0ED70."

As far es I have debugged, the shown dynamic_cast statement is responsible for the runtime error.

My question is, how could one go around this run time error and to login with Username and Password using Visual Studio 2012 Express?

Community
  • 1
  • 1
Ben
  • 1
  • 2

1 Answers1

0

You can try such approach, which is used in my project and works like a charm:

void MarketApplication::toAdmin(FIX::Message& message, const FIX::SessionID& sessionID) {

if (FIELD_GET_REF(message.getHeader(), MsgType) == FIX::MsgType_Logon)
{
    const FIX::Dictionary& session_settings = m_settings.get(sessionID);

    if (session_settings.has("TargetSubID"))
        message.setField(FIX::TargetSubID(session_settings.getString("TargetSubID")));

    if (session_settings.has("Username"))
        message.setField(FIX::Username(session_settings.getString("Username")));

    if (session_settings.has("Password"))
        message.setField(FIX::Password(session_settings.getString("Password")));
}

}

The main advantage is that you can specify password/login in session configuration avoiding any hardcode

Alexey Zhivotov
  • 101
  • 1
  • 5