|
The first parameter in eprom_update_byte() function declaration is different than what is the the implemntation. In the .h file it is a pointer to a uint8_t (uint8_t *__p), and in the implementation it is a copy of the object (uint8_t eeprom_addr) passed by value. I'm guessing, change the implementation line in the .c file. But that might cause you to call the function differently like,
eeprom_memory_update_byte(&eepromAddr, eepromVal);
|
|
|
|
|
You haven't given us the implementation of this prototype function
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
Implicit declaration error usually means you provided a prototype but no body code ... hence I am worried you haven't given me that functions code. I am assuming the EEPROM is flash and that code will do what we call the toggling test until it writes the byte to the flash. Warning if it is FLASH you usually also have to release protection registers by writing special commands to special addresses before you can write to the flash, did the original code also provide a function to release the protection on a sector per chance?
However onto your code as it stands, you are passing in the address to write as a byte which gives you a range of 0-255 in memory see here
bool Update_EEPROM_Memory_byte(byte val1, byte val2) {
uint8_t eepromAddr = val1;
uint8_t eepromVal = val2;
The original function they provided had a pointer to an byte (uint_8) which will be most likely be 32 bit ... see
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
I suspect you need your address to be a long ..... try
bool Update_EEPROM_Memory_byte(unsigned long val1, byte val2){
unsigned long eepromAddr = val1;
uint8_t eepromVal = val2;
Adjusted last function to take the long
bool eeprom_memory_update_byte(unsigned long eeprom_addr, uint8_t eepromValue)
{
eeprom_update_byte((uint8_t*) eeprom_addr, eepromValue);
uint8_t eepromVal = eeprom_read_byte(( uint8_t *) eeprom_addr);
if (eepromValue == eepromVal)
return 1;
else
return 0;
}
The alternative to an unsigned long for the address is to keep it as a pointer (uint8_t*).
That all means nothing if you have no code for the function eeprom_update_byte which isn't shown.
Other housekeeping Update_EEPROM_Memory_byte should return the result of eeprom_memory_update_byte rather than a static 1 (TRUE) result.
In vino veritas
modified 30-Jul-16 0:22am.
|
|
|
|
|
how to create buttons to input txt file and pdf files in microsoft visual c ++ ?
|
|
|
|
|
|
First I would like to start thanks to all on the CodeProject I think I am getting a little better at this (this being MFC)
Well my code works fine Under the VS 2012 debugger, However When I rebuild it in Release mode. I get a message that my program stopped working with the option of invoking the VS debugger, which I do the code points to MFC code Unhandled Exception going back via the Call Stack it points to CString code Which I will gladly post,
Well the Next thing I did seeing the code works fine in Debug mode, was code a CATCH_ALL exception handler just to see if the code with go to the CATCH_ALL block in Which I invoke AfxMessageBox(".... exception handler") and the message was displayed.
I think at this point I have to get a little more specific (as to what type of exception)
So at the point I think I'll post my code The Bold underline code seems be
where the problem is when I go bank via the Call Stack In Debug mode I check the contents
and tempstr is a Valid Null Terminated String
Can someone at least point me to where I might be able find information exception to catch the specific exception that's giving me the problem
Thanks
if(pMsg->message==WM_KEYDOWN)
{
TRY
{
if(pMsg->wParam==VK_RETURN)
{
main_app = (CHERC_CMDApp *)AfxGetApp();
memcpy((void *)main_app->mybaseeventptr->command,(void *)"REL",3);
memcpy((void *)main_app->threadptr[curr_thread]->sockbuffer,(void *)"REL",3);
main_app->threadptr[curr_thread]->num_buff = 3;
CString tempstr = PSW.ia;
tempstr.SetAt(16,0x00);
tempstr.MakeUpper();
if(tempstr == end_address)
{
memcpy((void *)main_app->threadptr[curr_thread]->sockbuffer,(void *)"TERM",4);
main_app->threadptr[curr_thread]->num_buff = 4;
}
::PostThreadMessage(main_app->threadptr[curr_thread]->m_nThreadID,WM_SEND_SOCK_MESS,22,(LPARAM) main_app->mybaseeventptr->command);
::GetCaretPos(&mycursor);
mychar = myedit->CharFromPos(mycursor);
longchar = mychar;
cursorline = myedit->LineFromChar(longchar);
linelen = myedit->LineLength(cursorline);
linelen = 125;
linechar = myedit->LineIndex(cursorline);
myedit->GetLine(cursorline,currline.GetBufferSetLength(linelen +1),linelen);
buffptr = currline.GetBuffer(10);
myeventptr = main_app->mybaseeventptr;
strncpy((char *)myeventptr->command,(char *)&nu_lls[0],5); myeventptr->send_window = this;
myeventptr->SetEvent();
}
}
CATCH_ALL(e)
{
AfxMessageBox("In ProgDebug Exception Routine");
}
END_CATCH_ALL
}
|
|
|
|
|
The big difference for variables between DEBUG mode and RELEASE mode is stack variables aren't zeroed.
The simple statement
void SomeFunc (void){
int i;
}
i is guaranteed to start as zero in DEBUG mode but could be literally anything in RELEASE mode.
In the above if you need the variable to start as zero you need it.
void SomeFunc (void){
int i = 0;
}
Now you most likely have a structure or pointer variable you are assuming is zero but you have not explicitly set it in a local variable. Your code will then always work in DEBUG mode but almost never works in RELEASE mode.
In vino veritas
|
|
|
|
|
How about in release mode I attach the debugger I try to stepping thru the code that's giving me a problem
Thanks
|
|
|
|
|
Also turn your error level to 4 in release mode and look for any warning along the lines possible use of uninitialized variable.
In vino veritas
|
|
|
|
|
MFC throws exceptions derived from the CException class which contain additional information and provide a function to show a message.
So you may add this block of code on front of your CATCH_ALL block:
CATCH(CException, pEx)
{
pEx->ReportError();
pEx->Delete();
}
The operation that might fail in your code is CString::SetAt (when the position is beyond the end of the string). This will throw an exception in release builds and assert with debug builds. Because you are not getting an assertion with a debug build, the only reason for an exception in release builds can be a different (shorter) PSW.ia string. If this is not the case the exception source is probably somewhere else.
To avoid such out of range acesses you should check the length or use a function that handles them like CString::Left .
|
|
|
|
|
How about pEX->GetErrorMessage.....
I think ReportError is just a message box with out any information ?
|
|
|
|
|
I must confess that I have not tested if the reporting contains the error message but assumed that it would do so.
But you can of course use GetErrorMessage with your own reporting.
|
|
|
|
|
it was the SetAt Truthfully I never called the constructer so CString tempstr(&PSW.ia,16);
Thanks
|
|
|
|
|
Thanks for your help answering my past queries.
If I have an array of strings:-
char*sss[10];
sss[0]="cow";
sss[1]="eland";
sss[2]="kudu";
....etc....
please how in a function can I display these strings and ask the user to choose one of these strings and get the function to return the index number of the chosen string?
I could write a function from scratch; but is there such a standard library function already?
modified 26-Jul-16 17:26pm.
|
|
|
|
|
Anthony Appleyard wrote: is there such a standard library function No, you will need to write your own.
|
|
|
|
|
Hi
I am getting an Error First Chance Exception at xxxxx (ntdll.dll) access violation reading location 0xFFFFFFFFFFFFFFFF (running under the Visual Studio Debugger)
This happens after I create a CDialog with a richedit from MAINFRAME
I don't have any exception handling in my program
When I look at the stack call its some where in NTDLL tracing back to Kernel32
Could someone at the very least point me to a good place for Exception handling for beginners in MFC
Thanks
|
|
|
|
|
This might not be the expected answer:
With most types of exceptions the best handling is avoiding that they occur.
This applies especially to the access violation exception. Even when catching it by code, the only reasonable "handling" is terminating the application immediately.
In your actual case you should use the debugger stepping back in the code to find out what let the exception occur. It is probably one of your objects that hasn't been initialised or set to an error state (e.g. a pointer containing the value -1 ) and the exception is thrown when it is used the first time (inside the kernel / ntddl in your case).
A general hint to reduce debugging time searching for the source of such exceptions is checking the success state of every function that provides one (usually the return value). The simplest way to do this is using assertions in debug build. With MFC you can use the ASSERT (MFC)[^] and VERIFY[^] macros.
|
|
|
|
|
Actually that was the answer I was hoping for
I'll back track and look
At what happened right before
Thanks
|
|
|
|
|
First Chance Exceptions can be benign under the debugger. Did the application crash at that point? If so, you should look at the stack trace to see what was the last line of code in your application.
|
|
|
|
|
It's some time after I create a CDialog with rich edit and it is displayed a few minutes after that the exception occurs
I'll back tack and look at my code
Thanks
|
|
|
|
|
I am returning to caller of SendMessage something on the stack the stack may have gotten deleted before the SendMessage completed I moved the return value to the class object
So I'll see
Thanks
|
|
|
|
|
If you are returning a value then it should be OK. But if it's a pointer to a stack variable then you are probably right.
|
|
|
|
|
ForNow wrote:
This happens after I create a CDialog with a richedit... Have you remembered to call AfxInitRichEdit2() to load the richedit library?
Another option would be to temporarily add the DS_NOFAILCREATE style to the dialog. That way it'll go ahead and create/display the dialog even if there is a problem with one or more controls. When you see what control is missing, you know where to focus your efforts.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I was doing sockets if my connect was good I issued A AfxMessageBox indicating success apparently that caused the problem I didn't use CWnd::MessageBox
|
|
|
|
|
That reminds me of a guy in college who was having trouble with his program crashing. He solved the problem by adding a few calls to printf() . I just sat there with a look in my eyes.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I've seen the same in assembler, "but when I put some NOP's here, it works fine!" Ugh!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|