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. Problem with MessageBox & Pointing

Problem with MessageBox & Pointing

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpcsharphtmldata-structures
13 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.
  • S Offline
    S Offline
    Semion_N
    wrote on last edited by
    #1

    Hello, I have two question-the first is about MessageBox and the second is about pointing. 1) Whaen I'm trying to use simple MessageBox MessageBox("hello"); it writes me: error C2660: 'MessageBoxA' : function does not take 1 arguments but as I know the other arguments are optional, so what is the problem? and why it writes MessageBoxA? 2) I asked a question one or two days ago about my Tic_Tac_Toe project, and have another: here is the code:Code[^] Some introduction: T1/T is a Tic_Tac_Toe object (the class is defined from line 2-12). PointersToNodes is a pointers array to Tic_Tac_Toe objects. currentCaseVector is an array of the current board. and buildNewTree is a function which returns adress of a Tic_Tac_Toe object(line 78). When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char). the error is(I uploaded a picture with the error): http://img241.imageshack.us/img241/2323/bugmq7.jpg[^] And those who can't see the picture so the error is:Unhandled exception at 0x004bebbf in Self_Learning_Tic_Tac_Toe.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. Why does the error occurs? and how can I fix it? Thank you!:)

    SnaidiS(Semion)

    _ W S 4 Replies Last reply
    0
    • S Semion_N

      Hello, I have two question-the first is about MessageBox and the second is about pointing. 1) Whaen I'm trying to use simple MessageBox MessageBox("hello"); it writes me: error C2660: 'MessageBoxA' : function does not take 1 arguments but as I know the other arguments are optional, so what is the problem? and why it writes MessageBoxA? 2) I asked a question one or two days ago about my Tic_Tac_Toe project, and have another: here is the code:Code[^] Some introduction: T1/T is a Tic_Tac_Toe object (the class is defined from line 2-12). PointersToNodes is a pointers array to Tic_Tac_Toe objects. currentCaseVector is an array of the current board. and buildNewTree is a function which returns adress of a Tic_Tac_Toe object(line 78). When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char). the error is(I uploaded a picture with the error): http://img241.imageshack.us/img241/2323/bugmq7.jpg[^] And those who can't see the picture so the error is:Unhandled exception at 0x004bebbf in Self_Learning_Tic_Tac_Toe.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. Why does the error occurs? and how can I fix it? Thank you!:)

      SnaidiS(Semion)

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Semion_N wrote:

      When I'm trying to use simple MessageBox("hello");

      MessageBox function take 4 parameters. It's declared as: int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType ); MessageBoxA- Windows MessageBoxW- Unicode //// Correction On the other hand AfxMessageBox takes only 1 parameter.The other's are default.int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, // This is default UINT nIDHelp = 0 // This is also default ); int AFXAPI AfxMessageBox( UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT ) -1 );

      Semion_N wrote:

      When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char).

      :doh: -- modified at 9:14 Tuesday 12th September, 2006

      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

      T S 2 Replies Last reply
      0
      • _ _AnsHUMAN_

        Semion_N wrote:

        When I'm trying to use simple MessageBox("hello");

        MessageBox function take 4 parameters. It's declared as: int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType ); MessageBoxA- Windows MessageBoxW- Unicode //// Correction On the other hand AfxMessageBox takes only 1 parameter.The other's are default.int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, // This is default UINT nIDHelp = 0 // This is also default ); int AFXAPI AfxMessageBox( UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT ) -1 );

        Semion_N wrote:

        When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char).

        :doh: -- modified at 9:14 Tuesday 12th September, 2006

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        S Offline
        S Offline
        Semion_N
        wrote on last edited by
        #3

        Thank you for the answer for 1 and What is the problem with the second question? please look at the code in line 40.:)

        SnaidiS(Semion)

        1 Reply Last reply
        0
        • _ _AnsHUMAN_

          Semion_N wrote:

          When I'm trying to use simple MessageBox("hello");

          MessageBox function take 4 parameters. It's declared as: int MessageBox(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType ); MessageBoxA- Windows MessageBoxW- Unicode //// Correction On the other hand AfxMessageBox takes only 1 parameter.The other's are default.int AfxMessageBox( LPCTSTR lpszText, UINT nType = MB_OK, // This is default UINT nIDHelp = 0 // This is also default ); int AFXAPI AfxMessageBox( UINT nIDPrompt, UINT nType = MB_OK, UINT nIDHelp = (UINT ) -1 );

          Semion_N wrote:

          When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char).

          :doh: -- modified at 9:14 Tuesday 12th September, 2006

          Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          _AnShUmAn_ wrote:

          MessageBoxA- Unicode MessageBoxW- Windows

          wrong, it's the opposite... A stands for Ansi W stands for wide characters ; UNICODE then


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          1 Reply Last reply
          0
          • S Semion_N

            Hello, I have two question-the first is about MessageBox and the second is about pointing. 1) Whaen I'm trying to use simple MessageBox MessageBox("hello"); it writes me: error C2660: 'MessageBoxA' : function does not take 1 arguments but as I know the other arguments are optional, so what is the problem? and why it writes MessageBoxA? 2) I asked a question one or two days ago about my Tic_Tac_Toe project, and have another: here is the code:Code[^] Some introduction: T1/T is a Tic_Tac_Toe object (the class is defined from line 2-12). PointersToNodes is a pointers array to Tic_Tac_Toe objects. currentCaseVector is an array of the current board. and buildNewTree is a function which returns adress of a Tic_Tac_Toe object(line 78). When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char). the error is(I uploaded a picture with the error): http://img241.imageshack.us/img241/2323/bugmq7.jpg[^] And those who can't see the picture so the error is:Unhandled exception at 0x004bebbf in Self_Learning_Tic_Tac_Toe.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. Why does the error occurs? and how can I fix it? Thank you!:)

            SnaidiS(Semion)

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #5

            1. Message function takes 4 paramaters, not 1. 2. 'cdcdcdcd' normaly means uninitialized memory. You create the array here currentCaseVector=new char[9]; But I can't see where you initialize it. try calling memset() first to set the memory to 0. Also, I don't want to call your code sloppy, but there is very little error checking. You should be initializing your variables and setting them to NULL. Later when you come to use them, you should check first if they are NULL or not.

            S 1 Reply Last reply
            0
            • W Waldermort

              1. Message function takes 4 paramaters, not 1. 2. 'cdcdcdcd' normaly means uninitialized memory. You create the array here currentCaseVector=new char[9]; But I can't see where you initialize it. try calling memset() first to set the memory to 0. Also, I don't want to call your code sloppy, but there is very little error checking. You should be initializing your variables and setting them to NULL. Later when you come to use them, you should check first if they are NULL or not.

              S Offline
              S Offline
              Semion_N
              wrote on last edited by
              #6

              I'm intializing it in lines 31-32: for(i=0;i<9;i++) T->currentCaseVector[i]='b';

              SnaidiS(Semion)

              W 1 Reply Last reply
              0
              • S Semion_N

                I'm intializing it in lines 31-32: for(i=0;i<9;i++) T->currentCaseVector[i]='b';

                SnaidiS(Semion)

                W Offline
                W Offline
                Waldermort
                wrote on last edited by
                #7

                No you are not.

                for(i=0;i<9;i++)
                T->currentCaseVector[i]='b';
                for(i=0;i<9;i++)
                c = T->PointersToNodes[1]->currentCaseVector[i];

                You are initializing each member of the localy created T object. But you are readig the uninitialized members of a pointer to an object of type T, in this case '1', the second member in the array. Your BuildNewTree() function is not initializing the currentCaseVector array.

                S 1 Reply Last reply
                0
                • W Waldermort

                  No you are not.

                  for(i=0;i<9;i++)
                  T->currentCaseVector[i]='b';
                  for(i=0;i<9;i++)
                  c = T->PointersToNodes[1]->currentCaseVector[i];

                  You are initializing each member of the localy created T object. But you are readig the uninitialized members of a pointer to an object of type T, in this case '1', the second member in the array. Your BuildNewTree() function is not initializing the currentCaseVector array.

                  S Offline
                  S Offline
                  Semion_N
                  wrote on last edited by
                  #8

                  It is. The function : resetCurrentCaseArray do that work.(line 49)

                  SnaidiS(Semion)

                  1 Reply Last reply
                  0
                  • S Semion_N

                    Hello, I have two question-the first is about MessageBox and the second is about pointing. 1) Whaen I'm trying to use simple MessageBox MessageBox("hello"); it writes me: error C2660: 'MessageBoxA' : function does not take 1 arguments but as I know the other arguments are optional, so what is the problem? and why it writes MessageBoxA? 2) I asked a question one or two days ago about my Tic_Tac_Toe project, and have another: here is the code:Code[^] Some introduction: T1/T is a Tic_Tac_Toe object (the class is defined from line 2-12). PointersToNodes is a pointers array to Tic_Tac_Toe objects. currentCaseVector is an array of the current board. and buildNewTree is a function which returns adress of a Tic_Tac_Toe object(line 78). When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char). the error is(I uploaded a picture with the error): http://img241.imageshack.us/img241/2323/bugmq7.jpg[^] And those who can't see the picture so the error is:Unhandled exception at 0x004bebbf in Self_Learning_Tic_Tac_Toe.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. Why does the error occurs? and how can I fix it? Thank you!:)

                    SnaidiS(Semion)

                    _ Offline
                    _ Offline
                    _AnsHUMAN_
                    wrote on last edited by
                    #9

                    Semion_N wrote:

                    T->PointersToNodes[1]->currentCaseVector[i];(c is char).

                    c = T->PointersToNodes[1]->currentCaseVector[i]; Did you initialize the contents for this.... Two lines before this you write T->currentCaseVector[i]='b'; in your code.

                    Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                    S 1 Reply Last reply
                    0
                    • _ _AnsHUMAN_

                      Semion_N wrote:

                      T->PointersToNodes[1]->currentCaseVector[i];(c is char).

                      c = T->PointersToNodes[1]->currentCaseVector[i]; Did you initialize the contents for this.... Two lines before this you write T->currentCaseVector[i]='b'; in your code.

                      Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

                      S Offline
                      S Offline
                      Semion_N
                      wrote on last edited by
                      #10

                      Yes I did intialized it. I'm pointing from T to the array of pointers to Tic_Tac_Toe and thenthe object of Tic_Tac_Toe from the array. there is a currentCaseVector. I intialized all.

                      SnaidiS(Semion)

                      1 Reply Last reply
                      0
                      • S Semion_N

                        Hello, I have two question-the first is about MessageBox and the second is about pointing. 1) Whaen I'm trying to use simple MessageBox MessageBox("hello"); it writes me: error C2660: 'MessageBoxA' : function does not take 1 arguments but as I know the other arguments are optional, so what is the problem? and why it writes MessageBoxA? 2) I asked a question one or two days ago about my Tic_Tac_Toe project, and have another: here is the code:Code[^] Some introduction: T1/T is a Tic_Tac_Toe object (the class is defined from line 2-12). PointersToNodes is a pointers array to Tic_Tac_Toe objects. currentCaseVector is an array of the current board. and buildNewTree is a function which returns adress of a Tic_Tac_Toe object(line 78). When I'm running the project it thorows me an error at line 40: c = T->PointersToNodes[1]->currentCaseVector[i];(c is char). the error is(I uploaded a picture with the error): http://img241.imageshack.us/img241/2323/bugmq7.jpg[^] And those who can't see the picture so the error is:Unhandled exception at 0x004bebbf in Self_Learning_Tic_Tac_Toe.exe: 0xC0000005: Access violation reading location 0xcdcdcdcd. Why does the error occurs? and how can I fix it? Thank you!:)

                        SnaidiS(Semion)

                        S Offline
                        S Offline
                        Semion_N
                        wrote on last edited by
                        #11

                        So can anyone help me please?

                        SnaidiS(Semion)

                        W 1 Reply Last reply
                        0
                        • S Semion_N

                          So can anyone help me please?

                          SnaidiS(Semion)

                          W Offline
                          W Offline
                          Waldermort
                          wrote on last edited by
                          #12

                          I have already told you the answer. You are reading un-initialized data. Step through it with your debugger and keep your eye on the values.

                          S 1 Reply Last reply
                          0
                          • W Waldermort

                            I have already told you the answer. You are reading un-initialized data. Step through it with your debugger and keep your eye on the values.

                            S Offline
                            S Offline
                            Semion_N
                            wrote on last edited by
                            #13

                            Ok , Thank you , I will do that.

                            SnaidiS(Semion)

                            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