Problem with MessageBox & Pointing
-
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)
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_
-
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_
-
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_
_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! ]
-
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)
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. -
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. -
I'm intializing it in lines 31-32:
for(i=0;i<9;i++) T->currentCaseVector[i]='b';
SnaidiS(Semion)
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.
-
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.
-
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)
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_
-
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_
-
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)
-
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.
-
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.