How I can pass pointer to C function ?

How I can pass pointer to C function ?

Postby shri_fwh » Mon Jan 11, 2010 8:05 am

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
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How I can pass pointer to C function ?

Postby Enrico Maria Giordano » Mon Jan 11, 2010 8:09 am

You are not passing a pointer. atmp[1] is not a pointer.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8398
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How I can pass pointer to C function ?

Postby shri_fwh » Mon Jan 11, 2010 8:16 am

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
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm

Re: How I can pass pointer to C function ?

Postby Enrico Maria Giordano » Mon Jan 11, 2010 8:19 am

Can you take the time to build a reduced and self-contained sample of the problem?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8398
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: How I can pass pointer to C function ?

Postby nageswaragunupudi » Mon Jan 11, 2010 9:56 am

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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10317
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How I can pass pointer to C function ?

Postby shri_fwh » Tue Jan 12, 2010 6:16 am

Thanks Mr. Rao,

Its working now.

Thanks
Shridhar
Thanks
Shridhar
FWH 19.12, BCC 7 32 bit, MariaDB
shri_fwh
 
Posts: 301
Joined: Mon Dec 07, 2009 2:49 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 135 guests