ayuda para pasar función a C

ayuda para pasar función a C

Postby lucasdebeltran » 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: Select all  Expand view
#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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby Antonio Linares » Tue Sep 04, 2012 11:58 am

Lucas,

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 41341
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ayuda para pasar función a C

Postby Antonio Linares » Tue Sep 04, 2012 12:00 pm

Si pasas el primer valor por referencia y lo quieres recuperar de esa forma:
Code: Select all  Expand view

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
User avatar
Antonio Linares
Site Admin
 
Posts: 41341
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: ayuda para pasar función a C

Postby lucasdebeltran » 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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby Daniel Garcia-Gil » Tue Sep 04, 2012 1:01 pm

Lucas

seria bueno saber el resultado... por que no te funciona?
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ayuda para pasar función a C

Postby lucasdebeltran » Tue Sep 04, 2012 1: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby lucasdebeltran » Tue Sep 04, 2012 1:38 pm

Este es el código en C que funciona OK:

Code: Select all  Expand view
#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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby lucasdebeltran » Tue Sep 04, 2012 1: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby lucasdebeltran » Tue Sep 04, 2012 2:08 pm

Hola de nuevo,

Probé a definir mi propia función:

Code: Select all  Expand view
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:

Image

¿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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby xmanuel » Tue Sep 04, 2012 4: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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: ayuda para pasar función a C

Postby lucasdebeltran » Tue Sep 04, 2012 4: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.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: ayuda para pasar función a C

Postby xmanuel » 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
xmanuel
 
Posts: 756
Joined: Sun Jun 15, 2008 7:47 pm
Location: Sevilla

Re: ayuda para pasar función a C

Postby George » Fri Sep 07, 2012 1:06 am

Manu,

Me anoto en la lista.

Saludos,

George
George
 
Posts: 724
Joined: Tue Oct 18, 2005 6:49 pm

Re: ayuda para pasar función a C

Postby Baxajaun » Fri Sep 07, 2012 10:39 am

Manu,

me siento en primera fila ;-)

Un abrazo,

Félix
User avatar
Baxajaun
 
Posts: 962
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: ayuda para pasar función a C

Postby Patricio Avalos Aguirre » 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
User avatar
Patricio Avalos Aguirre
 
Posts: 1059
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 14 guests