1

I have referd to here : QuickFix Login Failed due to password missing

and here : How to make the login part in QuickFIX

to add username and password in toAdmin like following :

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);
        FIX::Username username = std::string("my_username") ;
        logon_message.setField( username ); 
    }
}

This cause compiler error in gcc 4.8.2 :

error: cannot dynamic_cast ??message?? (of type ??class FIX::Message??) to type ??class FIX44::Logon&?? (target is not pointer or reference to complete type)

then I change my code to

    FIX44::Logon* logon_message = (FIX44::Logon*)(&message);
    FIX::Username username = std::string("my_username") ;
    logon_message->setField( username );

this time , compiler error again :

error: invalid use of incomplete type ??class FIX44::Logon??
logon_message->setField( username );
              ^

What should I modify so that I can correctly set username and password in function toAdmin ? what is wrong with logon_message->setField( username ); ?

Edit :

according to this webpage : https://sourceforge.net/p/quickfix/mailman/message/26233433/

The following works fine to me :

if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
    message.getHeader().setField(553, "XXXXXXXXX");
    message.getHeader().setField(554, "yyyyyyyyy");
}
Community
  • 1
  • 1
barfatchen
  • 1,630
  • 2
  • 24
  • 48
  • 1
    You were definitely on the right track, just some C++ pointer stuff tripping you up. Waheed Brown's answer below will probably set you straight. – Grant Birchmeier Mar 09 '16 at 14:58

3 Answers3

1

Have you tried

FIX44::Logon* logon_message = dynamic_cast<FIX44::Logon*>(message);

or

FIX44::Logon* logon_message = dynamic_cast<FIX44::Logon*>( *(message) );

or

FIX44::Logon* logon_message = dynamic_cast<FIX44::Logon*>(&message);

I think this may be an issue of dereferencing message correctly.

1

The error message suggests that you did not #include "quickfix/fix44/Logon.h".

That is why it thinks that you are using an incomplete type. Your compiler now probably just sees a forward declared: class FIX44::Logon; and it does not know what methods this class contains.

The other answers correctly state that you don't even need to downcast

message.setField(FIX::Username(username));
message.setField(FIX::Password(password));
0

You don't need to cast your message. Ultimately you end up calling setField which is a function available to the base class FIX::Message.

        void FIXSession::toAdmin(FIX::Message& msg, const FIX::SessionID& sid)
        {
            const std::string& field = msg.getHeader().getField(FIX::FIELD::MsgType);

            if (FIX::MsgType_Logon == field)
            {
                FIX::Dictionary dd(m_sessionSettings.get(sid));

                if (dd.has(FixSettingUsername))
                {
                    FIX::Username username = dd.getString(FixSettingUsername);
                    msg.setField(username);
                }
                if (dd.has(FixSettingPassword))
                {
                    FIX::Password password = dd.getString(FixSettingPassword);
                    msg.setField(password);
                }

                if (dd.has(FIX::SEND_RESETSEQNUMFLAG))
                {
                    FIX::ResetSeqNumFlag rsn(dd.getBool(FIX::SEND_RESETSEQNUMFLAG));
                    msg.setField(rsn);
                }
            }
        }