Click here to Skip to main content
15,894,122 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: File creation date and time Pin
bleedingfingers12-Oct-10 21:55
bleedingfingers12-Oct-10 21:55 
GeneralRe: File creation date and time Pin
CPallini12-Oct-10 22:01
mveCPallini12-Oct-10 22:01 
AnswerRe: File creation date and time Pin
Sauro Viti12-Oct-10 21:32
professionalSauro Viti12-Oct-10 21:32 
GeneralRe: File creation date and time Pin
john563212-Oct-10 23:23
john563212-Oct-10 23:23 
GeneralRe: File creation date and time Pin
Sauro Viti12-Oct-10 23:35
professionalSauro Viti12-Oct-10 23:35 
QuestionHow to hide the RibbonButton???? [modified] Pin
kwanghee choi12-Oct-10 20:10
kwanghee choi12-Oct-10 20:10 
AnswerRe: How to hide the RibbonButton???? Pin
Code-o-mat13-Oct-10 5:02
Code-o-mat13-Oct-10 5:02 
Questionsscanf_s invalidating pointers. Need help Pin
Hipcrostino12-Oct-10 20:03
Hipcrostino12-Oct-10 20:03 
Hi,

Normally I can figure this stuff out, but not this one. I have just upgraded my program from VC6 to VS 2010. Quite a jump. It allows me to do things like actually debug now which is fantastic. Anyway, I have found a problem that I do not understand.

Basically there is a function (which I did not code originally) that is used to convert a hex string into a binary buffer.
ULONG util_ConvertHexStringToBin(char *pszHexString, void *pBinaryBuffer, unsigned int uiBufferSize)
{	//Parses the contents of the null terminated text string representing a hexidecimal value, and converts
	//each pair of hex digits as a byte.  The function will convert no more than uiBufferSize bytes worth
	//of hex digits and will also terminate when all hex digit pairs have been parsed.
	//Returns the size of the resulting binary block
	unsigned int	uiHexPairs;
	unsigned int	uiByteIndex;
	char			*pszParse = NULL;
	BYTE			ucTempByte;

	
	uiHexPairs = strlen(pszHexString)/2; //String length divided by 2
	pszParse = pszHexString;

	uiByteIndex = 0;

	//Loop while still HEX pairs to parse and still bytes to fill in Buffer
	while (uiByteIndex < uiBufferSize && uiByteIndex < uiHexPairs)
	{
	    sscanf_s(pszParse, "%2x", &ucTempByte);
	   ((BYTE *)pBinaryBuffer)[uiByteIndex] = ucTempByte;
		pszParse += 2; //Advance string parse pointer 
		uiByteIndex++; //Advance byte index within buffer
	}
		
	return uiByteIndex;
}


The problem is, as soon as sscanf_s is called, pszParse becomes invalid. I've seen other strange things too, like the uiByteIndex being reset to 0 when calling sscanf_s. I have tried sscanf as well with the same results.

The problem this is at the edge of my c++ knowledge. Its acting like the memory where these varables are stored is free and being overwritten, but this shouldn't be the case. I'm getting different results all the time with this function and this worries me a lot!

Any help, or suggestion on where to look for help would be appreciated.
AnswerRe: sscanf_s invalidating pointers. Need help Pin
Cedric Moonen12-Oct-10 20:22
Cedric Moonen12-Oct-10 20:22 
GeneralRe: sscanf_s invalidating pointers. Need help Pin
Hipcrostino12-Oct-10 20:32
Hipcrostino12-Oct-10 20:32 
GeneralRe: sscanf_s invalidating pointers. Need help Pin
Cedric Moonen12-Oct-10 20:49
Cedric Moonen12-Oct-10 20:49 
GeneralRe: sscanf_s invalidating pointers. Need help Pin
Hipcrostino13-Oct-10 12:43
Hipcrostino13-Oct-10 12:43 
QuestionHow to pass generic pointer to function with void** parameter? Pin
Chesnokov Yuriy12-Oct-10 20:02
professionalChesnokov Yuriy12-Oct-10 20:02 
AnswerRe: How to pass generic pointer to function with void** parameter? Pin
CPallini12-Oct-10 21:00
mveCPallini12-Oct-10 21:00 
QuestionRe: How to pass generic pointer to function with void** parameter? Pin
Chesnokov Yuriy12-Oct-10 21:16
professionalChesnokov Yuriy12-Oct-10 21:16 
AnswerRe: How to pass generic pointer to function with void** parameter? PinPopular
CPallini12-Oct-10 21:26
mveCPallini12-Oct-10 21:26 
AnswerRe: How to pass generic pointer to function with void** parameter? Pin
Chesnokov Yuriy12-Oct-10 21:42
professionalChesnokov Yuriy12-Oct-10 21:42 
QuestionTiff FIle in Frame Window Pin
002comp12-Oct-10 19:29
002comp12-Oct-10 19:29 
QuestionCan WM_VSCROLL generate WM_MOUSEMOVE messages? Pin
old_hacker12-Oct-10 19:00
old_hacker12-Oct-10 19:00 
AnswerRe: Can WM_VSCROLL generate WM_MOUSEMOVE messages? Pin
mesajflaviu12-Oct-10 20:04
mesajflaviu12-Oct-10 20:04 
GeneralRe: Can WM_VSCROLL generate WM_MOUSEMOVE messages? Pin
old_hacker13-Oct-10 19:41
old_hacker13-Oct-10 19:41 
Questionhow to use code written in C# in Managed C++ (VC++.NET) Project? Pin
AmbiguousName12-Oct-10 9:04
AmbiguousName12-Oct-10 9:04 
AnswerRe: how to use code written in C# in Managed C++ (VC++.NET) Project? Pin
Luc Pattyn12-Oct-10 9:54
sitebuilderLuc Pattyn12-Oct-10 9:54 
GeneralRe: how to use code written in C# in Managed C++ (VC++.NET) Project? Pin
AmbiguousName12-Oct-10 10:49
AmbiguousName12-Oct-10 10:49 
GeneralRe: how to use code written in C# in Managed C++ (VC++.NET) Project? Pin
Luc Pattyn12-Oct-10 10:54
sitebuilderLuc Pattyn12-Oct-10 10:54 

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.