de C a xHarbour

de C a xHarbour

Postby pablovidal » Fri Jun 05, 2009 6:21 pm

Saludos,

Tengo una Lib Estatica de BorlandC, la cual tiene unas funciones, que necesito pasar a xHarbour. Aqui las funciones.

Code: Select all  Expand view
SP_STATUS   status;
SP_DWORD    DeveloperID;
SP_DWORD    licID;
SP_DWORD    flags;
SP_HANDLE   licHandle;//Out param
 
status = SFNTGetLicense( DeveloperID,
                         SOFTWARE_KEY,
                         licID,
                         flags,
                         &licHandle );

if (status != SP_SUCCESS)   {
  // If a key with the requested developer ID and License ID
  // is not found or a valid license is not available,
  // then SFNTGetLicense will return an error.
}
 

Code: Select all  Expand view
SP_STATUS          status;
SP_DEVICE_INFO     deviceInfo;
SP_HANDLE          licHandle;

status = SFNTGetDeviceInfo( licHandle,
                            &deviceInfo );

if (status != SP_SUCCESS) {
  // If license is already released,
  // then this API will return error.
}

Code: Select all  Expand view
SP_STATUS status;
SP_DWORD  featureID;
SP_BYTE   value[256];
SP_DWORD  length;
SP_DWORD  licHandle;

status = SFNTReadString( licHandle,
                          featureID,
                          value,
                          length);

if (status != SP_SUCCESS) {
  // If featureID is invalid, then this API will return error.
}


Gracias por su ayuda...
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour - Resuelto a Medias

Postby pablovidal » Sat Jun 06, 2009 11:49 am

Resumido Asi...
Code: Select all  Expand view

#pragma BEGINDUMP

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

HB_FUNC( SFNTGETLICENSE )
{
 hb_retnl( SFNTGetLicense( hb_parc( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parc( 5 ) ) );
}
#pragma ENDDUMP
 


El problema ahora es que no tengo acceso la libreria que esta para Borland C, la añado al proyecto de compilacion de VERCE y nada... Tengo que hacer algo en especial para acceder a la libreria de C
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour *** todavia con problemas ***

Postby pablovidal » Mon Jun 08, 2009 6:29 pm

Saludos,

Ya puedo hacer a la Funcion en "C" y todo ok, el problema es que tengo que pasarle un valor por referencia y no se como se hace... Aqui el codigo...

Code: Select all  Expand view
Function SafaNet()
Local hStatus := 0
Local status  := SFNTGetLicense( @hStatus )

? status

Return Nil

#pragma BEGINDUMP
#include <hbapi.h>
#include "SentinelKeys.h"         /*  Header file for the Sentinel Keys client library  */
#include "SentinelKeysLicense.h"  /*  Header file for this License  */

HB_FUNC( SFNTGETLICENSE )
{
 hb_retnl( SFNTGetLicense( DEVELOPERID, SOFTWARE_KEY, LICENSEID, 32, &hb_hardnl(1 ) );
 }

#pragma ENDDUMP
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby Antonio Linares » Mon Jun 08, 2009 7:02 pm

Pablo,

Code: Select all  Expand view

Function SafaNet()
Local hStatus := 0
Local status  := SFNTGetLicense( @hStatus )

? status

Return Nil

#pragma BEGINDUMP
#include <hbapi.h>
#include "SentinelKeys.h"         /*  Header file for the Sentinel Keys client library  */
#include "SentinelKeysLicense.h"  /*  Header file for this License  */

HB_FUNC( SFNTGETLICENSE )
{
   SP_DWORD license;

    hb_retnl( SFNTGetLicense( DEVELOPERID, SOFTWARE_KEY, LICENSEID, 32, &license );
    hb_stornl( ( LONG ) license, 1 );
 }

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby pablovidal » Mon Jun 08, 2009 9:40 pm

Antonio Gracias...

funciono a la mil maravillas....
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby pablovidal » Tue Jun 09, 2009 2:37 am

Antonio Linares wrote:Pablo,

Code: Select all  Expand view

Function SafaNet()
Local hStatus := 0
Local status  := SFNTGetLicense( @hStatus )

? status

Return Nil

#pragma BEGINDUMP
#include <hbapi.h>
#include "SentinelKeys.h"         /*  Header file for the Sentinel Keys client library  */
#include "SentinelKeysLicense.h"  /*  Header file for this License  */

HB_FUNC( SFNTGETLICENSE )
{
   SP_DWORD license;

    hb_retnl( SFNTGetLicense( DEVELOPERID, SOFTWARE_KEY, LICENSEID, 32, &license );
    hb_stornl( ( LONG ) license, 1 );
 }

#pragma ENDDUMP
 


Antonio, gracias me funciono de perlas, pero tengo estas otras dos funciones que son la que me complementan...

Code: Select all  Expand view
SP_STATUS          status;
SP_DEVICE_INFO     deviceInfo;
SP_HANDLE          licHandle;

status = SFNTGetDeviceInfo( licHandle,
                            &deviceInfo );

if (status != SP_SUCCESS) {
  // If license is already released,
  // then this API will return error.
}
 

Code: Select all  Expand view
SP_STATUS status;
SP_DWORD  featureID;
SP_BYTE   value[256];
SP_DWORD  length;
SP_DWORD  licHandle;

status = SFNTReadString( licHandle,
                          featureID,
                          value,
                          length);

if (status != SP_SUCCESS) {
  // If featureID is invalid, then this API will return error.
}

Y disculpa, es que de C se muy poco y ando un poco rapido con esto...
Ademas estas funciones les pueden servir a otros, son para unas llaves de seguridad USB. Que impiden que el programa sea copiado y ademas traen un relog interno para llevar la hora sin importar la que tenga el pc...
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby Antonio Linares » Tue Jun 09, 2009 6:09 am

Pablo,

Para la primera:
Code: Select all  Expand view

SP_STATUS          status;
SP_DEVICE_INFO     deviceInfo;
SP_HANDLE          licHandle;

HB_FUNC( SFNTGETDEVICEINFO )  // licence, @deviceInfo --> status
{
   SP_DEVICE_INFO deviceInfo;

   hb_retnl( SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), &deviceInfo );
   hb_stornl( ( LONG ) deviceInfo, 1 );
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby Antonio Linares » Tue Jun 09, 2009 6:13 am

Pablo,

la segunda:
Code: Select all  Expand view

SP_STATUS status;
SP_DWORD  featureID;
SP_BYTE   value[256];
SP_DWORD  length;
SP_DWORD  licHandle;

HB_FUNC( SFNTREADSTRING ) // licence, featureID, @value --> status
{
   SP_BYTE value[ 256 ];
   SP_DWORD length;

   hb_retnl( ( LONG ) SFNTReadString( ( SP_DWORD ) hb_parnl( 1 ), ( SP_DWORD ) hb_parnl( 2 ), value, &length );
   hb_storclen( value, length, 3 );  
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby pablovidal » Tue Jun 09, 2009 10:27 am

Image
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby Antonio Linares » Tue Jun 09, 2009 2:00 pm

Pablo,

Por favor, envíame lotenet.prg por email para compilarlo aqui, gracias
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby pablovidal » Wed Jun 10, 2009 9:26 pm

Saludos Antonio,

Esta es la funcion donde tengo problemas, No se que devuelve ?
y me da error en tiempo en ejecucion

Code: Select all  Expand view
HB_FUNC( SFNTGETDEVICEINFO )
{
   SPP_DEVICE_INFO deviceInfo;

   hb_retnl( SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), deviceInfo ) );
   hb_storclen( ( char * ) deviceInfo, sizeof( SPP_DEVICE_INFO ), 2 );
}


y por ultimo esta esta otra funcion que sirve para escribir data...

Code: Select all  Expand view

SP_STATUS  status;
SP_DWORD   featureID;
SP_BYTE    value[ ] = { 0x00};
SP_DWORD   writePassword;
SP_HANDLE  licHandle;

status = SFNTWriteString ( licHandle, featureID, value, writePassword);
 
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby Antonio Linares » Wed Jun 10, 2009 9:38 pm

Pablo,

A la primera función le tienes que pasar un segundo parámetro, tipo cadena, por referencia.

Lo que devuelve en el segundo parámetro, pasado por referencia, es el contenido entero de la estructura SPP_DEVICE_INFO.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby pablovidal » Thu Jun 11, 2009 3:22 am

El problema es que me da un error en tiempo de ejecución.

Code: Select all  Expand view

Local hHeader := 0
Local nStatus  := SFNTGetLicense( @hHeader )
Local cRetorno := Space( 250 )

If SFNTGetDeviceInfo( hHeader, @cRetorno ) == 0 // <--- Aki da error en Tiempo de Ejecucion
 ? "Ok..."
EndIf
 


Otra cosa, es que me contacte con el fabricante y me digo que la funcion SFNTGetDeviceInfo devuelve un array.
Code: Select all  Expand view
typedef struct SP_Device_Info
{
    SP_DWORD        formFactorType;
    SP_DWORD        productCode;
    SP_DWORD        hardlimit;
    SP_DWORD        capabilities;
    SP_DWORD        devID;
    SP_DWORD        devSN;
    SP_DATE_TIME    timeValue;
    SP_DWORD        memorySize;
    SP_DWORD        freeSize;
    SP_DWORD        drvVersion;
} SP_DEVICE_INFO, *SPP_DEVICE_INFO;
 


Y la constante SP_DATE_TIME es SubArray

Code: Select all  Expand view
typedef struct SP_DateTime
{
    SP_DWORD        year;
    SP_BYTE         month;
    SP_BYTE         dayOfMonth;
    SP_BYTE         hour;
    SP_BYTE         minute;
    SP_BYTE         second;
} SP_DATE_TIME, *SPP_DATE_TIME;
 
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Re: de C a xHarbour

Postby Antonio Linares » Thu Jun 11, 2009 6:04 am

Pablo,

En C se le dicen estructuras. Arrays es otra cosa :-)

Prueba asi: (de esta forma devuelve todos los elementos de la estructura juntos)
Code: Select all  Expand view

HB_FUNC( SFNTGETDEVICEINFO )
{
   SPP_DEVICE_INFO deviceInfo;

   hb_retnl( SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), &deviceInfo ) );  // OJO al &
   hb_storclen( ( char * ) deviceInfo, sizeof( SPP_DEVICE_INFO ), 2 );
}
 

Para devolver un array tipo Harbour, tendrías que hacerlo asi:
Code: Select all  Expand view

HB_FUNC( SFNTGETDEVICEINFO )
{
   SPP_DEVICE_INFO deviceInfo;

   SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), &deviceInfo );

   hb_reta( 10 ); // vamos a devolver un array de 10 elementos

   hb_stornl( ( LONG ) deviceInfo.formFactorType, -1, 1 );
   hb_stornl( ( LONG ) deviceInfo.productCode, -1, 2 );
   ... asi por cada uno de los elementos de la estructura
}
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41901
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: de C a xHarbour

Postby pablovidal » Thu Jun 11, 2009 11:12 am

Antonio de esta manera
Code: Select all  Expand view
HB_FUNC( SFNTGETDEVICEINFO )
{
   SPP_DEVICE_INFO deviceInfo;

   hb_retnl( SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), &deviceInfo ) );  // OJO al &
   hb_storclen( ( char * ) deviceInfo, sizeof( SPP_DEVICE_INFO ), 2 );
}

Me da el siguiente error:
Image

y de esta manera:
Code: Select all  Expand view
HB_FUNC( SFNTGETDEVICEINFO )
{
   SPP_DEVICE_INFO deviceInfo;

   SFNTGetDeviceInfo( ( SP_HANDLE ) hb_parnl( 1 ), &deviceInfo );

   hb_reta( 10 ); // vamos a devolver un array de 10 elementos

   hb_stornl( ( LONG ) deviceInfo.formFactorType, -1, 1 );
   hb_stornl( ( LONG ) deviceInfo.productCode, -1, 2 );
   hb_stornl( ( LONG ) deviceInfo.hardlimit, -1, 3 );
   hb_stornl( ( LONG ) deviceInfo.capabilities, -1, 4 );
   hb_stornl( ( LONG ) deviceInfo.devID, -1, 5 );
   hb_stornl( ( LONG ) deviceInfo.devSN, -1, 6 );
   hb_stornl( ( LONG ) deviceInfo.timeValue, -1, 7 );
   hb_stornl( ( LONG ) deviceInfo.memorySize, -1, 8 );
   hb_stornl( ( LONG ) deviceInfo.freeSize, -1, 9 );
   hb_stornl( ( LONG ) deviceInfo.drvVersion, -1, 10 );
}


Me dice lo siguiente:
Structure requiered on left side of . or .* in function

Esto en cada una de las lineas de forma de array
Saludos,

Pablo Alberto Vidal
/*
------------------------------------------------------
Harbour 3.2.0, Fivewin 17.02, BCC7
------------------------------------------------------
*/
User avatar
pablovidal
 
Posts: 401
Joined: Thu Oct 06, 2005 10:15 pm
Location: Republica Dominicana

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 32 guests