Click here to Skip to main content
15,895,871 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: RegGetValue / Win32 Pin
Jonathan Davies3-Oct-10 1:48
Jonathan Davies3-Oct-10 1:48 
GeneralRe: RegGetValue / Win32 Pin
Fareed Rizkalla3-Oct-10 3:21
Fareed Rizkalla3-Oct-10 3:21 
GeneralRe: RegGetValue / Win32 Pin
«_Superman_»3-Oct-10 3:57
professional«_Superman_»3-Oct-10 3:57 
GeneralRe: RegGetValue / Win32 Pin
Richard MacCutchan3-Oct-10 4:01
mveRichard MacCutchan3-Oct-10 4:01 
QuestionSafeArrayCreate throwing ACCESS_VIOLATION exception, why? Pin
NeerajMD1-Oct-10 21:58
NeerajMD1-Oct-10 21:58 
AnswerRe: SafeArrayCreate throwing ACCESS_VIOLATION exception, why? Pin
Niklas L1-Oct-10 22:24
Niklas L1-Oct-10 22:24 
GeneralRe: SafeArrayCreate throwing ACCESS_VIOLATION exception, why? Pin
NeerajMD2-Oct-10 0:11
NeerajMD2-Oct-10 0:11 
QuestionWeird threading error with LibTiff Pin
Alan Balkany1-Oct-10 5:06
Alan Balkany1-Oct-10 5:06 
Hi,

I'm using LibTiff to write TIFF files (from multiple threads) in C++, and getting
the following error message:

"Probable I/O race condition detected while copying memory. The I/O
package is not thread safe by default. In multithreaded applications,
a stream must be accessed in a thread-safe way, such as a thread-safe
wrapper returned by TeaxtReader´s or TextWriters´s Synchronized methods.
This also applies to classes like StreamWriter and StreamReader"

(The C++ is being called from a C# GUI, which accounts for the .NET class names.)

The weird thing is that the LibTiff call is in a critical section, which
(theoretically) should avoid race conditions:

DLLEXPORT int writeVariableImage (HBITMAP staticBlackLayer, HBITMAP varLayer,
						VariableObject* varObj, int numVarObjects,
						char* fileName)
{
	if (!criticalSectionInitialized)
	{
		InitializeCriticalSection (&cs);
		criticalSectionInitialized = true;
	}

	EnterCriticalSection(&cs);

	try
	{							// Make copy of black
		if (!copyBitmap (varLayer, staticBlackLayer))	// layer to mark up:
			throw 666;				// Problem found.

		HDC memDc = CreateCompatibleDC (NULL);		// Prepare to draw:
		HGDIOBJ Obmp  = SelectObject(memDc, varLayer);

		if (!memDc  ||  !Obmp)
			throw 666;				// Problem found.

								// Go through objects:
		for (int i = 0;   i < numVarObjects;   ++i)	// Draw markup:
			drawVariableObject (memDc, &varObj [i]);// Draw next var object.

		invertLayer (memDc, varLayer); 
		writeToTiffFile (varLayer, fileName);		// Write to file.

		if (!SelectObject (memDc, Obmp)  ||		// Clean up:
			!DeleteDC (memDc))
			throw 666;				// Problem found.
	}
	catch (...)
	{
		DWORD err = GetLastError ();

		if (err)
		{
			LPTSTR s;				// Show error message:
			FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
				NULL, err, 0, (LPTSTR)&s, 0, NULL);
			MessageBox (NULL, s, L"Error", 0);
			LocalFree (s);
		}

		LeaveCriticalSection(&cs);
		return 0;					// Failed.
	}

	LeaveCriticalSection(&cs);
	return 1;						// Success.
}


The other oddity is that the error only shows up on 1 out of the 4 computers it's
been tried on. (The computer that shows the error has 4 cores, the others, 2.)

Any ideas what could be causing this, or how to avoid it? Thanks!
AnswerRe: Weird threading error with LibTiff PinPopular
Blake Miller1-Oct-10 6:14
Blake Miller1-Oct-10 6:14 
GeneralRe: Weird threading error with LibTiff Pin
Alan Balkany1-Oct-10 6:23
Alan Balkany1-Oct-10 6:23 
QuestionXP theme/common control question Pin
David Crow1-Oct-10 4:29
David Crow1-Oct-10 4:29 
AnswerRe: XP theme/common control question Pin
Richard MacCutchan1-Oct-10 5:53
mveRichard MacCutchan1-Oct-10 5:53 
QuestionHow to question about stepping into a dll Pin
ns1-Oct-10 4:28
ns1-Oct-10 4:28 
AnswerRe: How to question about stepping into a dll Pin
Richard MacCutchan1-Oct-10 5:37
mveRichard MacCutchan1-Oct-10 5:37 
GeneralRe: How to question about stepping into a dll Pin
Blake Miller1-Oct-10 6:16
Blake Miller1-Oct-10 6:16 
GeneralRe: How to question about stepping into a dll Pin
Richard MacCutchan1-Oct-10 10:16
mveRichard MacCutchan1-Oct-10 10:16 
AnswerRe: How to question about stepping into a dll Pin
Alan Balkany1-Oct-10 6:27
Alan Balkany1-Oct-10 6:27 
QuestionC2061 Compiler Error syntax error : identifier 'BOOL' Pin
timb7530-Sep-10 22:29
timb7530-Sep-10 22:29 
AnswerRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
CPallini30-Sep-10 22:59
mveCPallini30-Sep-10 22:59 
GeneralRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
Sauro Viti30-Sep-10 23:48
professionalSauro Viti30-Sep-10 23:48 
GeneralRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
CPallini1-Oct-10 2:23
mveCPallini1-Oct-10 2:23 
JokeRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
bleedingfingers1-Oct-10 2:26
bleedingfingers1-Oct-10 2:26 
GeneralRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
CPallini1-Oct-10 2:33
mveCPallini1-Oct-10 2:33 
JokeRe: C2061 Compiler Error syntax error : identifier 'BOOL' Pin
Sauro Viti1-Oct-10 3:39
professionalSauro Viti1-Oct-10 3:39 
QuestionC++ Rookie. Pin
forexsurfr30-Sep-10 20:27
forexsurfr30-Sep-10 20:27 

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.