Página 1 de 1

Help Calling Functions from DLLs

Publicado: Jue Feb 18, 2010 5:46 pm
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

Help Calling Functions from DLLs

Publicado: Vie Feb 19, 2010 1:16 pm
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

Help Calling Functions from DLLs

Publicado: Vie Feb 19, 2010 1:16 pm
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

Help Calling Functions from DLLs

Publicado: Vie Feb 19, 2010 3:50 pm
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
>

Help Calling Functions from DLLs

Publicado: Vie Feb 19, 2010 3:50 pm
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
>