Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how do i make another main.c file where i can call this program and run according to it..? Pin
Richard MacCutchan2-Aug-14 0:41
mveRichard MacCutchan2-Aug-14 0:41 
GeneralRe: how do i make another main.c file where i can call this program and run according to it..? Pin
mybm12-Aug-14 2:06
mybm12-Aug-14 2:06 
GeneralRe: how do i make another main.c file where i can call this program and run according to it..? Pin
Richard MacCutchan2-Aug-14 2:49
mveRichard MacCutchan2-Aug-14 2:49 
GeneralRe: how do i make another main.c file where i can call this program and run according to it..? Pin
CPallini2-Aug-14 2:59
mveCPallini2-Aug-14 2:59 
GeneralRe: how do i make another main.c file where i can call this program and run according to it..? Pin
Richard MacCutchan2-Aug-14 3:05
mveRichard MacCutchan2-Aug-14 3:05 
AnswerRe: Put the other main in a namespace Pin
Software_Developer2-Aug-14 7:10
Software_Developer2-Aug-14 7:10 
GeneralRe: Put the other main in a namespace Pin
CPallini3-Aug-14 0:20
mveCPallini3-Aug-14 0:20 
QuestionC++ ofstream System.AccessViolation Pin
Kit Fisto1-Aug-14 5:07
Kit Fisto1-Aug-14 5:07 
Hello guys,

I have a problem. I'm writing to a log file, but when I do the application throws:

An unhandled exception of type 'System.AccessViolationException' occurred in ****

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


The code (unmanaged) I'm using is this one:

C++
inline bool writeLog(nsCLog::eSeverity severity, string message)
{
	ofstream myfile;
							
		if( ((int)severity) >= mLogLevel)
		{
			myfile.open(mStrSource.c_str(), ios::in | ios::out | ios::app);

			if(!myfile.is_open())
			{
				throw "Unable to open the file: " + mStrSource;
			}
			
			myfile << "TESTE" << endl;

			myfile.close();
		}
	}

	return true;
};


When receiving this error, the code points to the _Lock() of file fstream:

C++
virtual void __CLR_OR_THIS_CALL _Lock()
		{	// lock file instead of stream buffer
		if (_Myfile)
			_CSTD _lock_file(_Myfile);
		}


Other info:

Developed under VS2010 (Incially the project was Winx32 but now it's Winx64) (.NET Framework 4).

The open() method of ofstream creates the file and the file is writable but throws the exception when try's to write on the file.

Thank you guys in advanced.

modified 1-Aug-14 12:23pm.

QuestionRe: C++ ofstream System.AccessViolation Pin
CPallini1-Aug-14 6:11
mveCPallini1-Aug-14 6:11 
AnswerRe: C++ ofstream System.AccessViolation Pin
Kit Fisto1-Aug-14 6:22
Kit Fisto1-Aug-14 6:22 
GeneralRe: C++ ofstream System.AccessViolation Pin
CPallini1-Aug-14 22:05
mveCPallini1-Aug-14 22:05 
AnswerRe: C++ ofstream System.AccessViolation Pin
Kit Fisto4-Aug-14 23:49
Kit Fisto4-Aug-14 23:49 
AnswerRe: C++ ofstream System.AccessViolation Pin
Member 138550171-Jun-18 13:43
Member 138550171-Jun-18 13:43 
QuestionHow can I display Japanese characters in an application ? Pin
Swap930-Jul-14 23:12
Swap930-Jul-14 23:12 
QuestionRe: How can I display Japanese characters in an application ? Pin
Richard MacCutchan30-Jul-14 23:42
mveRichard MacCutchan30-Jul-14 23:42 
AnswerRe: How can I display Japanese characters in an application ? Pin
Swap930-Jul-14 23:53
Swap930-Jul-14 23:53 
QuestionImport CSV to Access DB. Pin
Member 1093049930-Jul-14 8:25
Member 1093049930-Jul-14 8:25 
AnswerRe: Import CSV to Access DB. Pin
Richard MacCutchan30-Jul-14 20:31
mveRichard MacCutchan30-Jul-14 20:31 
QuestionHow to consume web service in C++ using REST SDK.? Pin
mbatra3130-Jul-14 4:34
mbatra3130-Jul-14 4:34 
AnswerRe: How to consume web service in C++ using REST SDK.? Pin
Richard MacCutchan30-Jul-14 5:01
mveRichard MacCutchan30-Jul-14 5:01 
Questiontreeview ctrl rmb menu question Pin
bobfresh30-Jul-14 0:09
bobfresh30-Jul-14 0:09 
QuestionRe: treeview ctrl rmb menu question Pin
Richard MacCutchan30-Jul-14 0:37
mveRichard MacCutchan30-Jul-14 0:37 
Questioncan anyone help how to find summation of float number? Pin
mybm129-Jul-14 20:33
mybm129-Jul-14 20:33 
AnswerRe: can anyone help how to find summation of float number? Pin
Richard MacCutchan29-Jul-14 20:54
mveRichard MacCutchan29-Jul-14 20:54 
GeneralRe: can anyone help how to find summation of float number? Pin
mybm129-Jul-14 21:05
mybm129-Jul-14 21:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.