// Using C++ with Harbour
// sample developed by FiveTech Software
function Main()
local oTest := Test() // We create a C++ object
XMSGINFO( TEST_IVALUE( oTest ) ) // We retrieve a C++ object data
return nil
#pragma BEGINDUMP
#include <hbapi.h>
class Sample
{
public:
int iValue;
Sample();
};
Sample::Sample()
{
iValue = 123;
}
HB_FUNC( TEST )
{
Sample * p = new Sample;
hb_retnl( ( unsigned long ) p );
}
HB_FUNC( TEST_IVALUE )
{
hb_retnl( ( ( Sample * ) hb_parnl( 1 ) )->iValue );
}
extern "C"
{
HB_FUN_MSGINFO( void );
}
HB_FUNC( XMSGINFO )
{
HB_FUN_MSGINFO();
}
#pragma ENDDUMP
1 VERSIONINFO
FILEVERSION 2, 52, 25
PRODUCTVERSION 2, 52, 25
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "Author", "Ing. Mario González\000"
VALUE "CompanyName", "Ideas & Desarrollos\000"
VALUE "FileDescription", "Bancos & Recursos\000"
VALUE "FileVersion", "rev.2.52.25 (build 07/06)\000"
VALUE "InternalName", "mgbyr\000"
VALUE "LegalCopyright", "I&D © 1989-2006\000"
VALUE "ProductName", "Bancos & Recursos\000"
VALUE "ProductVersion", "rev.2.52.25 (build 07/06)\000"
VALUE "OriginalFilename", "mgbyr.exe\000"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 2048, 1200
}
}
// Using C++ with Harbour
// sample developed by FiveTech Software
function Main()
local oTest := Test() // We create a C++ object
MsgInfo( TEST_IVALUE( oTest ) ) // We retrieve a C++ object data
return nil
#pragma BEGINDUMP
#include <hbapi.h>
class Sample
{
public:
int iValue;
Sample();
};
Sample::Sample()
{
iValue = 123;
}
HB_FUNC( TEST )
{
Sample * p = new Sample;
hb_retnl( ( unsigned long ) p );
}
HB_FUNC( TEST_IVALUE )
{
hb_retnl( ( ( Sample * ) hb_parnl( 1 ) )->iValue );
}
#pragma ENDDUMP
Antonio Linares wrote:Alex,
Puedes usar C++ siempre que llames a Borland C con el parámetro -P para forzar la compilación en C++. Aqui tienes un ejemplo:
- Code: Select all Expand view RUN
// Using C++ with Harbour
// sample developed by FiveTech Software
function Main()
local oTest := Test() // We create a C++ object
XMSGINFO( TEST_IVALUE( oTest ) ) // We retrieve a C++ object data
return nil
#pragma BEGINDUMP
#include <hbapi.h>
class Sample
{
public:
int iValue;
Sample();
};
Sample::Sample()
{
iValue = 123;
}
HB_FUNC( TEST )
{
Sample * p = new Sample;
hb_retnl( ( unsigned long ) p );
}
HB_FUNC( TEST_IVALUE )
{
hb_retnl( ( ( Sample * ) hb_parnl( 1 ) )->iValue );
}
extern "C"
{
HB_FUN_MSGINFO( void );
}
HB_FUNC( XMSGINFO )
{
HB_FUN_MSGINFO();
}
#pragma ENDDUMP
#include "hbapi.h"
//------------------------------------------------------------------------------
class sample {
public:
int iValue;
sample();
mostrar();
};
//------------------------------------------------------------------------------
sample:: sample() {
iValue= 123;
}
//------------------------------------------------------------------------------
sample:: mostrar() {
// Aca quiero que me retorne el valor "123"
}
//------------------------------------------------------------------------------
_ wrote:Gustavo haber si te sirve esto
Main.prg
- Code: Select all Expand view RUN
#include "Fivewin.ch"
/*-----------------------------------------------------------------------------------------------*/
FUNCTION Main()
LOCAL oCpp
MsgInfo( "Hola Mundo desde xHarbour" )
MsgInfo( MENSAJEC() )
MsgInfo( MENSAJECPP() )
oCpp := CreateSample()
? SampleMostrar( oCpp )
RETURN NIL
Testc.c
- Code: Select all Expand view RUN
#include <hbapi.h>
HB_FUNC( MENSAJEC ){
hb_retc( "hola mundo desde c" );
}
Testcpp.cpp
- Code: Select all Expand view RUN
#include <hbapi.h>
extern "C" HB_FUNC( MENSAJECPP ){
hb_retc( "hola mundo desde c++" );
}
class sample {
public:
int iValue;
sample();
mostrar();
};
//------------------------------------------------------------------------------
sample:: sample() {
iValue = 123;
}
//------------------------------------------------------------------------------
sample:: mostrar() {
return iValue;
}
extern "C" HB_FUNC( CREATESAMPLE ){
sample * p = new sample;
hb_retnl( ( unsigned long ) p );
}
extern "C" HB_FUNC( SAMPLEMOSTRAR ){
hb_retni( ( ( sample * ) hb_parnl( 1 ) ) -> mostrar() );
}
salu2
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 63 guests