On Thu, 11 Feb 2010, jara...@users.sourceforge.net wrote: Hi Xavi,
> 2010-02-11 04:25 UTC+0100 Xavi (jarabal/at/gmail.com) > * contrib/hbwin/wapi_winbase.c > + Added wapi_GETSHORTPATHNAME() Thank you very much. Just only few notes. WAPI_* functions should be as closed to original implementation as possible. We can introduce some small extensions and parameter validation (it's even suggested) using additional information we have due to Harbour item types but we should not change or ignore valid parameters. In this case passing 0 as 3-rd parameter is ignored Also the buffer is 1 or 3 in UNICODE mode bytes greater then request by user. If programmer not precisely check the implementation details then he can be seriously confused by the results. If wapi_GETSHORTPATHNAME() supports the following parameters: wapi_GETSHORTPATHNAME( <cLongName> [, @<shortName> [, <nMaxSize> ] ] ) -> < nShortLenght> then the implementation should follow it. I also suggest to eliminate double call to GetShortPathName() if possible. In some cases it can be quite expensive i.e. network volumes. Below is your code a little bit modified to respect above conditions. I think that we should add also wapi_GETLONGPATHNAME() and wapi_GETFULLPATHNAME() Can you implement them too? best regards, Przemek HB_FUNC( WAPI_GETSHORTPATHNAME ) { void * hLongPath; DWORD length = 0; LPCTSTR lpszLongPath = HB_PARSTR( 1, &hLongPath, NULL ); if( lpszLongPath ) { if( HB_ISBYREF( 2 ) ) { TCHAR buffer[ HB_PATH_MAX ]; DWORD cchBuffer = ( DWORD ) HB_SIZEOFARRAY( buffer ); LPTSTR lpszShortPath = buffer; HB_BOOL fSize = HB_ISNUM( 3 ); if( fSize ) /* the size of buffer is limited by user */ { cchBuffer = ( DWORD ) hb_parnl( 3 ); if( cchBuffer == 0 ) lpszShortPath = NULL; else if( cchBuffer > ( DWORD ) HB_SIZEOFARRAY( buffer ) ) lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) ); } length = GetShortPathName( lpszLongPath, lpszShortPath, cchBuffer ); if( !fSize && length > cchBuffer ) /* default buffer size was too small */ { cchBuffer = length; lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) ); length = GetShortPathName( lpszLongPath, lpszShortPath, cchBuffer ); } hbwapi_SetLastError( GetLastError() ); HB_STORSTRLEN( lpszShortPath, length > cchBuffer ? 0 : length, 2 ); if( lpszShortPath && lpszShortPath != buffer ) hb_xfree( lpszShortPath ); } else { length = GetShortPathName( lpszLongPath, NULL, 0 ); hbwapi_SetLastError( GetLastError() ); } } hb_retnl( length ); hb_strfree( hLongPath ); } _______________________________________________ Harbour mailing list (attachment size limit: 40KB) Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour