Hello Shum,

On Mar 28, 2010, at 1:23 AM, Teo Fonrouge wrote:

> Hello Shum,
> 
> On Mar 27, 2010, at 11:05 PM, Shum wrote:
> 
>> 
>> Hi Teo,
>> 
>>> HB_FUNC( POINTER2STRING )
>>> {
>>>     PHB_ITEM p = hb_param( 1, HB_IT_POINTER );
>>>     PHB_ITEM n = hb_param( 2, HB_IT_NUMERIC );
>>> 
>>>     if( p && n )
>>>     {
>>>             PHB_ITEM s = hb_itemNew( NULL );
>>>             hb_itemPutCL( s, hb_itemGetPtr( p ), hb_itemGetNI( n ) );
>>>             hb_itemReturnRelease( s );
>>>     }
>>> }
>> 
>> It seems that POINTER2STRING had to pass 2 parameters.
>> Because i donot know the length of the return string....
>> Can I pass NIL to the 2nd parameter? and just obtain the string ?
> 
> <prg>
> HB_FUNC( POINTER2STRING )
> {
>       PHB_ITEM p = hb_param( 1, HB_IT_POINTER );
>       
>       if( p )
>       {
>               PHB_ITEM s = hb_itemNew( NULL );
>               hb_itemPutCL( s, hb_itemGetPtr( p ), hb_pcount() > 1 ? 
> hb_itemGetNI( hb_param( 2, HB_IT_NUMERIC ) ) : strlen( hb_itemGetPtr( p ) ) );
>               hb_itemReturnRelease( s );
>       }
> 
> }
> </prg>


This is a better one ( having a good time with beer & friends ) accepts 
2nd parameter only if it is numeric:

HB_FUNC( POINTER2STRING )
{
        PHB_ITEM p = hb_param( 1, HB_IT_POINTER );
        
        if( p )
        {
                PHB_ITEM s = hb_itemNew( NULL );
                PHB_ITEM n = hb_param( 2, HB_IT_NUMERIC );
                hb_itemPutCL( s, hb_itemGetPtr( p ), n ? hb_itemGetNI( n ) : 
strlen( hb_itemGetPtr( p ) ) );
                hb_itemReturnRelease( s );
        }

}


best regards,

Teo

_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
Harbour@harbour-project.org
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to