In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Help Calling Functions from DLLs

Xailer professional forum in English
Responder
Pedro Sousa e Faro
Mensajes: 91
Registrado: Mié May 30, 2007 5:25 pm

Help Calling Functions from DLLs

Mensaje por Pedro Sousa e Faro »

Hi
I'm trying to call a function from a DLL (non XAILER , simple win32dll) from
a xailer program
The DLL has only one function "CheckAdapter"
DYNAMIC CheckAdapter //define function
nHandle := HB_LibLoad( "EcloExpressThermoAPI.dll" ) //open DLL
msginfo(CheckAdapter()) //see what returns
HB_LibFree( nHandle )
The program returns "Undefined function: CHECKADAPTER".
What is missing ?
Best regards
Pedro
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

Help Calling Functions from DLLs

Mensaje por jfgimenez »

Pedro,
> I'm trying to call a function from a DLL (non XAILER , simple win32dll)
> from a xailer program
>
> The DLL has only one function "CheckAdapter"
>
>
> DYNAMIC CheckAdapter //define function
>
>
> nHandle := HB_LibLoad( "EcloExpressThermoAPI.dll" ) //open DLL
>
> msginfo(CheckAdapter()) //see what returns
>
> HB_LibFree( nHandle )
>
> The program returns "Undefined function: CHECKADAPTER".
>
>
> What is missing ?
You need to write a "wrapper" to that function in the dll. Try something
like this:
XA_FUNC( CHECKADAPTER )
{
HMODULE hdll = LoadLibrary( "EcloExpressThermoAPI.dll" );
typedef int ( WINAPI * FN )( void ); // <<<<<<<< Check this line
FN p = ( FN ) GetProcAddress( hdll, "CheckAdapter" );
if( p )
hb_retni( p() );
else
hb_retni( 0 );
FreeLibrary( hdll );
}
Of course, you have to write the imported function prototype (the remarked
line) according to the real function; if not, you'll probably get a GPF or
simply it won't work.
--
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Avatar de Usuario
jfgimenez
Site Admin
Mensajes: 5718
Registrado: Lun Abr 06, 2015 8:48 pm
Contactar:

Help Calling Functions from DLLs

Mensaje por jfgimenez »

Pedro,
> I'm trying to call a function from a DLL (non XAILER , simple win32dll)
> from a xailer program
>
> The DLL has only one function "CheckAdapter"
>
>
> DYNAMIC CheckAdapter //define function
>
>
> nHandle := HB_LibLoad( "EcloExpressThermoAPI.dll" ) //open DLL
>
> msginfo(CheckAdapter()) //see what returns
>
> HB_LibFree( nHandle )
>
> The program returns "Undefined function: CHECKADAPTER".
>
>
> What is missing ?
You need to write a "wrapper" to that function in the dll. Try something
like this:
XA_FUNC( CHECKADAPTER )
{
HMODULE hdll = LoadLibrary( "EcloExpressThermoAPI.dll" );
typedef int ( WINAPI * FN )( void ); // <<<<<<<< Check this line
FN p = ( FN ) GetProcAddress( hdll, "CheckAdapter" );
if( p )
hb_retni( p() );
else
hb_retni( 0 );
FreeLibrary( hdll );
}
Of course, you have to write the imported function prototype (the remarked
line) according to the real function; if not, you'll probably get a GPF or
simply it won't work.
--
Regards,
Jose F. Gimenez
http://www.xailer.com
http://www.xailer.info
José F. Giménez
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
Pedro Sousa e Faro
Mensajes: 91
Registrado: Mié May 30, 2007 5:25 pm

Help Calling Functions from DLLs

Mensaje por Pedro Sousa e Faro »

Hi Jose
Great !!! works fine.
In this case de Function returns a Int Number , and works ok.
What would be the sintaxe for a Char Returns ?
Regards.
Pedro
"Jose F. Gimenez" <jfgimenez@wanadoo.es> escreveu na mensagem
news:4b7e8116$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Pedro,
>
>> I'm trying to call a function from a DLL (non XAILER , simple win32dll)
>> from a xailer program
>>
>> The DLL has only one function "CheckAdapter"
>>
>>
>> DYNAMIC CheckAdapter //define function
>>
>>
>> nHandle := HB_LibLoad( "EcloExpressThermoAPI.dll" ) //open DLL
>>
>> msginfo(CheckAdapter()) //see what returns
>>
>> HB_LibFree( nHandle )
>>
>> The program returns "Undefined function: CHECKADAPTER".
>>
>>
>> What is missing ?
>
> You need to write a "wrapper" to that function in the dll. Try something
> like this:
>
> XA_FUNC( CHECKADAPTER )
> {
> HMODULE hdll = LoadLibrary( "EcloExpressThermoAPI.dll" );
> typedef int ( WINAPI * FN )( void ); // <<<<<<<< Check this line
>
> FN p = ( FN ) GetProcAddress( hdll, "CheckAdapter" );
> if( p )
> hb_retni( p() );
> else
> hb_retni( 0 );
> FreeLibrary( hdll );
> }
>
> Of course, you have to write the imported function prototype (the remarked
> line) according to the real function; if not, you'll probably get a GPF or
> simply it won't work.
>
>
> --
> Regards,
>
> Jose F. Gimenez
> http://www.xailer.com
> http://www.xailer.info
>
Pedro Sousa e Faro
Mensajes: 91
Registrado: Mié May 30, 2007 5:25 pm

Help Calling Functions from DLLs

Mensaje por Pedro Sousa e Faro »

Hi Jose
Great !!! works fine.
In this case de Function returns a Int Number , and works ok.
What would be the sintaxe for a Char Returns ?
Regards.
Pedro
"Jose F. Gimenez" <jfgimenez@wanadoo.es> escreveu na mensagem
news:4b7e8116$[email=1@svctag-j7w3v3j....]1@svctag-j7w3v3j....[/email]
> Pedro,
>
>> I'm trying to call a function from a DLL (non XAILER , simple win32dll)
>> from a xailer program
>>
>> The DLL has only one function "CheckAdapter"
>>
>>
>> DYNAMIC CheckAdapter //define function
>>
>>
>> nHandle := HB_LibLoad( "EcloExpressThermoAPI.dll" ) //open DLL
>>
>> msginfo(CheckAdapter()) //see what returns
>>
>> HB_LibFree( nHandle )
>>
>> The program returns "Undefined function: CHECKADAPTER".
>>
>>
>> What is missing ?
>
> You need to write a "wrapper" to that function in the dll. Try something
> like this:
>
> XA_FUNC( CHECKADAPTER )
> {
> HMODULE hdll = LoadLibrary( "EcloExpressThermoAPI.dll" );
> typedef int ( WINAPI * FN )( void ); // <<<<<<<< Check this line
>
> FN p = ( FN ) GetProcAddress( hdll, "CheckAdapter" );
> if( p )
> hb_retni( p() );
> else
> hb_retni( 0 );
> FreeLibrary( hdll );
> }
>
> Of course, you have to write the imported function prototype (the remarked
> line) according to the real function; if not, you'll probably get a GPF or
> simply it won't work.
>
>
> --
> Regards,
>
> Jose F. Gimenez
> http://www.xailer.com
> http://www.xailer.info
>
Responder