Click here to Skip to main content
15,918,889 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Dialog help needed Pin
BlitzPackage12-Nov-06 15:04
BlitzPackage12-Nov-06 15:04 
Questionmshflexgrid problem Pin
Tarek Jabri12-Nov-06 3:22
Tarek Jabri12-Nov-06 3:22 
AnswerRe: mshflexgrid problem Pin
S Douglas13-Nov-06 21:59
professionalS Douglas13-Nov-06 21:59 
QuestionMalloc fails...why? Pin
damir_tk12-Nov-06 2:30
damir_tk12-Nov-06 2:30 
AnswerRe: Malloc fails...why? Pin
Taka Muraoka12-Nov-06 2:36
Taka Muraoka12-Nov-06 2:36 
AnswerRe: Malloc fails...why? Pin
Waldermort12-Nov-06 4:22
Waldermort12-Nov-06 4:22 
GeneralRe: Malloc fails...why? Pin
damir_tk12-Nov-06 9:50
damir_tk12-Nov-06 9:50 
AnswerRe: Malloc fails...why? Pin
Mark Salsbery12-Nov-06 8:33
Mark Salsbery12-Nov-06 8:33 
I would recommend looking VERY closely at all the string functions you use.
Some use/return lengths in characters. Some use/return lengths in bytes.
Some include NULL terminator in lengths. Some do not.
LPTSTR FileHelper::GetFileFullPath( LPWSTR lpwName )
{
	LPTSTR lptFileFullPath;

	DWORD LenInChars = GetCurrentDirectory( 0, NULL );

	++LenInChars; // add 1 for NULL terminator

	LPWSTR lpwFolder;
	lpwFolder = (LPWSTR) malloc( LenInChars * sizeof(TCHAR) );

	if ( lpwFolder == NULL )
	{
		return NULL; // or throw new CIScrewedUpException();
	}

	if ( GetCurrentDirectory( LenInChars, lpwFolder ) != 0 )
	{
		// added 1 for NULL terminator
		LenInChars = (DWORD) ( wcslen( lpwFolder ) + wcslen( lpwName ) + 1 );

		lptFileFullPath = (LPTSTR) malloc( LenInChars * sizeof(TCHAR));

		// Here lptFileFullPath simply evaluates to NULL, showing the ?!
		if ( lptFileFullPath == NULL )
		{
			// prevent memory leak
			free( lpwFolder );
			return NULL;
		}

		// ...the rest of the code stripped off...
	}

	// prevent memory leak
	free( lpwFolder );

	return lptFileFullPath;
}

*EDIT* And for goodness sakes, use new/delete instead of malloc/free!!! Smile | :)
GeneralRe: Malloc fails...why? Pin
damir_tk12-Nov-06 9:55
damir_tk12-Nov-06 9:55 
GeneralRe: Malloc fails...why? Pin
Mark Salsbery12-Nov-06 10:27
Mark Salsbery12-Nov-06 10:27 
GeneralRe: Malloc fails...why? Pin
damir_tk12-Nov-06 10:42
damir_tk12-Nov-06 10:42 
Questionproblem with colour the radio & check box in property page [modified] Pin
vikas amin12-Nov-06 0:54
vikas amin12-Nov-06 0:54 
AnswerRe: problem with colour the radio & check box in property page Pin
Rajesh R Subramanian12-Nov-06 19:39
professionalRajesh R Subramanian12-Nov-06 19:39 
GeneralRe: problem with colour the radio & check box in property page Pin
vikas amin12-Nov-06 20:21
vikas amin12-Nov-06 20:21 
GeneralRe: problem with colour the radio & check box in property page Pin
Rajesh R Subramanian12-Nov-06 20:43
professionalRajesh R Subramanian12-Nov-06 20:43 
GeneralRe: problem with colour the radio & check box in property page Pin
vikas amin12-Nov-06 21:14
vikas amin12-Nov-06 21:14 
Question"How can I pass jbyte * from C++ to VB" Pin
Orchid8512-Nov-06 0:46
Orchid8512-Nov-06 0:46 
Questioninterface in background Pin
Johpoke12-Nov-06 0:42
Johpoke12-Nov-06 0:42 
AnswerRe: interface in background Pin
Sceptic Mole12-Nov-06 6:16
Sceptic Mole12-Nov-06 6:16 
AnswerRe: interface in background Pin
Mike_V12-Nov-06 15:10
Mike_V12-Nov-06 15:10 
GeneralRe: interface in background Pin
Johpoke13-Nov-06 8:17
Johpoke13-Nov-06 8:17 
GeneralRe: interface in background Pin
Mike_V13-Nov-06 8:43
Mike_V13-Nov-06 8:43 
GeneralRe: interface in background Pin
Johpoke13-Nov-06 8:51
Johpoke13-Nov-06 8:51 
GeneralRe: interface in background Pin
Johpoke13-Nov-06 8:52
Johpoke13-Nov-06 8:52 
GeneralRe: interface in background Pin
Mike_V13-Nov-06 12:20
Mike_V13-Nov-06 12:20 

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.