Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can anyone see the problem-newbie [modified]

Can anyone see the problem-newbie [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helptestingbeta-testingquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    antonaras
    wrote on last edited by
    #1

    Hi again Just when i thought i'm done this comes up i wrote this code for testing it compiles ok but it then crashes at a certain point can anyone help me find the error #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") using namespace std; void main() { string token="viagra"; HRESULT hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; // Formerly opened connection pointer string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token; command+="'"; pCommand->CommandText = command.data(); //the problem is definetly in the following part _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; int valField3; double valField4; int valField5; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5); pRecordset->MoveNext(); } } else cout<<"No record found insert?"<Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); } Any ideas thanks again -- modified at 14:41 Thursday 1st June, 2006

    A C Z D 4 Replies Last reply
    0
    • A antonaras

      Hi again Just when i thought i'm done this comes up i wrote this code for testing it compiles ok but it then crashes at a certain point can anyone help me find the error #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") using namespace std; void main() { string token="viagra"; HRESULT hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; // Formerly opened connection pointer string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token; command+="'"; pCommand->CommandText = command.data(); //the problem is definetly in the following part _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; int valField3; double valField4; int valField5; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5); pRecordset->MoveNext(); } } else cout<<"No record found insert?"<Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); } Any ideas thanks again -- modified at 14:41 Thursday 1st June, 2006

      A Offline
      A Offline
      antonaras
      wrote on last edited by
      #2

      Sorry i forgot to give some more details The table of the database is tblDatabase and the colums are token:: text Spam::Number Ham::Number P::Number(with decimal points) app::number Thanks

      1 Reply Last reply
      0
      • A antonaras

        Hi again Just when i thought i'm done this comes up i wrote this code for testing it compiles ok but it then crashes at a certain point can anyone help me find the error #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") using namespace std; void main() { string token="viagra"; HRESULT hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; // Formerly opened connection pointer string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token; command+="'"; pCommand->CommandText = command.data(); //the problem is definetly in the following part _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; int valField3; double valField4; int valField5; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5); pRecordset->MoveNext(); } } else cout<<"No record found insert?"<Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); } Any ideas thanks again -- modified at 14:41 Thursday 1st June, 2006

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        antonaras wrote:

        it then crashes at a certain point

        which point is that? Cleek | Image Toolkits | Thumbnail maker

        1 Reply Last reply
        0
        • A antonaras

          Hi again Just when i thought i'm done this comes up i wrote this code for testing it compiles ok but it then crashes at a certain point can anyone help me find the error #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") using namespace std; void main() { string token="viagra"; HRESULT hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; // Formerly opened connection pointer string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token; command+="'"; pCommand->CommandText = command.data(); //the problem is definetly in the following part _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; int valField3; double valField4; int valField5; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5); pRecordset->MoveNext(); } } else cout<<"No record found insert?"<Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); } Any ideas thanks again -- modified at 14:41 Thursday 1st June, 2006

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          Without actually knowing where it is crashing (and not being able to run it myself), here are the most likely places based on the code:

          antonaras wrote:

          valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5);

          If GetItem returns NULL for any of those items at any point in time, you will get an access violation. Also, if the types don't match up (that is, if the field is a double and you are checking the int value), you will get strange results that could blow up your stack in a weird place. Additionally, the printf statement will blow up your stack the way it is written. When you have 2 arguments in the printf string, you should only have 2 variables to match them (you have 2 in the string and 4 trying to match them).

          antonaras wrote:

          m_pConn->Close();

          You didn't close the recordset, so at this point, the connection is being closed. Now, when the Recordset smart pointer goes out of scope, it will attempt to close, but it will no longer have a connection. Try adding a pRecordset->Close(); call prior to the connection's close call. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac -- modified at 15:21 Thursday 1st June, 2006

          1 Reply Last reply
          0
          • A antonaras

            Hi again Just when i thought i'm done this comes up i wrote this code for testing it compiles ok but it then crashes at a certain point can anyone help me find the error #import "C:\Program Files\Common Files\System\ADO\msado15.dll" \ no_namespace rename("EOF", "EndOfFile") using namespace std; void main() { string token="viagra"; HRESULT hr = S_OK; CoInitialize(NULL); try { _ConnectionPtr m_pConn; HRESULT hr =m_pConn.CreateInstance(__uuidof(Connection)); if (FAILED( hr )) cout<<"Can't create an intance of ADO.Connection"<Open(_bstr_t("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =bayesfilter.MDB"), _bstr_t( "" ), _bstr_t( "" ), adModeUnknown ))) cout<<"Can't open datasource"<ActiveConnection = m_pConn; // Formerly opened connection pointer string command="SELECT token,Spam,Ham,P,app FROM tblDictionary WHERE token='"+ token; command+="'"; pCommand->CommandText = command.data(); //the problem is definetly in the following part _RecordsetPtr pRecordset; pRecordset.CreateInstance (__uuidof (Recordset)); pRecordset->CursorLocation = adUseClient; pRecordset->Open ( (IDispatch *) pCommand, vtMissing, adOpenStatic, adLockBatchOptimistic, adCmdUnknown); _bstr_t valField1; int valField2; int valField3; double valField4; int valField5; pRecordset->MoveFirst(); if (!pRecordset->EndOfFile) { while(!pRecordset->EndOfFile) { valField1 = pRecordset->Fields->GetItem("Token")->Value; valField2 = pRecordset->Fields->GetItem("Spam")->Value.intVal; valField3 = pRecordset->Fields->GetItem("Ham")->Value.intVal; valField4 = pRecordset->Fields->GetItem("P")->Value.dblVal; valField5 = pRecordset->Fields->GetItem("app")->Value.intVal; printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5); pRecordset->MoveNext(); } } else cout<<"No record found insert?"<Close(); }catch( _com_error &ce ) { printf("Error:%s\n",ce.Description); } CoUninitialize(); } Any ideas thanks again -- modified at 14:41 Thursday 1st June, 2006

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            antonaras wrote:

            printf("%d - %s\n",(LPCSTR)valField1,valField2,valField3,valField5);

            This should be:

            printf("%d - %s\n", valField2, (LPCSTR) valField1);


            "The largest fire starts but with the smallest spark." - David Crow

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups