Unable to add equations (C++ - SW API)!

Hi.

Could anyone please review the following piece of code and tell me

where am I going wrong in trying to add equations to the Eqn manager?

Thanks!

//    ---------------------------------------------------------------------------

int _tmain(int argc, _TCHAR* argv[]) 
{

    //  Some initial code here

    //    Initialize COM        
    CoInitialize(NULL); 

    //    Use ATL smart pointers
    CComPtr swApp;

    //    Create an instance of SolidWorks
    HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);


    swApp->put_UserControl(VARIANT_TRUE);
    swApp->put_Visible(VARIANT_TRUE);


    //    Obtain a ptr to current model doc and its extension
    //
    CComPtr            swModel;
    CComPtr swModelExt;

    swApp->get_IActiveDoc2(&swModel);

    if (! swModel)
    {
        exitSW(swApp);          // Releases COM and Uninitializes
    }
    else
    {

        char        *myCharArray=NULL;
        BSTR        myBstr=0;        // Initialize to NULL
        BSTR        myBstr1=0;        // Initialize to NULL

        //    Fetch extended doc interface
        //
        swModel->get_Extension(&swModelExt);


        //    Obtain the equations being used in the CAD model
        //
        CComPtr        swModelEqnMgr;   

        swModel->GetEquationMgr(&swModelEqnMgr);

        long numEqns;
        swModelEqnMgr->GetCount(&numEqns);


        CComBSTR    strEquation;
        double        dblValue;
        VARIANT_BOOL blSuppression;


        {

            long    retVal;
            CComPtr swCallout;

            myBstr = _com_util::ConvertStringToBSTR("Equations");
            myBstr1= _com_util::ConvertStringToBSTR("EQNFOLDER");

            swModelExt->SelectByID2( myBstr,myBstr1, 0, 0, 0, false, 0, \
                                     swCallout, 0, &blSuppression );

            swModel->ClearSelection2(true);

            //swModel->DeleteAllRelations();


            while( opFileStrm.getline(equationStr,80) && !opFileStrm.eof() )
            {
               
                myBstr = _com_util::ConvertStringToBSTR(equationStr);

                //    Index is '-1' so as to add it at the end
                //
                swModelEqnMgr->Add2((long)-1,myBstr,false,&retVal);

                equationStr[0]    = '\0';       
            }           

        }

        opFileStrm.close();


   
        //    Free-up myBSTR
        //
        ::SysFreeString(myBstr);           
        ::SysFreeString(myBstr1);

        delete [] equationStr;


        swModel->Close();

        exitSW(swApp);
           
    } // END else{}

    return 0;
}

SolidworksApi macros