FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour ayuda para pasar funci贸n a C
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 11:34 AM
Hola,

Tengo la siguiente funci贸n en C:

__declspec(dllimport) void _stdcall SECheckVirtualPC(int *user_var, int user_value);

#define CHECK_VIRTUAL_PC(var, val) SECheckVirtualPC(&var, val);


Y la defino as铆:

Code (fw): Select all Collapse
#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"
#include "hbapiitm.h"

#include "ThemidaSDK.h"




HB_FUNC( CHECK_VIRTUAL_PC )
{

  hb_retni( SECheckVirtualPC( hb_parni( 1 ), hb_parni( 2 )  ));

}



//------------------------------------------------//



#pragma ENDDUMP




Y me da este error al compilar con BCC 582:

Error E2342 themida.prg 102: Type mismatch in parameter 'user_var' (wanted 'int *', got 'int') in function HB_FUN_CHECK_VIRTUAL_PC
Error E2468 themida.prg 102: Value of type void is not allowed in function HB_FUN_CHECK_VIRTUAL_PC

驴Qu茅 hago mal por favor?.

Muchas gracias.
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 11:58 AM
Lucas,

Code (fw): Select all Collapse
HB_FUNC( CHECK_VIRTUAL_PC )
{
   int i = hb_parni( 1 );

  SECheckVirtualPC( &i, hb_parni( 2 )  );

   hb_retnl( i ):
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 12:00 PM
Si pasas el primer valor por referencia y lo quieres recuperar de esa forma:
Code (fw): Select all Collapse
HB_FUNC( CHECK_VIRTUAL_PC )
{
   int i = hb_parni( 1 );

  SECheckVirtualPC( &i, hb_parni( 2 )  );

   hb_storni( i, 1 ):
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 12:19 PM

Muchas gracias, pero no me funciona.

Este es el c贸digo C:

int MyCheckVar;

CHECK_VIRTUAL_PC(MyCheckVar, 0x12345678)

if (MyCheckVar != 0x12345678)

printf("Application is running under VMWare/VirtualPC");

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 01:01 PM

Lucas

seria bueno saber el resultado... por que no te funciona?

Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 01:29 PM

Daniel,

Muchas gracias por responder.

Se supone que CHECK_VIRTUAL_PC(MyCheckVar, 100) debe cambiar MyCheckVar.

Siempre me devuelve 100, tanto en el PC como en VMWARE.

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 01:38 PM
Este es el c贸digo en C que funciona OK:

Code (fw): Select all Collapse
#include <stdio.h>
#include "windows.h"
#include "hbapi.h"
#include "hbapiitm.h"

#include "ThemidaSDK.h"


int main()

{

int MyCheckVar;

VM_START

CHECK_VIRTUAL_PC(MyCheckVar, 0x12345678)


if (MyCheckVar != 0x12345678)
    {
        MessageBox(NULL, "Using VMware / Virtual PC.", "INFO", MB_OK + MB_ICONINFORMATION);
    }
    else
    {
        MessageBox(NULL, "Application not under VMWARE / Virtual PC", "info", MB_OK + MB_ICONERROR);
    }



 printf("\n\nBye bye\n");
 return 0;


VM_END

}






//------------------------------------------------//
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 01:49 PM
Y el funcionamiento de la funci贸n:

CHECK_VIRTUAL_PC (user_variable, user_value)



Where "user_variable" is any local or global variable in the application and "user_value" is any immediate value (constant value). The way that it works is the following:



路 The CHECK_VIRTUAL_PC macro is called.



路 SecureEngine takes control of the processor and make special checks to know if your application is running under VMWare/VirtualPC.



路 If your application is not running under VMWare/VirtualPC, SecureEngine sets "user_variable" equal to "user_value".



路 If the application is running under VMWare/VirtualPC, SecureEngine does not set "user_variable". You should take care of initializing "user_variable" to something else from "user_value".



路 SecureEngine returns control to the protected application. The protected application should check the value of "user_variable" and execute the desired action if the application is running under VMWare/VirtualPC.






Much铆simas gracias.
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 02:08 PM
Hola de nuevo,

Prob茅 a definir mi propia funci贸n:

Code (fw): Select all Collapse
HB_FUNC( LUCAS )

{

int MyCheckVar;

VM_START

CHECK_VIRTUAL_PC(MyCheckVar, 0x12345678)



if (MyCheckVar != 0x12345678)
    {
        MessageBox(NULL, "Using VMware / Virtual PC.", "INFO", MB_OK + MB_ICONINFORMATION);
        hb_retni(1);
    }
    else
    {
        MessageBox(NULL, "Application not under VMWARE / Virtual PC", "info", MB_OK + MB_ICONERROR);
        hb_retni(0);
    }

/*
if (MyCheckVar != 0x12345678)
    hb_retni(1);
else
    hb_retni(2);
*/

VM_END


MessageBox(NULL, "break point", "INFO", MB_OK );

}



Hasta el "break point" todo va bien.

Cuando va a devolver el control a Harbour salta un gpf:



驴Qu茅 hago mal?.

Muchas gracias.
Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 04:15 PM

Hola Lucas, prueba esto:

//---------------------------------------------------------

include <stdio.h>

include "windows.h"

include "hbapi.h"

include "hbapiitm.h"

include "ThemidaSDK.h"

HB_FUNC( CHECK_VIRTUAL_PC )
{
int MyCheckVar;

CHECK_VIRTUAL_PC(MyCheckVar, 0x12345678);

hb_retl(MyCheckVar != 0x12345678);
}

//---------------------------------------------------------

Esta funci贸n devuelve un valor l贸gico y se usa as铆:

if CHECK_VIRTUAL_PC()
Alert("Using VMware / Virtual PC.")
else
Alert("Application not under VMWARE / Virtual PC")
endif

Espero que te valga :-)

Saludos de Manu Exp贸sito
(TDbf, Eagle1, Condor1, TPrn)

______________________________________________________________________________

Sevilla - Andaluc铆a
Posts: 1303
Joined: Tue Jul 21, 2009 08:12 AM
Re: ayuda para pasar funci贸n a C
Posted: Tue Sep 04, 2012 04:55 PM

Manu,

Un mill贸n de gracias.

El problema es que este producto no permite ser mezclado con c贸digo Harbour, lo he tenido que sacar a un m貌dulo .c exclusivo.

Por cierto, a ver si alguien se anima a darnos un curso de C y Harbour, de pago naturalmente ;).

Un saludo

Muchas gracias. Many thanks.



Un saludo, Best regards,



Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producci贸n]



Implementando MSVC 2010, FWH64 y ADO.



Abandonando uso xHarbour y SQLRDD.
Posts: 817
Joined: Sun Jun 15, 2008 07:47 PM
Re: ayuda para pasar funci贸n a C
Posted: Thu Sep 06, 2012 10:06 PM

Venga... vale yo hago un libro monogr谩fico sobre el sistema extendido, el API ITEM, etc de Harbour con muchos ejemplos pr谩cticos.
Pero tiene que haber cuorum... :oops:
Cuantos y cuanto estar铆an dispuestos a pagar por ese libro? :?: :mrgreen:

Saludos
Manu Exp贸sito

______________________________________________________________________________

Sevilla - Andaluc铆a
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Re: ayuda para pasar funci贸n a C
Posted: Fri Sep 07, 2012 01:06 AM

Manu,

Me anoto en la lista.

Saludos,

George

Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Re: ayuda para pasar funci贸n a C
Posted: Fri Sep 07, 2012 10:39 AM

Manu,

me siento en primera fila ;-)

Un abrazo,

F茅lix

Posts: 1074
Joined: Fri Oct 07, 2005 01:56 PM
Re: ayuda para pasar funci贸n a C
Posted: Fri Sep 07, 2012 12:36 PM

Hola

yo tambien me anoto, pero que el pago se a atraves de paypal

Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl