Page 1 of 1

How I can pass pointer to C function ?

PostPosted: Mon Jan 11, 2010 8:05 am
by shri_fwh
Hi,

I have "C" function that needs to pass a pointer paramter of number ( dobule ) data type.
How I can pass pointer to C function ? I tried but its not working.

Procedure Call_C_Func

atmp := { 123123.12, 123123.1223, 12312312312.12312 }

c_wrap_func( atmp[1] )


HB_FUNC( c_wrap_func )
{

c_function( (double *) hb_parptr(1) ) ;

}

Please guide me. Thanks in advance.
Shridhar

Re: How I can pass pointer to C function ?

PostPosted: Mon Jan 11, 2010 8:09 am
by Enrico Maria Giordano
You are not passing a pointer. atmp[1] is not a pointer.

EMG

Re: How I can pass pointer to C function ?

PostPosted: Mon Jan 11, 2010 8:16 am
by shri_fwh
Hi,

Even below code is not working.

Procedure Call_C_Func

atmp := { 123123.12, 123123.1223, 12312312312.12312 }

c_wrap_func( @atmp[1] ) // passed as pointer.

HB_FUNC( c_wrap_func )
{

c_function( (double *) hb_parptr(1) ) ;

}

Thank
Shridhar

Re: How I can pass pointer to C function ?

PostPosted: Mon Jan 11, 2010 8:19 am
by Enrico Maria Giordano
Can you take the time to build a reduced and self-contained sample of the problem?

EMG

Re: How I can pass pointer to C function ?

PostPosted: Mon Jan 11, 2010 9:56 am
by nageswaragunupudi
This is a suggested code to achieve the purpose:
Code: Select all  Expand view
#include "FiveWin.Ch"

function Main()

   local a := { 1, 2 }

   c_wrapper( a )
   msginfo( a[ 1 ] )

return ( 0 )

#pragma BEGINDUMP

#include <hbapi.h>

void c_function( double * p )
{
   double x = 123.45;

   *( p ) = x;
}

HB_FUNC( C_WRAPPER )
{
   double n;

   n = hb_parnd( 1, 1 );
   c_function( &n );
   hb_stornd( n, 1, 1 );
   hb_ret();
}

#pragma ENDDUMP
 

Re: How I can pass pointer to C function ?

PostPosted: Tue Jan 12, 2010 6:16 am
by shri_fwh
Thanks Mr. Rao,

Its working now.

Thanks
Shridhar