|
jtasph wrote: I don't know what's the meaning of "0x33, 0xC0, 0xC2, 0x04, 0x00".
As David said, it is hex code for "return 0;" . So after you do that WriteProcessMemory (), the SetUnhandledExceptionFilter () will not work any maore it will simply reurn 0. Not only for CRT calls for you also( I am not sure when CRT calls this function. If it has called the SetUnhandledExceptionFilter() before you disable it, the CRT exception handler will work ).
However I suspect the necessity of supressing the CRT exception trough the above method. I guess the you can use the _set_abort_behavior () to control the exception handler of CRT.
More over there is AddVectoredExceptionHandler () function which will be executed before the exception handler specified in SetUnhandledExceptionFilter ().
|
|
|
|
|
Naveen wrote: However I suspect the necessity of supressing the CRT exception trough the above method. I guess the you can use the _set_abort_behavior() to control the exception handler of CRT.
I found out some introdution about exception handling mechanism in VS2005.
There're 3 kinds of checks in CRT code that pass around and invoke Dr.Watson directly.
1.One is when we have detected a buffer overrun (/GS failure). For security reasons in this case, we directly call the UnhandledExceptionFilter.
2.Another is when we detect an invalid parameter before a bad situation occurs.
3.A third are other abnormal terminations (purecall, unexpected, etc). These generally have their own handlers that you can set (_set_purecall, _set_terminate, _set_unexpected). These exist only in cases where we consider it safe to do so.
_set_abort_behavior, signal(SIGABRT, ...), and _set_invalid_parameter_handler(...) functions allow to intercept in case 2 and case 3. But for case 1, we can set api hook.
Is it right?
|
|
|
|
|
jtasph wrote: functions allow to intercept in case 2 and case 3. But for case 1, we can set api hook.
Hmm..Seems there is no way to control the first one. Did you check the AddVectoredExceptionHandler()? With that i guess there is no need to block any other SEH filters. Here [^]is an excellent article about vectored exception handing written by Matt Pietrek.
|
|
|
|
|
jtasph wrote: In addition, when I debug the code to catch exception, a exception dialog will ask me "Abort, Retry or Ignore". If I select "Abort" or "Ignore', my defined exception funciton will not call.
Add the following code to your project and tell me if your exception handler works:
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
Best Wishes,
-David Delaune
|
|
|
|
|
I added "SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);" but it does not work.
|
|
|
|
|
Thanks for all answerers. Here is my test code:
LONG WINAPI MyUnFilterA (struct _EXCEPTION_POINTERS *lpExceptionInfo)
{
AfxMessageBox(_T("11"));
return EXCEPTION_CONTINUE_SEARCH;
}
1.
void CExceptionDlg::OnBnClickedOk()
{
SetUnhandledExceptionFilter(MyUnFilterA);
DisableSetUnhandledExceptionFilter();
*(int *) 0 = 0;
}
2.
void CExceptionDlg::OnBnClickedOk()
{
SetUnhandledExceptionFilter(MyUnFilterA);
DisableSetUnhandledExceptionFilter();
abort();
}
3.
void CExceptionDlg::OnBnClickedOk()
{
AddVectoredExceptionHandler(1, MyUnFilterA);
*(int *) 0 = 0;
}
4.
void CExceptionDlg::OnBnClickedOk()
{
AddVectoredExceptionHandler(1, MyUnFilterA);
abort();
}
When I pressed button OK, an excepiton will occur. Case 1 and case 3 are the same result. That is,
MyUnFilterA will be be called and a messagebox will pop up and show the text "11". And after the messagebox is closed, the application exits. Case 2 and case 2 are the same result. An error dialog will pop up first and ask me "Abort", "Retry" or "Ignore". If select "Retry", the message box "11" will show. Otherwise, the application will exit.
I think it's better pop up my defined message box first. What should I do?
modified on Thursday, October 22, 2009 5:32 AM
|
|
|
|
|
Hi, can someone help me out with CFile Read mode. I want to read from a txt file and place it in the format below. My code give me error. Can't read at all.
My code
CStdioFile f1;
CString f1_txt;
f1.Open("C:/abc", CFile::modeRead);
int len = f1.GetLength();
f1.Read(f1_txt, len);
_tscanf(f1_txt, "%lf %lf %lf\n", &a, &b, &c);
....
....
....
f1.Close();
f1.Flush();
Can someone help me out with this? Need to read in this "%lf %lf %lf\n", &a, &b, &c) format.
Thanks alot.
|
|
|
|
|
If you use Read function, then its better to use CFile.
Use ReadString to get hte benefit of CStdioFile.
CStdioFile FileData;
CString chLine;
if( !FileData.Open( csFilePath_i, CFile::modeRead ))
{
return;
}
FileData.SeekToBegin();
while (FileData.ReadString(chLine))
{
_stscanf(chLine, "%lf %lf %lf\n", &a, &b, &c);
}
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks for replied ARJ09.
I can't readstring. I can only use Read. If i will readstring, my output will be wrong cos my file consist of numbers and abit of letters.
|
|
|
|
|
That wont be a problem. If you use CStdioFile then it means you like to ReadString, it will help to read line by line of your file so easily as mentioned above.
But if you prefer to read chunk by chunk data then i prefer you to use Read itself.
Величие не Бога может быть недооценена.
modified on Thursday, October 22, 2009 2:07 AM
|
|
|
|
|
Nicholas Amh wrote: _tscanf(f1_txt, "%lf %lf %lf\n", &a, &b, &c);
I think yesterday you said its working...
Whats the error?
|
|
|
|
|
The error is the program will just stop and ask me to debug, send error online or not.
It work when i change the CString txt to char* txt = new char[len+1]
but my output result is wrong. I am read some number with letter from a txt file. The txt file is quite big.
|
|
|
|
|
Check the value in the f1_txt after reading. Is it same you wrote to the file?
|
|
|
|
|
|
See my response here[^], you are going round in circles.
|
|
|
|
|
wat's up? you are fighting with CStdioFile for past more than 3 days???
If you need to read data from file, why cant you use fscanf or fstream class? it would be one line cod with that.?
still if you want to use your method, read line by line(i told you that 2 days back?) and use your sscanf function.
|
|
|
|
|
Ya, have been fighting with it for past 3weeks. I can't use fscanf cos i want to set some security. I don't want other user to open the file for reading/writing when my program is using it. Therefore i need to use CFile or CStdioFile. I change my code to
CStdioFile f1;
f1.Open("C:/abc", CFile::modeRead);
int len = f1.GetLength();
char* txt = new char[len+1];
f1.Read(txt, len);
while(_tscanf(txt, "%lf %lf %lf\n", &a, &b, &c) != EOF)
{
.....
....
}
f1.Close();
Using that, it work. But my output result is wrong. The file i am reading consist alot of number and a bit of letter. Thanks
|
|
|
|
|
Sorry if I dont know but is there any such option in CFile that is helping you to block reading/writing access to a file when you are using it and which is not possible with fscanf?
I am not saying what you are doing is impossible or wrong but I used the functions I mentioned before and they were very easy to use. I have never used CFile before. I never felt the need for it..
There must be some special use of CFile..
|
|
|
|
|
Nicholas Amh wrote: My code give me error.
Are you keeping the error a secret?
Nicholas Amh wrote: Can someone help me out with this?
You need to explain: 1) what your program is doing, and 2) what you want your program to do.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Hi all ..
I am trying to make an exe which will save the data entered by user in a text format.
Its also possible to import the text file to the editbox.. I have four editboxes and these four will be having different data.. but once i store it in text format it will be in one file and during importing the complete data will be in all four edit boxes..
I want to filter out the data for specific editboxes while importing.. Editboxes are Critical, Important, Less Important and Normal.....
Can snybody help me how to filter out the specific data...
iam including my code here.. also my text format...plz hav a look and guide me...
thanku so much
void CNoteDlg::OnOpen()
{
FILE * pFile;
CFile flEdit;
char strFilter[] = { "Text Files (*.txt)|*.txt|*.txt (*.*)|*.*||" };
CFileDialog FileDlg(TRUE, ".txt", "Prioritynotes",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
strFilter,NULL);
if( FileDlg.DoModal() == IDOK )
{
char c;
CString mystring;
pFile = fopen ("D:\\Prioritynotes.txt" , "r");
if (pFile == NULL) perror ("Error opening file");
else
{
while (!feof(pFile))
{
c = fgetc (pFile);
mystring+= c;
if (c=='\n')
{
mystring.TrimRight();
char d[3];
d[0] = 0x0D;
d[1]= 0x0A;
d[2]= 00;
mystring+= d;
m_sedit1 = mystring;
m_sedit2 = mystring;
m_sedit3 = mystring;
m_sedit4 = mystring;
UpdateData(FALSE);
}
}
}
}
}
my format of text file
Date
21/10/2009
Time
4:05:41 PM
**********************
Critical****
--------------------------
Important***
--------------------------
Less Important**
--------------------------
Normal*
--------------------------
|
|
|
|
|
If it's a professional app (which i feel is not the case), then you can use xml with four nodes and data for each node.
If you are making for learning purposes, then just insert a unique tag say <!!!TAG - 001!!!> and then dump all data for tag1. Similarly for tag2,3..
while reading data, search for <!!!TAG - 001!!!> and read data till you reach EOF or another TAG.
Now regarding searching of tags, use something like
while(*fp != '<') fp++;
if(fp == EOF) byebye.
if(read_next_9_characters() != "!!!TAG - ")
then read tag number and check for "!!!>" if it's present.
Read all data for current tag number and store.
Similarly for searching for another tags.
I am sure you can find many articles on searching string in a file in C/C++
An example is here [<a href="http://www.tutorialized.com/view/tutorial/Searching-for-a-string-in-a-File/9990" target="_blank">^</a>]
Other languages like python have built-in search capabilities for regular expressions search which makes this task very easy. other members can put more light on that.
|
|
|
|
|
thanks for the reply....
ya ur assumption is rite. im a student...
iam a beginner in vc++ and hav only very lil background in programming..
this is my first attempt...
may i know how to insert a tag ....
and as per my attempt i need to get the data after the string Critical**** from text file to be printed in first editbox and simlarly the other three...
hope u wud help me out 
|
|
|
|
|
by inserting a tag, I only meant writing some special string in a text file which has very little probability of appearing in the text entered by user. That tag serve as a flag that tells the reader of file that data for a different edit box begin here.
|
|
|
|
|
Have you tried:
CStdioFile file("D:\\Prioritynotes.txt", CFile::modeRead);
CString str;
file.ReadString(str);
m_edit1.SetWindowText(str);
m_edit2.SetWindowText(str);
m_edit3.SetWindowText(str);
m_edit4.SetWindowText(str);
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
hello david.. nice to c u here also
thanks for solving my first doubt ...
dis post was regarding the saving and opening of file.. i hav few strings with me which i need to get displayed in the text file before and in between the text from edit box...
Iam using
CString S1;
CStioFile flEdit;
m_edit1.GetWindowText(S1);
flEdit.Write(S1, S1.GetLength());
how can i make it possible..
before i was using CString every where so i was able to get the text file as per my requirement..
thanks is advance
Date
27/10/2009
Time
11:19:41 AM
**********************
Critical****
--------------------------
Important***
--------------------------
Less Important**
--------------------------
Normal*
--------------------------
|
|
|
|