Hi Przemek


Przemyslaw Czerpak-2 wrote:
> 
>    #if !defined( StringCchCat )
>       #ifdef UNICODE
>          #define StringCchCat(d,n,s)   hb_wcnCpy( (d), (s), (n) - 1 )
>       #else
>          #define StringCchCat(d,n,s)   hb_strnCpy( (d), (s), (n) - 1 )
>       #endif
>    #endif
> 

To test everything I did as:

#if !defined( StringCchCat )
   #ifdef UNICODE
      #define StringCchCat(d,n,s)   hb_wcncpy( (d), (s), (n) - 1 )
   #else
      #define StringCchCat(d,n,s)   hb_xstrncpy( (d), (s), (n) - 1 )
   #endif
#endif

//  Copied from harbour/source/rtl/hbstr.c and renamed.

/*
 * This function copies szText to destination buffer.
 * NOTE: Unlike the documentation for strncpy, this routine will always
append
 *       a null
 */
char * hb_xstrncpy( char * pDest, const char * pSource, ULONG ulLen )
{
   char *pBuf = pDest;

   pDest[ ulLen ] ='\0';

   while( ulLen && ( *pDest++ = *pSource++ ) != '\0' )
      ulLen--;

   while( ulLen-- )
      *pDest++ = '\0';

   return pBuf;
}


wchar_t *hb_wcncpy( wchar_t *dstW, const wchar_t *srcW, unsigned long ulLen
)
{
   ULONG ulDst, ulSrc;

   dstW[ ulLen ] = 0;
   ulDst = lstrlenW( dstW );
   if( ulDst < ulLen )
   {
      ulSrc = lstrlenW( srcW );
      if( ulDst + ulSrc > ulLen )
         ulSrc = ulLen - ulDst;
      memcpy( &dstW[ ulDst ], srcW, ulSrc * sizeof( wchar_t ) );
      dstW[ ulDst + ulSrc ] = 0;
   }
   return dstW;
}


Then test performed on :

      TCHAR szLibName[ MAX_PATH + 1 ] = { 0 };

      GetSystemDirectory( szLibName, MAX_PATH );

      StringCchCat( szLibName, MAX_PATH + 1, TEXT( "\\atl.dll" ) );

      hLib = LoadLibrary( szLibName );

UNICODE compile is perfect. No errors.

Normal compile GPF's. How do I detect what is wrong? 

Regards

-- 
View this message in context: 
http://www.nabble.com/C-and-Unicode-compliant-string-conversions-tp20721945p20724830.html
Sent from the Harbour - Dev mailing list archive at Nabble.com.

_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to