Stratos: Punto de Encuentro de Desarrolladores

¡Bienvenido a Stratos!

Acceder

Foros





Ayuda con función....

Iniciado por SkyNetBCN, 12 de Julio de 2006, 08:36:13 AM

« anterior - próximo »

SkyNetBCN

Alguien me puede indicar un ejemplo válido de "WideCharToMultiByte"??

Lo he intentado utilizar pero nunca me ha funcionado a la hora de pasar un WCHAR[260] a un tipo MultiByte.

Alguien me puede ayudar?
Gracias de antemano

vincent

Ejemplos sacados de la dxutil de DX:


//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToWideCch()
// Desc: This is a UNICODE conversion utility to convert a CHAR string into a
//       WCHAR string.
//       cchDestChar is the size in TCHARs of wstrDestination.  Be careful not to
//       pass in sizeof(strDest)
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertAnsiStringToWideCch( WCHAR* wstrDestination, const CHAR* strSource,
                                    int cchDestChar )
{
   if( wstrDestination==NULL || strSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;

   int nResult = MultiByteToWideChar( CP_ACP, 0, strSource, -1,
                                      wstrDestination, cchDestChar );
   wstrDestination[cchDestChar-1] = 0;
   
   if( nResult == 0 )
       return E_FAIL;
   return S_OK;
}




//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertWideStringToAnsi()
// Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
//       CHAR string.
//       cchDestChar is the size in TCHARs of strDestination
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertWideStringToAnsiCch( CHAR* strDestination, const WCHAR* wstrSource,
                                    int cchDestChar )
{
   if( strDestination==NULL || wstrSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;

   int nResult = WideCharToMultiByte( CP_ACP, 0, wstrSource, -1, strDestination,
                                      cchDestChar*sizeof(CHAR), NULL, NULL );
   strDestination[cchDestChar-1] = 0;
   
   if( nResult == 0 )
       return E_FAIL;
   return S_OK;
}




//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertGenericStringToAnsi()
// Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
//       CHAR string.
//       cchDestChar is the size in TCHARs of strDestination
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource,
                                          int cchDestChar )
{
   if( strDestination==NULL || tstrSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;

#ifdef _UNICODE
   return DXUtil_ConvertWideStringToAnsiCch( strDestination, tstrSource, cchDestChar );
#else
   strncpy( strDestination, tstrSource, cchDestChar );
   strDestination[cchDestChar-1] = '\0';
   return S_OK;
#endif  
}




//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertGenericStringToWide()
// Desc: This is a UNICODE conversion utility to convert a TCHAR string into a
//       WCHAR string.
//       cchDestChar is the size in TCHARs of wstrDestination.  Be careful not to
//       pass in sizeof(strDest)
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertGenericStringToWideCch( WCHAR* wstrDestination, const TCHAR* tstrSource,
                                          int cchDestChar )
{
   if( wstrDestination==NULL || tstrSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;

#ifdef _UNICODE
   wcsncpy( wstrDestination, tstrSource, cchDestChar );
   wstrDestination[cchDestChar-1] = L'\0';
   return S_OK;
#else
   return DXUtil_ConvertAnsiStringToWideCch( wstrDestination, tstrSource, cchDestChar );
#endif    
}




//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToGeneric()
// Desc: This is a UNICODE conversion utility to convert a CHAR string into a
//       TCHAR string.
//       cchDestChar is the size in TCHARs of tstrDestination.  Be careful not to
//       pass in sizeof(strDest) on UNICODE builds
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertAnsiStringToGenericCch( TCHAR* tstrDestination, const CHAR* strSource,
                                          int cchDestChar )
{
   if( tstrDestination==NULL || strSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;
       
#ifdef _UNICODE
   return DXUtil_ConvertAnsiStringToWideCch( tstrDestination, strSource, cchDestChar );
#else
   strncpy( tstrDestination, strSource, cchDestChar );
   tstrDestination[cchDestChar-1] = '\0';
   return S_OK;
#endif    
}




//-----------------------------------------------------------------------------
// Name: DXUtil_ConvertAnsiStringToGeneric()
// Desc: This is a UNICODE conversion utility to convert a WCHAR string into a
//       TCHAR string.
//       cchDestChar is the size in TCHARs of tstrDestination.  Be careful not to
//       pass in sizeof(strDest) on UNICODE builds
//-----------------------------------------------------------------------------
HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource,
                                          int cchDestChar )
{
   if( tstrDestination==NULL || wstrSource==NULL || cchDestChar < 1 )
       return E_INVALIDARG;

#ifdef _UNICODE
   wcsncpy( tstrDestination, wstrSource, cchDestChar );
   tstrDestination[cchDestChar-1] = L'\0';    
   return S_OK;
#else
   return DXUtil_ConvertWideStringToAnsiCch( tstrDestination, wstrSource, cchDestChar );
#endif
}
Desarrollo en .Net y metodologías http://devnettips.blogspot.com






Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.