|
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
|
|
|
|
|
jeron1 wrote: "but when I put some NOP's here, it works fine!"
In some cases, that can actually be the solution.
For example, the PC/AT was too fast for some older PC peripherals, and would cause the peripherals to crash when sending back-to-back OUT commands to the peripheral. The solution was to add a NOP between the OUTs, which slowed the operation by just the right amount.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Ok, ok you got me there . We've recently run into this, where the propagation delay of HC logic was too slow for the MCU we were using, and yes we threw in some delay. In this instance though, it was old Motorola HC11, and there was a floating input and the input read would be different depending on, apparently, the instructions that were being executed just before the read.
"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
|
|
|
|
|
Hi
I have a modeless dialog box in Which I create a Rich Edit
After the Create I try to acess the Window Handle via GetSafeHwnd
Sometimes I get an exception
HWND dlgwnd;
main_app->progdbg->Create(IDD_PROGDBG,AfxGetMainWnd());
dlgwnd = main_app->progdbg->GetSafeHwnd();
|
|
|
|
|
Well, Create method might fail. You are not checking its return value (it is worth noting that Create , on success, returns the handle you are searching for).
|
|
|
|
|
Ok
Thanks rebuild see what happens
|
|
|
|
|
ForNow wrote: Sometimes I get an exception
And exactly this exception look like?
And did you try to debug your code to be sure all the parts of your expressions are correct?
|
|
|
|
|
Generate Unique Ids
FormStrings(unsigned int id, string bigText)
{
for(int x = 0; x< k; ++x)
unsigned int id uid = generateUniqueId(..);
ForwardString(uid, stringx)
}
FormStrings() method receives id which starts from 1 and increments ahead as FormStrings() method is called.
FormStrings() method further split the bigText received into smaller strings and passes to other methods.
Requirement is to generate a unique 32 bit id for the new strings created. I should also take care of how many uids are getting created from id, so that if later anyone calls delete id, all the sub-uids string should get deleted.
For example:
FormStrings(1, "Hi, I want to learn cpp.")
string1 = Hi,
String2 = I want to
String3 = learn cpp.
Here id 1 has 3 substrings. I need to create 3 uids.
Next time when FormStrings() method is called, it will come with an id 2, then 3 and so on.
I thought of creating id using 32 bits as
16 bits for id - 65535 ids
8 bits for storing number of strings formed.
but when I ran the actual program, I found out that 65535 is a small number to store id, it could be a very big number(20 bits will also not work), even number of strings formed from bigText is not fixed. I am open to create new variables, structs etc
Any suggestions are welcome.
|
|
|
|
|
You could use each half of the 32 bit value such that the most significant half is the first digit (1, 2 etc.), and the second half is the string sequence number. So your id is generated by something like:
FormStrings(unsigned int id, string bigText)
{
unsigned int uid = id << 16;
for(int x = 0; x< k; ++x)
{
uid += 1;
ForwardString(uid, stringx)
}
}
This should provide enough unique values for most purposes.
|
|
|
|
|
What you are making is called a hash table but you have a linking requirement.
This will need a linked list due to this part of the requirement => if later anyone calls delete id, all the sub-uids string should get deleted.
In its simplest form your substring structure using ID's will be
struct uiString {
unsigned long uid;
struct uiString* next;
};
The humour is your uid is the same length as just holding a pointer to the string which is guaranteed unique
You bascially keep deleting a each "next" sub string until your reach NULL for your above requirement.
Unless the text is in or going into a database I can't see a point to the uid you might as well use the pointer to the text as the uid.
So I guess the question I ask is what is the purpose of the hash table .. security?
In vino veritas
|
|
|
|
|
does anyone have an example of steganography source code for c ++ ?
thank you 
|
|
|
|
|
Most likely yes, and Google will find them for you.
|
|
|
|
|
Hi
I am trying to concatenate a number of CString, problem is After the third it includes the NULL termination which delimits the string. Let me post the code
b_command, prog_location, end_addr and casid2 are all of type CString
int starters = strtol(prog_location,&hold_ptr,16);
int enders = starters + progsize;
_itoa(enders,p = end_addr.GetBuffer(0),16);
b_command = b_command + prog_location + "-" + end_addr + " " + casid2;
b_command, prog_location, end_addr, and casid2 are all strings
After b_commnd = .....
the string containing end_addr has the NULL marker included in b_command making the data casid2 invisible I can see that casid2 is there after the NULL by looking in memory
|
|
|
|
|
You must call ReleaseBuffer() after changing the string. While not doing so the CString object may be in an undefined state. See CSimpleStringT::GetBuffer[^]:
Quote: If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before you use any other CSimpleStringT member methods.
So use:
_itoa(enders,p = end_addr.GetBuffer(0),16);
end_addr.ReleaseBuffer();
|
|
|
|
|
worked
Thanks
|
|
|
|