Utilizar funciones de una dll con harbour

Utilizar funciones de una dll con harbour

Postby Xevi » Thu Dec 06, 2018 12:02 pm

Si bien he probado y visto como se saca partido a unas funciones de una dll con FW, del sample babu.prg y babudll.prg

Pretendo utilizar lo mismo, funciones de un fichero dll, el mismo babudll.dll, PERO sin utilizar FW, con Harbour nativo.
He agregado la lib hbxpp para compilar, pero no consigo hacerlo andar.

También, segun he visto algun ejemplo por la red, pero no lo consigo!!!

Code: Select all  Expand view

function Main()
   Local hDLL

   hDLL = LoadLibrary( "user32.dll" )
   msginfo( hDLL )  //me da correctamente el handle

//hbxpp.lib
//DllCall(<cDllFile>|<nDllHandle>,[<nCallingConvention>],<cFuncName>|<nOrdinal>,[<xParams,...>])->nResult
   DllCall( "user32.dll", 32, "GetWindowText" )
   DllCall( hDLL, 32, "GetWindowText" )
//no consigo nada, ni con el nombre ni con el handle

   MsgInfo( "aquí llego" )
   
   FreeLibrary( hDLL )

return nil
 


¿Alguien puede orientarme un poco???
¿Que hago mal???
¿Que me falta???
¿Se pueden atacar DLLs con harbour nativo???

Gracias.
Un Saludo,
Xevi.

Aprendiz de la vida!!!
User avatar
Xevi
 
Posts: 169
Joined: Wed Nov 29, 2017 11:42 am
Location: Girona

Re: Utilizar funciones de una dll con harbour

Postby cmsoft » Thu Dec 06, 2018 10:14 pm

Esto es con la funcion CALLDLL32 de Fivewin, no se si te servira.
Code: Select all  Expand view

nHandler := CallDll32( "Funcion" , "ARCHIVO.DLL" , nParam1 , nParam2 )
IF nHandler >= 0
     CallDll32( "OtraFuncion" , "ARCHIVO.DLL" , nHandler )
     CallDll32 ( "Respuesta" , "ARCHIVO.DLL" , nHandler, @RTA )
ENDIF
 
User avatar
cmsoft
 
Posts: 1189
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: Utilizar funciones de una dll con harbour

Postby cnavarro » Thu Dec 06, 2018 11:05 pm

Mira este ejemplo

Code: Select all  Expand view

#include "Fivewin.ch"

Static cTitle  := ""

Function Main()

   local oDlg
   cTitle     := Space( 40 )

   DEFINE WINDOW oDlg TITLE "Prueba" FROM 10, 10 TO 200, 300 PIXEL

   ACTIVATE WINDOW oDlg ON INIT ( GetTextW( oDlg:hWnd, @cTitle, 255 ), MsgInfo( cTitle ) )

Return nil

DLL FUNCTION GetTextW( nHandle AS LONG, @cT AS LPSTR, nMax AS LONG ) AS _INT PASCAL FROM "GetWindowTextA" LIB "user32.dll"

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Utilizar funciones de una dll con harbour

Postby Xevi » Mon Dec 10, 2018 8:41 am

Las dos opciones requieren de FW, por lo tanto no me sirve para utilizar con Harbour nativo.

Cristobal, el código ppo de la opcion que me sugieres, hecha mano de FWCallDLL y GetProcAdd de FW

function GetTextW( nHandle,cT,nMax ) ; local _hDLL := If( ValType( "user32.dll" ) == "N", "user32.dll", LoadLibrary( "user32.dll" ) ) ; local uResult ; local cFarProc ; if Abs( _hDLL ) > 32 ; cFarProc = GetProcAdd( _hDLL, If( Empty( "GetWindowTextA" ) == .T., "GetTextW", "GetWindowTextA" ), .T., 7,7,9,7 ) ; uResult = FWCallDLL( cFarProc,nHandle,@cT,nMax ) ; If( ValType( "user32.dll" ) == "N",, FreeLibrary( _hDLL ) ) ; else ; MsgAlert( "Error code: " + LTrim( Str( _hDLL ) ) + " loading " + If( ValType( "user32.dll" ) == "C", "user32.dll", Str( "user32.dll" ) ) ) ; end ; return uResult


Y la otra opción, CallDll32, ya directamente es una función de FW.

Alguna sugerencia... o cual foro Harbour donde poner mi petición???

Gracias.
Un Saludo,
Xevi.

Aprendiz de la vida!!!
User avatar
Xevi
 
Posts: 169
Joined: Wed Nov 29, 2017 11:42 am
Location: Girona

Re: Utilizar funciones de una dll con harbour

Postby Joaquim Ferrer » Mon Dec 10, 2018 2:49 pm

Buenas Xevi

Pretendes utilizar funciones contenidas en una DLL o pcode harbour de una DLL ?

Si es lo último :

Code: Select all  Expand view

DYNAMIC HRBFUNC1
FUNCTION Main()
Local x, handle := hb_LibLoad( "my.dll" )
 
x := hrbFunc1()   // hrbFunc1 - the function from my.dll
 
hb_LibUnload( handle )
Return Nil
 


Tienes +info en http://www.kresin.ru/en/hrbfaq_3.html#Doc12
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
User avatar
Joaquim Ferrer
 
Posts: 102
Joined: Sat Jan 14, 2012 3:46 pm
Location: Barcelona

Re: Utilizar funciones de una dll con harbour

Postby Xevi » Mon Dec 10, 2018 4:33 pm

Gracias, Quim.

Funciones contenidas en una Dll...
Llamar a funciones en pcode, eso ya lo havia visto.
Un Saludo,
Xevi.

Aprendiz de la vida!!!
User avatar
Xevi
 
Posts: 169
Joined: Wed Nov 29, 2017 11:42 am
Location: Girona

Re: Utilizar funciones de una dll con harbour

Postby Joaquim Ferrer » Tue Dec 11, 2018 7:42 am

Xevi

Puedes probar con automatización OLE y la función harbour
Code: Select all  Expand view
win_oleCreateObject()

Tienes un ejemplo en https://github.com/vszakats/harbour-core/blob/master/contrib/hbwin/tests/ole.prg

También puedes llamar a una DLL de esta forma, mediante un script, linea de comando, etc
Code: Select all  Expand view
Rundll32 Shell32.dll,SHHelpShortcuts_RunDLL PrintersFolder


Algunos ejemplos en https://www.thewindowsclub.com/rundll32-shortcut-commands-windows
Saludos
Fivewinner desde 1.9, programador PHP y Javascript, PWA & HTML5 evangelista
User avatar
Joaquim Ferrer
 
Posts: 102
Joined: Sat Jan 14, 2012 3:46 pm
Location: Barcelona


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 92 guests