Calling harbour function from c function

668 views
Skip to first unread message

Franček Prijatelj

unread,
Sep 21, 2015, 8:32:34 AM9/21/15
to Harbour Users
Hi

Can anybody show me how to call simple harbour function  from c function.
(other way calling c func from hrb func is no problem):

t1.prg

FUNCTION double(n)
RETURN 2*n


t2.c  

int myFunc() {
   int inp,out;
 
   // how to pass inp to function, and how to get result back to out
   HB_FUN_DOUBLE();
}

thanks




Massimo Belgrano

unread,
Sep 21, 2015, 8:53:02 AM9/21/15
to harbou...@googlegroups.com

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Massimo Belgrano
Delta Informatica S.r.l. (Cliccami per scoprire 

Franček Prijatelj

unread,
Sep 21, 2015, 10:30:11 AM9/21/15
to Harbour Users
Hi Massimo

It's nice manual, but it's only about calling c functions from harbour, which is a no problem to me as I said allready.
I have  writen some "wrappers" for Harbour . The last one is mongoDb wrapper for Harbour. So I have some
expirience in using it.

 


This  is maybe closser.
But I need statical linking and a very simple sample ( or maybe info about which appi to use).
In the former case I'am using extension appi (hb_parc,hb_parni,hb_retni,hb_retc.......)
Which api is working in oposite way (using harbour functions from c)?

regards

Massimo Belgrano

unread,
Sep 21, 2015, 10:54:01 AM9/21/15
to harbou...@googlegroups.com
afaik if harbour produce exe you can't call from c
also if is possible write your wrapper from command line
sorry but I not have any sample


--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Franček Prijatelj

unread,
Sep 21, 2015, 11:29:38 AM9/21/15
to Harbour Users

He

To be more specific.
My main program is written in C.
I would like to know how to initialize HB virtual machine in it and call some functions
which are written in Harbour and staticaljy linked to my program.

regards

Влад Ермаков

unread,
Sep 23, 2015, 4:28:03 AM9/23/15
to harbou...@googlegroups.com
Hi, Franček


Something like this (a simplified excerpt from my working code):

// Harbour function
Function StrMerge(cString1, cString2)
Local cOutStr
  cOutStr := cString1+cString2
Return cOutStr

// C function
#include <hbapi.h>
#include <hbvm.h>
#include <hbapiitm.h>

char  testfunc(  char *c_s1,    char *c_s2)
    PHB_ITEM pResult;
    char *sResult;

{
       hb_vmInit( 0 );  /* Don't execute first linked symbol */
                PHB_ITEM pItem1 = hb_itemPutC( NULL, c_s1 );
                PHB_ITEM pItem2 = hb_itemPutC( NULL, c_s2 );
                char * HbFuncName  = "STRMERGE";
                pResult = hb_itemDoC( HbFuncName, 2,  (PHB_ITEM) pItem1 ,  (PHB_ITEM) pItem2 , 0 );
        sResult = hb_itemGetC( pResult );
                hb_itemRelease( pItem2 );
                hb_itemRelease( pItem1 );
    return sResult ;
}
//--------------

Regards

--

Ábel Farkas

unread,
Oct 3, 2018, 7:20:22 AM10/3/18
to Harbour Users
Can you tell me how can i compile this code?
I tried it whit hbmk2 but doesn't do anything ecxept that log: Unrecoverable error 9012: Can't locate the starting procedure: 'MAIN'
I vas unable to compile whit gcc either
Reply all
Reply to author
Forward
0 new messages