i dont know why this is showing up as a mempry leak.
HRESULT NarrowString( const wchar_t* String, char** dest )
{
if( String == TNULL )
return E_INVALIDARG;
char* temp = TNULL;
int lenW = lstrlenW( String );
int lenA = ::WideCharToMultiByte( CP_ACP, 0, String, lenW, TNULL, 0, TNULL, nullptr );
if ( lenA > 0)
{
temp = TNEW char[ lenA + 1 ]; // allocate a final null terminator as well
::WideCharToMultiByte( CP_ACP, 0, String, lenW, temp, lenA, TNULL, TNULL );
temp[ lenA ] = 0; // Set the null terminator yourself
}
else
{
// handle the error
DWORD dwError = GetLastError();
return HRESULT_FROM_WIN32( dwError );
}
*dest = TNEW char[ lenA + 1 ];
memmove( *dest, temp, lenA + 1 );
temp = TNULL;
return S_OK;
}
also why do does this only work if "dest" is a double pointer ?
because when i try it as a single pointer "dest" is shown up as a bad pointer.
the reason why i dont know why this is causing the leak is because i append the resulting char array to a std::string.
this is how im appending the string
HRESULT NarrowString( const std::wstring* String, std::string* dest )
{
if( String == nullptr )
return E_INVALIDARG;
char* narrow = TNULL;
HRESULT hr = TIPNarrowString( String->c_str(), &narrow );
if( FAILED( hr ) )
return hr;
dest->clear();
dest->append( narrow );
return S_OK;
}
Thanks In Advance.
This post has been edited by ryan20fun: 10 November 2011 - 05:38 AM

New Topic/Question
Reply




MultiQuote







|