FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How I can pass pointer to C function ?
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
How I can pass pointer to C function ?
Posted: Mon Jan 11, 2010 08: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 24.04, BCC 7 32 bit, MariaDB
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How I can pass pointer to C function ?
Posted: Mon Jan 11, 2010 08:09 AM

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

EMG

Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
Re: How I can pass pointer to C function ?
Posted: Mon Jan 11, 2010 08: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 24.04, BCC 7 32 bit, MariaDB
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: How I can pass pointer to C function ?
Posted: Mon Jan 11, 2010 08:19 AM

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

EMG

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How I can pass pointer to C function ?
Posted: Mon Jan 11, 2010 09:56 AM
This is a suggested code to achieve the purpose:
Code (fw): Select all Collapse
#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
Posts: 336
Joined: Mon Dec 07, 2009 02:49 PM
Re: How I can pass pointer to C function ?
Posted: Tue Jan 12, 2010 06:16 AM

Thanks Mr. Rao,

Its working now.

Thanks
Shridhar

Thanks

Shridhar

FWH 24.04, BCC 7 32 bit, MariaDB

Continue the discussion