Page 1 of 2

DLL vs LIB

Posted: Wed Aug 31, 2016 3:57 pm
by jorge.posadas
Grupo,

Hace muchisimo tiempo que usando clipper logre hace una libreria, encadenarla a mis PRG y luego usarla, ahora con el nacimiento de HMG, he leido sobre DLL mi pregunta es:

Cual es la diferencia entre DLL y LIB?
Cuando se debe usar LIB y cuando una DLL
Hay ventas de una sobre la otra?

Y por terminar,

Ejemplo,

LnCustomerId :=GetNextNumber("customer_id")


*------------------------------------------------------------------------------*
FUNCTION GetNextNumber(PsModule)
*------------------------------------------------------------------------------*
LdDateSQL := "DATE('NOW')"
LsTimeSQL := "TIME('NOW','LOCALTIME')"
LsModule := C2SQL(PsModule)
GnNextNumber := 0
IF .NOT. ConectMe()
MsgExclamation ("No me pude conectar a la base de datos")
RETURN NIL
ELSE
GsRead := "SELECT Module, Last_Number, "
GsRead += "(Last_Number + Sequence_Count) AS [Next_Number] "
GsRead += "FROM Folios WHERE LOWER(Module) = LOWER(&LsModule)"
IF TryToLock()
aTableNextNum := sql(oDataBase,GsRead)
IF LEN(aTableNextNum) = 0
MsgExclamation("No se encontro el modulo para la numeracion")
DeleteFileLock()
RETURN NIL
EndIf
GnNextNumber := aTableNextNum[1,3]
GsQueryInsert := "UPDATE Folios SET "
GsQueryInsert += "Last_Number = (Last_Number + Sequence_Count), "
GsQueryInsert += "Modify_Date = "+LdDateSQL +", "
GsQueryInsert += "Modify_Time = "+LsTimeSQL
GsQueryInsert += "WHERE LOWER(Module) = LOWER(&LsModule)"
IF .NOT. BeforeSave(GsQueryInsert)
MsgExclamation ("Error al tratar de obtener el folio siguiente.")
ENDIF
DeleteFileLock()
ENDIF
ENDIF
RETURN ( VAL(GnNextNumber ))

Pregunta: Como convierto esa pequea function en DLL y como se debe de llamar en un PRG.

De antemano agradezco la ayuda.

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 3:36 am
by Rathinagiri
Difference between DLL and LIB:

DLL is dynamically linked library (ie., linked at the runtime). LIB is statically linked library inside the EXE.

DLL can be reused by many EXE files. LIB once attached to the EXE can be used by only that EXE.

Other than that, I don't see much of a difference between these two.

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 7:49 am
by serge_girard
Thanks for clarification Rathi!

Serge

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 8:22 am
by mol
Can sb. place small sample how to load dll into .exe and later unload it?
Regards, Marek

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 8:45 am
by mlnr

Code: Select all

If !File("example.dll")
  MsgInfo ('Missing file: EXAMPLE.DLL')
  ReleaseAllWindows()
Endif
regikez:=ErrorBlock({ |objerr| ujkez(objerr,.T.) })
Begin Sequence
   jDll := hb_libLoad( hb_DirBase() + "example.dll" )
   IF !Empty( jDll )
      hb_DynCall( { "VerzioSzam", jDll, HB_DYN_CALLCONV_CDECL, HB_DYN_CTYPE_DOUBLE},@DllVersion)
      If DllVersion>1.1
         PcNev := hb_DynCall( { "PcNeve", jDll, hb_bitOr( HB_DYN_CALLCONV_STDCALL, HB_DYN_ENC_UTF16, HB_DYN_CTYPE_CHAR_PTR ),HB_DYN_CTYPE_CHAR_PTR },'*' )
      EndIf
    Else
      MsgInfo ('The program was not able to start correctly' + Chr(13) + Chr(10) + ' Please install .net framework 4' )
   EndIf
Recover Using objlocal
End Sequence
ErrorBlock(regikez) 

unload:

hb_libFree( hLib )

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 9:54 am
by Anand
Rathinagiri wrote:Difference between DLL and LIB:

DLL is dynamically linked library (ie., linked at the runtime). LIB is statically linked library inside the EXE.

DLL can be reused by many EXE files. LIB once attached to the EXE can be used by only that EXE.
Further with what Rathi said, calling functions in a DLL is same like calling in your codes, if the dll is linked statically with lib. Whereas calling the function requires dllcall with defined parameters if it is dynamically linked.

Regards,

Anand

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 3:57 pm
by srvet_claudio
The only advantage of the dll is when a very large library is shared by multiple applications or require frequent updating in library functions, so the dll is used in the practice only by software developers for programmers.

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 4:34 pm
by Rathinagiri
Rightly said Claudio.

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 8:40 pm
by jorge.posadas
Grupo,

Gracias a todos por sus comentarios, ahora me tocara investigar COMO se crea una DLL y luego el COMO se usa en mis aplicaciones

Re: DLL vs LIB

Posted: Thu Sep 01, 2016 9:51 pm
by Carlos Britos
jorge.posadas wrote:Grupo,

Gracias a todos por sus comentarios, ahora me tocara investigar COMO se crea una DLL y luego el COMO se usa en mis aplicaciones
Hi Jorge

Crear una dll con harbour no es una tarea sencilla, aunque si es posble. Deberas manejar mucho el codigo C. La gran pregunta es si se justifica todo ese trabajo para cargar una funcion.

Usarla es muy sencillo hay varios ejemplos en los samples.

Create a DLL with harbour is not easy, but not impossible. You have to do a lot of work with C code. The big question is if this big job paid for it, just to load one function.

Using dll is very simple, you can find many samples in the Samples folder.