emotta Posted July 24, 2014 Report Share Posted July 24, 2014 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 Quote Link to comment Share on other sites More sharing options...
bencz Posted July 25, 2014 Report Share Posted July 25, 2014 é 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 Quote Link to comment Share on other sites More sharing options...
emotta Posted July 25, 2014 Author Report Share Posted July 25, 2014 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 Quote Link to comment Share on other sites More sharing options...
alex2002 Posted July 25, 2014 Report Share Posted July 25, 2014 Ta vendo. O "C" acabando fazendo o xHarbour ficar muuuuuuuiiiiiiiiiiittttttttttooooooooo poderoso e isso é muito bom. kapiaba 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.