Hola a todos,
Estas son notas para los que como yo no tenemos ni idea de 'C' y precisamos llamar a una funci贸n 'C' de una .Lib de terceros, desde FiveWin/Harbour.
Gracias a este foro, sobre todo a Antonio Linares lo he conseguido.
La .lib de terceros en mi caso era: ter16bc.lib
--->>> ATENCI脫N: la .lib debe ser compatible con nuestro compilador/lincador.
La funci贸n de la .lib a usar era: CreateTerWindow()
Recib铆a como par谩metro un puntero a una estructura: arg_list
y devolv铆a un handle de una ventana que yo quer铆a obtener/manipular/gestionar desde un array de 2 elementos: aRet
Deb铆a comenzar mi c贸digo 'C' con:
#pragma BEGINDUMP
#include <hbapi.h>
y acabarlo con:
#pragma ENDDUMP
Hasta aqu铆 f谩cil.
Dentro del c贸digo 'C' deb铆a declarar la estructura, as铆:
struct arg_list {
int x;
long LineLimit;
BOOL WordWrap;
BYTE InputType;
BYTE file[131];
HGLOBAL hBuffer;
HINSTANCE hInst;
HWND hParentWnd;
DWORD style;
};
Tambi茅n dentro del c贸digo 'C' debia declarar la funci贸n 'C' que yo iba a utilizar de la .lib (prototipo?), as铆:
HWND CreateTerWindow( struct arg_list * );
Hace 20 a帽os me ense帽aron que los arteriscos ten铆an algo que ver (indicaban) con los punteros de 'C' (vaya nivelazo tengo!).
NOTA---------------------------------------------------------------------------------
Por cierto para definir el prototipo debemos saber si la funci贸n es del tipo 'PASCAL', 'C' o 'WINAPI'.
Si disponemos de la DLL, para ello se puede crear un fichero DEF a partir de la DLL:
impdef.exe TuDLL.DEF TuDLL.DLL
Este fichero es de tipo texto (ascii) y su contenido ser谩 m谩s o menos as铆:
LIBRARY TuDLL.DLL
EXPORTS
ClearAllAnalog @13 ; ClearAllAnalog
CreateTerWindow @8 ; CreateTerWindow
ClearAnalogChannel @14 ; ClearAnalogChannel
Si los simbolos usa S脫LO mayusculas y NO lleva subrayado delante seran del tipo 'PASCAL':
HWND PASCAL CreateTerWindow( struct arg_list * );
Si los simbolos usa mayusculas y minusculas y SI lleva subrayado delante seran del tipo 'C':
HWND CreateTerWindow( struct arg_list * );
Si los simbolos usa mayusculas y minusculas y NO lleva subrayado delante seran del tipo 'WINAPI':
HWND WINAPI CreateTerWindow( struct arg_list * );
Fin de NOTA--------------------------------------------------------------------------
Tambi茅n dentro del c贸digo 'C' deb铆a declarar/codificar la funci贸n 'Harbour' (por decirlo de alguna manera, para que nos entendamos) que ser铆a la que llamar铆a en 煤ltima instancia a la funci贸n 'C'. Si no estoy equivocado su nombre debe estar en may煤sculas!, as铆:
HB_FUNC( ACREATETERWINDOW )
Esta funci贸n recib铆a en mi caso una array con los valores que deb铆a asignar a los 'campos' de la estructura que recibir铆a la funci贸n 'C'.
Aqu铆 empez贸 mi dolor de cabeza por ignorante, los int, long, BOOL, BYTE,... tienen tratamiento diferente seg煤n cada tipo de dato. Observad el c贸digo de ejemplo y vereis como se asignan.
Este es el c贸digo de la funci贸n 'Harbour':
HWND hWndTer;
struct arg_list aParams;
aParams.x = hb_parni(1,1);
aParams.LineLimit = hb_parnl(1,2);
aParams.WordWrap = hb_parl(1,3);
aParams.InputType = hb_parc(1,4)[ 0 ];
strcpy( aParams.file, hb_parc( 1, 5 ) );
aParams.hBuffer = ( HWND ) hb_parnl(1,6);
aParams.hInst = ( HWND ) hb_parnl(1,7);
aParams.hParentWnd = ( HWND ) hb_parnl(1,8);
aParams.style = hb_parnl(1,9);
hWndTer = CreateTerWindow( &aParams );
hb_reta( 2 ); // creamos y devolvemos un array de 2 elementos.
// rellenamos los datos del array (situado en "return", que se indica con -1)
hb_stornl( ( LONG ) hWndTer, -1, 1 );
hb_stornl( ( LONG ) aParams.hTextWnd, -1, 2 );
Bueno hasta aqu铆 creo que s贸lo lo entiendo yo, aqu铆 os dejo el c贸digo del PRG de ejemplo:
... y no os olvideis abrir y cerrar par茅ntesis,.... y los punto y coma al final de cada l铆nea de 'C'.
Un Saludo
Carlos G.
Estas son notas para los que como yo no tenemos ni idea de 'C' y precisamos llamar a una funci贸n 'C' de una .Lib de terceros, desde FiveWin/Harbour.
Gracias a este foro, sobre todo a Antonio Linares lo he conseguido.
La .lib de terceros en mi caso era: ter16bc.lib
--->>> ATENCI脫N: la .lib debe ser compatible con nuestro compilador/lincador.
La funci贸n de la .lib a usar era: CreateTerWindow()
Recib铆a como par谩metro un puntero a una estructura: arg_list
y devolv铆a un handle de una ventana que yo quer铆a obtener/manipular/gestionar desde un array de 2 elementos: aRet
Deb铆a comenzar mi c贸digo 'C' con:
#pragma BEGINDUMP
#include <hbapi.h>
y acabarlo con:
#pragma ENDDUMP
Hasta aqu铆 f谩cil.
Dentro del c贸digo 'C' deb铆a declarar la estructura, as铆:
struct arg_list {
int x;
long LineLimit;
BOOL WordWrap;
BYTE InputType;
BYTE file[131];
HGLOBAL hBuffer;
HINSTANCE hInst;
HWND hParentWnd;
DWORD style;
};
Tambi茅n dentro del c贸digo 'C' debia declarar la funci贸n 'C' que yo iba a utilizar de la .lib (prototipo?), as铆:
HWND CreateTerWindow( struct arg_list * );
Hace 20 a帽os me ense帽aron que los arteriscos ten铆an algo que ver (indicaban) con los punteros de 'C' (vaya nivelazo tengo!).
NOTA---------------------------------------------------------------------------------
Por cierto para definir el prototipo debemos saber si la funci贸n es del tipo 'PASCAL', 'C' o 'WINAPI'.
Si disponemos de la DLL, para ello se puede crear un fichero DEF a partir de la DLL:
impdef.exe TuDLL.DEF TuDLL.DLL
Este fichero es de tipo texto (ascii) y su contenido ser谩 m谩s o menos as铆:
LIBRARY TuDLL.DLL
EXPORTS
ClearAllAnalog @13 ; ClearAllAnalog
CreateTerWindow @8 ; CreateTerWindow
ClearAnalogChannel @14 ; ClearAnalogChannel
Si los simbolos usa S脫LO mayusculas y NO lleva subrayado delante seran del tipo 'PASCAL':
HWND PASCAL CreateTerWindow( struct arg_list * );
Si los simbolos usa mayusculas y minusculas y SI lleva subrayado delante seran del tipo 'C':
HWND CreateTerWindow( struct arg_list * );
Si los simbolos usa mayusculas y minusculas y NO lleva subrayado delante seran del tipo 'WINAPI':
HWND WINAPI CreateTerWindow( struct arg_list * );
Fin de NOTA--------------------------------------------------------------------------
Tambi茅n dentro del c贸digo 'C' deb铆a declarar/codificar la funci贸n 'Harbour' (por decirlo de alguna manera, para que nos entendamos) que ser铆a la que llamar铆a en 煤ltima instancia a la funci贸n 'C'. Si no estoy equivocado su nombre debe estar en may煤sculas!, as铆:
HB_FUNC( ACREATETERWINDOW )
Esta funci贸n recib铆a en mi caso una array con los valores que deb铆a asignar a los 'campos' de la estructura que recibir铆a la funci贸n 'C'.
Aqu铆 empez贸 mi dolor de cabeza por ignorante, los int, long, BOOL, BYTE,... tienen tratamiento diferente seg煤n cada tipo de dato. Observad el c贸digo de ejemplo y vereis como se asignan.
Este es el c贸digo de la funci贸n 'Harbour':
HWND hWndTer;
struct arg_list aParams;
aParams.x = hb_parni(1,1);
aParams.LineLimit = hb_parnl(1,2);
aParams.WordWrap = hb_parl(1,3);
aParams.InputType = hb_parc(1,4)[ 0 ];
strcpy( aParams.file, hb_parc( 1, 5 ) );
aParams.hBuffer = ( HWND ) hb_parnl(1,6);
aParams.hInst = ( HWND ) hb_parnl(1,7);
aParams.hParentWnd = ( HWND ) hb_parnl(1,8);
aParams.style = hb_parnl(1,9);
hWndTer = CreateTerWindow( &aParams );
hb_reta( 2 ); // creamos y devolvemos un array de 2 elementos.
// rellenamos los datos del array (situado en "return", que se indica con -1)
hb_stornl( ( LONG ) hWndTer, -1, 1 );
hb_stornl( ( LONG ) aParams.hTextWnd, -1, 2 );
Bueno hasta aqu铆 creo que s贸lo lo entiendo yo, aqu铆 os dejo el c贸digo del PRG de ejemplo:
... y no os olvideis abrir y cerrar par茅ntesis,.... y los punto y coma al final de cada l铆nea de 'C'.
Un Saludo
Carlos G.
FUNCTION LlamaTer( oWndMain )
Local oWndTer 聽 聽 := Nil
Local nStyle 聽 聽 聽:= 0
Local aParametros := {}
Local aRet 聽 聽 聽 聽:= {}
DEFINE WINDOW oWndTer MDICHILD FROM 0,0 TO 520,804 TITLE "Control per escriure" ;
聽 聽 COLORS CLR_BLACK, nil OF oWndMain NOZOOM PIXEL //FIVEWIDI
ACTIVATE WINDOW oWndTer
nStyle := nOR( WS_CAPTION, WS_CHILD ,WS_VISIBLE, WS_TABSTOP )
aParametros := { 0, ; 聽 聽 聽 聽 聽 聽 聽 聽 // x
聽 聽 聽 聽 聽 聽 聽 聽 聽999, ; 聽 聽 聽 聽 聽 聽 聽 // LineLimit
聽 聽 聽 聽 聽 聽 聽 聽 聽.F., ; 聽 聽 聽 聽 聽 聽 聽 // WordWrap
聽 聽 聽 聽 聽 聽 聽 聽 聽"J", ; 聽 聽 聽 聽 聽 聽 聽 // InputType
聽 聽 聽 聽 聽 聽 聽 聽 聽"C:\temp\ea.txt", ; 聽// File
聽 聽 聽 聽 聽 聽 聽 聽 聽0, ; 聽 聽 聽 聽 聽 聽 聽 聽 // hBuffer
聽 聽 聽 聽 聽 聽 聽 聽 聽0, ; 聽 聽 聽 聽 聽 聽 聽 聽 // hInst
聽 聽 聽 聽 聽 聽 聽 聽 聽oWndTer:HWnd, ; 聽 聽 聽// hParentWnd
聽 聽 聽 聽 聽 聽 聽 聽 聽nStyle, ; 聽 聽 聽 聽 聽 聽// Style
聽 聽 聽 聽 聽 聽 聽 聽 }
aRet := aCreateTerWindow( aParametros )
Return aRet
/* -------------------------------------------------------------------------------------- */
#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
struct arg_list {
聽 聽 int 聽 聽x; 聽 聽 聽 聽 聽 聽 聽 聽 /* Initial x position of the editing window,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽you may specify CW_USEDEFAULT to use default values. */
聽 聽 long 聽 LineLimit; 聽 聽 聽 聽 /* Number of lines allowed in the editor window.
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽Set to 0 to have unlimited number of lines */
聽 聽 BOOL 聽 WordWrap; 聽 聽 聽 聽 聽/* Set this flag to true (1), 聽if you wish to enable the
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽word wrapping feature. */
聽 聽 BYTE 聽 InputType; 聽 聽 聽 聽 /* This flag specifies the input type. If you wish to
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽edit a file, set the input_type to 'F'. Conversely,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽if you wish to pass the text for editing in a buffer,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽set this field to 'B'. */
聽 聽 BYTE 聽 file[131]; 聽 聽 聽 聽/* 聽If the input type is set to 'F', 聽specify the file
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽name for editing in this field. */
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽// ===== Buffer input fields only =======
聽 聽 HGLOBAL hBuffer; 聽 聽 聽 聽 /* 聽Specify the global memory handle containing the
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽input text data. 聽This handle becomes the property
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽of the editor. 聽Your program must never try to lock
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽or free this handle */
聽 聽 HINSTANCE hInst; 聽 聽 聽 聽 // 聽Handle of the current instanaces.
聽 聽 HWND 聽 hParentWnd; 聽 聽 聽 // Handle to the parent window
聽 聽 DWORD 聽style; 聽 聽 聽 聽 聽 聽// 聽Editor window style
聽 聽 };
HWND CreateTerWindow( struct arg_list * );
HB_FUNC( ACREATETERWINDOW )
{
聽 聽HWND hWndTer;
聽 聽struct arg_list aParams;
聽 聽aParams.x 聽 聽 聽 聽 聽 聽 = hb_parni(1,1);
聽 聽aParams.LineLimit 聽 聽 = hb_parnl(1,2);
聽 聽aParams.WordWrap 聽 聽 聽= hb_parl(1,3);
聽 聽aParams.InputType 聽 聽 = hb_parc(1,4)[ 0 ];
聽 聽strcpy( aParams.file, hb_parc( 1, 5 ) );
聽 聽aParams.hBuffer 聽 聽 聽 = ( HWND ) hb_parnl(1,6);
聽 聽aParams.hInst 聽 聽 聽 聽 = ( HWND ) hb_parnl(1,7);
聽 聽aParams.hParentWnd 聽 聽= ( HWND ) hb_parnl(1,8);
聽 聽aParams.style 聽 聽 聽 聽 = hb_parnl(1,9);
聽 聽hWndTer = CreateTerWindow( &aParams );
聽 聽hb_reta( 2 ); // creamos y devolvemos un array de 2 elementos.
聽 聽// rellenamos los datos del array (situado en "return", que se indica con -1)
聽 聽hb_stornl( ( LONG ) hWndTer, -1, 1 );
聽 聽hb_stornl( ( LONG ) aParams.hTextWnd, -1, 2 );
}
#pragma ENDDUMPUn Saludo
Carlos G.
FiveWin 25.12 + Harbour 3.2.0dev (r2502110321), BCC 7.7 Windows 11 Home