Página 1 de 1

Listar funções de uma DLL

Enviado: 28 Jul 2016 11:24
por rossine
Olá,

Alguém sabe se é possível, através do harbour, listar as funções que estão contidas em uma determinada DLL ?

Obrigado,

Listar funções de uma DLL

Enviado: 28 Jul 2016 12:42
por JoséQuintas
Não dá pra conseguir com o fabricante?
Às vezes tem restrições, ou conversão de dados que impedem o uso, mesmo sabendo os nomes.
Só de tipos numéricos, devem existir mais de 10 tipos diferentes.
E pode ser necessário passar o parâmetro como valor ou como pointer (por referência), ou com tamanho específico no caso de strings.

Listar funções de uma DLL

Enviado: 29 Jul 2016 10:58
por rossine
Olá José,

Meu intuito é conseguir esta lista de uma DLL criada por mim mesmo em harbour.
Eu queria saber se além das minhas funções o harbour acrescenta alguma função extra dentro da DLL.

Obrigado,

Listar funções de uma DLL

Enviado: 02 Ago 2016 06:29
por vailton
Eu queria saber se além das minhas funções o harbour acrescenta alguma função extra dentro da DLL.
Neste caso é possível sim, existe um aplicativo chamado depends.exe (google it!) que lista todas as funções exportadas por usa .DLL além de todas as .DLL que foram linkadas diretamente junto ao executável (excetua-se as que são carregadas via loadlibrary pelo programador). Roda com .DLLs e tabmém com .EXEs.

Espero ter ajudado.

Listar funções de uma DLL

Enviado: 02 Ago 2016 11:03
por rossine
Olá Vailton,

Como vão as coisas aí em sampa ?

Olha instalei o dependency Walker aqui e chamei direto a minha Dll e consegui as funções que estão linkadas nela.

Valeu pela dica e grande abraço pra turma aí :-)

Rossine.

Listar funções de uma DLL

Enviado: 03 Fev 2017 21:15
por Claudio Soto
En HMG oficial existe la funcion escrita en C:

HMG_GetDLLFunctions ()
Returns an array with all functions names from specific DLL file
 
Useful function to retrieves functions name in DLL files.
 
 
HMG_GetDLLFunctions( cDllName ) --> return array { cFuncName1, cFuncName2, ... }


Buscar en la carpeta Source el código fuente de esta función. En este momento no recuerdo en cuál archivo está definido, pero lo pueden encontrar fácilmente buscando por ej. Con Notepad++, con la opción find in Files.

Listar funções de uma DLL

Enviado: 04 Fev 2017 18:13
por rossine
Olá Claudio Soto,

Primeiramente muito obrigado por responder e com suas dicas eu consegui fazer o que eu precisava.

Montei um código de teste que mostro abaixo:

Obs: Claudio eu consegui compilar e executar o código abaixo normalmente mas ele está correto ?

Código: Selecionar todos

function main( cDll )

cls

? hb_valtoexp( HMG_GetDLLFunctions( cDll ) )

return NIL

#pragma BEGINDUMP

#include <shlobj.h>
#include <windows.h>
#include <commctrl.h>
#include <psapi.h>
#include <tchar.h>
//#include <winreg.h>
//#include <uxtheme.h>
#include <imagehlp.h>
#include "hbapiitm.h"
#include "hbapi.h"
#include "hbapifs.h"

/*****************************************************************************************
*   MACRO DEFINITION FOR CALL DLL FUNCTION
******************************************************************************************/

#define HMG_DEFINE_DLL_FUNC(\
                             _FUNC_NAME,             \
                             _DLL_LIBNAME,           \
                             _DLL_FUNC_RET,          \
                             _DLL_FUNC_TYPE,         \
                             _DLL_FUNC_NAMESTRINGAW, \
                             _DLL_FUNC_PARAM,        \
                             _DLL_FUNC_CALLPARAM,    \
                             _DLL_FUNC_RETFAILCALL   \
                            )\
\
_DLL_FUNC_RET _DLL_FUNC_TYPE _FUNC_NAME _DLL_FUNC_PARAM \
{\
   typedef _DLL_FUNC_RET (_DLL_FUNC_TYPE *PFUNC) _DLL_FUNC_PARAM;\
   static PFUNC pfunc = NULL;\
   if (pfunc == NULL)\
   {\
      HMODULE hLib = LoadLibrary (_TEXT (_DLL_LIBNAME) );\
      pfunc = (PFUNC) GetProcAddress (hLib, _DLL_FUNC_NAMESTRINGAW);\
   }\
   if(pfunc == NULL)\
      return ((_DLL_FUNC_RET) _DLL_FUNC_RETFAILCALL);\
   else\
      return pfunc _DLL_FUNC_CALLPARAM;\
}

HMG_DEFINE_DLL_FUNC ( win_Shell_GetImageLists,                            // user function name
                      "Shell32.dll",                                      // dll name
                      BOOL,                                               // function return type
                      WINAPI,                                             // function type
                      "Shell_GetImageLists",                              // dll function name
                      (HIMAGELIST *phimlLarge, HIMAGELIST *phimlSmall),   // dll function parameters (types and names)
                      (phimlLarge, phimlSmall),                           // function parameters (only names)
                      FALSE                                               // return value if fail call function of dll
                    )

//********************************
// by Dr. Claudio Soto, June 2015
//********************************

HMG_DEFINE_DLL_FUNC ( win_MapAndLoad,   // user function name
                      "Imagehlp.dll",   // dll name
                      WINBOOL,          // function return type
                      WINAPI,           // function type
                      "MapAndLoad",     // dll function name
                      (PCSTR ImageName, PCSTR DllPath, PLOADED_IMAGE LoadedImage, WINBOOL DotDll, WINBOOL ReadOnly),   // dll function parameters (types and names)
                      (ImageName, DllPath, LoadedImage, DotDll, ReadOnly),   // function parameters (only names)
                      FALSE                                                  // return value if fail call function of dll
                    )

HMG_DEFINE_DLL_FUNC ( win_UnMapAndLoad,   // user function name
                      "Imagehlp.dll",     // dll name
                      WINBOOL,            // function return type
                      WINAPI,             // function type
                      "UnMapAndLoad",     // dll function name
                      (PLOADED_IMAGE LoadedImage),   // dll function parameters (types and names)
                      (LoadedImage),                 // function parameters (only names)
                      FALSE                          // return value if fail call function of dll
                    )

HMG_DEFINE_DLL_FUNC ( win_ImageDirectoryEntryToData,   // user function name
                      "Dbghelp.dll",                   // dll name
                      PVOID,                           // function return type
                      WINAPI,                          // function type
                      "ImageDirectoryEntryToData",     // dll function name
                      (PVOID Base, BOOLEAN MappedAsImage, USHORT DirectoryEntry, PULONG Size),   // dll function parameters (types and names)
                      (Base, MappedAsImage, DirectoryEntry, Size),   // function parameters (only names)
                      NULL                                           // return value if fail call function of dll
                    )

HMG_DEFINE_DLL_FUNC ( win_ImageRvaToVa,   // user function name
                      "Dbghelp.dll",      // dll name
                      PVOID,              // function return type
                      WINAPI,             // function type
                      "ImageRvaToVa",     // dll function name
                      (PIMAGE_NT_HEADERS NtHeaders,PVOID Base,ULONG Rva,PIMAGE_SECTION_HEADER *LastRvaSection),   // dll function parameters (types and names)
                      (NtHeaders, Base, Rva, LastRvaSection),   // function parameters (only names)
                      NULL                                      // return value if fail call function of dll
                    )

//        HMG_GetDLLFunctions( cDllName ) --> return array { cFuncName1, cFuncName2, ... }
HB_FUNC ( HMG_GETDLLFUNCTIONS )
{
    CHAR *cDllName = (CHAR *) hb_parc (1);
    DWORD *dNameRVAs = NULL;
    LOADED_IMAGE LI;
    IMAGE_EXPORT_DIRECTORY *IED;
    ULONG DirSize;
    CHAR *cFuncName;

    if ( win_MapAndLoad (cDllName, NULL, &LI, TRUE, TRUE) )
    {
        IED = (IMAGE_EXPORT_DIRECTORY *) win_ImageDirectoryEntryToData (LI.MappedAddress, FALSE, IMAGE_DIRECTORY_ENTRY_EXPORT, &DirSize);
        if (IED != NULL)
        {
            dNameRVAs = (DWORD *) win_ImageRvaToVa (LI.FileHeader, LI.MappedAddress, IED->AddressOfNames, NULL);
            ULONG i;
            hb_reta ( IED->NumberOfNames );
            for(i = 0; i < IED->NumberOfNames; i++)
            {
                cFuncName = (CHAR *) win_ImageRvaToVa (LI.FileHeader, LI.MappedAddress, dNameRVAs[i], NULL);
                hb_storvc ( cFuncName, -1, i + 1 );
            }
        }
        win_UnMapAndLoad (&LI);
    }
}

#pragma ENDDUMP
Mais uma vez, muito obrigado,

Listar funções de uma DLL

Enviado: 04 Fev 2017 22:50
por Claudio Soto
A simple vista me parece que esta ok.
Siempre es un placer poder ayudar.

Nota: la siguiente definición no es necesaria en este código.

HMG_DEFINE_DLL_FUNC ( win_Shell_GetImageLists,                            // user function name
                      "Shell32.dll",                                      // dll name
                      BOOL,                                               // function return type
                      WINAPI,                                             // function type
                      "Shell_GetImageLists",                              // dll function name
                      (HIMAGELIST *phimlLarge, HIMAGELIST *phimlSmall),   // dll function parameters (types and names)
                      (phimlLarge, phimlSmall),                           // function parameters (only names)
                      FALSE                                               // return value if fail call function of dll
                    )

Listar funções de uma DLL

Enviado: 05 Fev 2017 01:00
por rochinha
Amiguinhos,

Eu uso o bom e velho IMPLIB da Borland e depois abro a .LIB gerada com ExplorerLIB 2.0.

Código: Selecionar todos

IMPLIB NomeDaDLL.lib NomeDaDLL.dll
Com este comando uma biblioteca será gerada a partir da .DLL especificada.

ExplorerLIB 2.0

Listar funções de uma DLL

Enviado: 05 Fev 2017 09:25
por rossine
Bom dia,
Claudio Soto escreveu:A simple vista me parece que esta ok.
Siempre es un placer poder ayudar.

Nota: la siguiente definición no es necesaria en este código.

HMG_DEFINE_DLL_FUNC ( win_Shell_GetImageLists, // user function name
"Shell32.dll", // dll name
BOOL, // function return type
WINAPI, // function type
"Shell_GetImageLists", // dll function name
(HIMAGELIST *phimlLarge, HIMAGELIST *phimlSmall), // dll function parameters (types and names)
(phimlLarge, phimlSmall), // function parameters (only names)
FALSE // return value if fail call function of dll
)
Ok, tirei esta parte do código e compilou normalmente. Muito obrigado :-Y
rochinha escreveu:Amiguinhos,

Eu uso o bom e velho IMPLIB da Borland e depois abro a .LIB gerada com ExplorerLIB 2.0.

Código: Selecionar todos

IMPLIB NomeDaDLL.lib NomeDaDLL.dll
Com este comando uma biblioteca será gerada a partir da .DLL especificada.

ExplorerLIB 2.0
Ótima dica Rochinha, obrigado.