I am trying to debug a c++ windows service when the following exception is thrown (only in debug mode, in realse the exception is not thrown): "Exception thrown at 0x00007FF75127C410 in xxxxxxxx.exe: 0xC0000005: Access violation writing location 0x0000018818AF3000".
Importent note: the code worked for me before but probably some workspace changes has corrupted it. when it worked i was developing in VS 17 i have recentlly changed the IDE to VS 19. when the problem occured i have tried to go back to VS 17 but it didnt work.
EDIT:
USHORT logFileHeaderVersion;
DLLS_CHECK_MODE eDllCheckMode;
LONGLONG lastClientTimeZValue;
LONGLONG lastServerClientTimeDelta;
wstring computerName;
string macAddresses;
BYTE* buffer;
DWORD dwBytesToWrite = 0;
DWORD dwBytesWritten = 0;
logFileHeaderVersion = LOG_FILE_HEADER_VERSION;
eDllCheckMode = getConfigurationManager()->getDllsCheckMode();
lastClientTimeZValue = Globals::getLastClientTimeZValue();
lastServerClientTimeDelta = Globals::getLastServerClientTimeDelta();
computerName = getComputerName();
macAddresses = getMacAddresses();
// Convert time delta values from ticks to milliseconds.
lastClientTimeZValue = lastClientTimeZValue / MILLISECOND_IN_TICKS;
lastServerClientTimeDelta = lastServerClientTimeDelta / MILLISECOND_IN_TICKS;
// Determine header size.
dwBytesToWrite += 2; // Header-size size.
dwBytesToWrite += 2; // Header version size.
dwBytesToWrite += 1; // Mode size.
dwBytesToWrite += 8; // Client time Z value size.
dwBytesToWrite += 8; // Server client time delta size.
dwBytesToWrite += ( (computerName.size() + 1) * 2 ); // Computer name size (+ null terminator, wide string).
dwBytesToWrite += ( macAddresses.size() + 1 ); // Mac addresses size (+ null terminator).
// Allocate the header.
buffer = new BYTE[dwBytesToWrite];
// Fill the header.
*((USHORT*) (buffer + dwBytesWritten)) = (USHORT) dwBytesToWrite;
dwBytesWritten += 2;
*((USHORT*) (buffer + dwBytesWritten)) = logFileHeaderVersion;
dwBytesWritten += 2;
*((BYTE*) (buffer + dwBytesWritten)) = (BYTE) eDllCheckMode;
dwBytesWritten += 1;
*((LONGLONG*) (buffer + dwBytesWritten)) = lastClientTimeZValue;
dwBytesWritten += 8;
*((LONGLONG*) (buffer + dwBytesWritten)) = lastServerClientTimeDelta;
dwBytesWritten += 8;
wcscpy_s( (PWCHAR)(buffer + dwBytesWritten), dwBytesToWrite - dwBytesWritten, computerName.c_str());
dwBytesWritten += ( (computerName.size() + 1) * 2 );
The exception is thrown in the following line: i think its something to do with the usage of wstring. and maybe the RELEASE preforming some optimization that fix the problem in the DEBUG
wcscpy_s( (PWCHAR)(buffer + dwBytesWritten), dwBytesToWrite - dwBytesWritten, computerName.c_str());
User contributions licensed under CC BY-SA 3.0