Page 1 of 1

Export a variable from C to Clipper

PostPosted: Tue Aug 26, 2014 5:59 pm
by jgayoso
Hearing, as I can export a variable from a routine application of C to Clipper

I want to do the same thing:

            USE MYTABLE
            ? MYCAMPO1

but:
            fMyFunc_C ()
            ? MYCAMPO1

where:

# Pragma BEGINDUMP

          HB_FUNC (fMyFunc_C)
                  {
                       char MYCAMPO1 = 'HELLO';
                  }
# Pragma ENDDUMP




That fMyFunc to invoke () function is initialized and recognize the variable MYCAMPO1

Re: Export a variable from C to Clipper

PostPosted: Thu Aug 28, 2014 1:08 pm
by bpd2000
Code: Select all  Expand view
/* Código Harbour */
REQUEST HB_GT_WIN_DEFAULT
Function Main()
? Hola()
WAIT
RETURN NIL
/* Código C */
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
HB_FUNC( HOLA )
{
hb_retc( "Hola Mundo" );
}
#pragma ENDDUMP

Re: Export a variable from C to Clipper

PostPosted: Tue Sep 02, 2014 1:36 pm
by jgayoso
That's not what I want to do:

The idea is to simulate:

use mitabla
?micampo

how come:

fMiFuntion()
?myvar

where myvar is defined in fmifunction public or static





bpd2000 wrote:
Code: Select all  Expand view
/* Código Harbour */
REQUEST HB_GT_WIN_DEFAULT
Function Main()
? Hola()
WAIT
RETURN NIL
/* Código C */
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"
HB_FUNC( HOLA )
{
hb_retc( "Hola Mundo" );
}
#pragma ENDDUMP

Re: Export a variable from C to Clipper

PostPosted: Wed Sep 03, 2014 9:56 am
by Antonio Linares
Jorge,

As I answered you by email that this code is what you need:

Code: Select all  Expand view
# pragma BEGINDUMP

#include <hbapi.h>

char * pszChar = "";

HB_FUNC (FMI_C)
{
   if( hb_pcount() > 0 ) // cambiar el contenido de la variable
   {
      if( pszChar )
         hb_xfree( pszChar )

      pszChar = ( char * ) hb_xgrab( strlen( hb_parc( 1 ) ) + 1 );
      strcpy( pszChar, hb_parc( 1 ) );
   }
   else   // obtener el valor de la variable
      hb_retc( pszChar );
}

# pragma ENDDUMP