Jump to content
Fivewin Brasil

Como executar uma função em xHarbour a partir do codigo em C


emotta

Recommended Posts

Com o xHarbour eu consigo escrever uma função em C e executar ela normalmente. Porem preciso do inverso, ou seja, no codigo em C executar uma função escrita em xHarbour. Como fazer?

Exemplo:

Function Main()
Fun_C()  // aqui executo a funcao em C
Return

Function calchrb()
Return 1

#pragma begindump

#include <windows.h>
#include <stdlib.h>
#include "hbapi.h"


HB_FUNC( FUN_C ) 
{
int x;

x = calchrb(); // aqui executo a função em xHarbour a partir do codigo C

} 

#pragma enddump

Link to comment
Share on other sites

é muito simples, veja:

#include "inkey.ch"function main()  CTRL_HANDLE_CONSOLE()    IF FILE("cliente.dbf") == .F.    aDB := { { "Codigo", "N", 3, 0 }, { "Nome", "C", 50, 0 } }    DbCreate( "clientes", aDB )  ENDIF    USE Clientes EXCLUSIVE NEW    while .t.    tk := inkey(0,INKEY_ALL)    if tk==27 .and. nextkey()==0        minha_funcao()    endif  endreturn nilfunction minha_funcao()  ? "Fechando tudoooo!!!"  CLOSE ALL  QUITreturn nil#pragma BEGINDUMP#include "hbapi.h"#include "hbinit.h"#include "hbvm.h"#include HB_FUNC_EXTERN( MINHA_FUNCAO );  // define como função externaint WINAPI closeHandler(DWORD Evento){   switch (Evento)   {   case CTRL_CLOSE_EVENT:    MessageBox(NULL, "Vc clicou no X", "Eba Oba!!", MB_OK);    HB_FUNC_EXEC( MINHA_FUNCAO );   // chamada da função HARBOUR      return 0;   }   return 1;}HB_FUNC( CTRL_HANDLE_CONSOLE ){  SetConsoleCtrlHandler(closeHandler, 1);}#pragma ENDDUMP
Link to comment
Share on other sites

Obrigado... Só pra registrar tem esta solução também...

http://forums.fivetechsupport.com/viewtopic.php?p=66183#p66183


    function Main()

       MsgInfo( Test() )

    return nil

    function Another( cValue )

       MsgInfo( cValue )

    return "returned from high level"

    #pragma BEGINDUMP

    #include <hbapi.h>
    #include <hbvm.h>

    HB_FUNC( TEST )
    {
       // We build the virtual machine stack frame

       hb_vmPushSymbol( hb_dynsymGetSymbol( "ANOTHER" ) ); // we push the symbol of the function to call
       hb_vmPushNil(); // we push nil for a function, a codeblock for Eval, an object for a method
       hb_vmPushString( "High level access from low level", strlen( "High level access from low level" ) );
       hb_vmFunction( 1 ); // 1 --> number of supplied parameters
       
       // the returned value can be accessed using hb_stackReturnItem() --> PHB_ITEM
       // or simply calling hb_par...( -1 );
    }

    #pragma ENDDUMP
     
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...