News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Using functions dynamically.A library making dynamic load

Started by TouEnMasm, August 16, 2012, 05:57:20 AM

Previous topic - Next topic

TouEnMasm

This tool read an header file and search the define prototypes (PROTO) in it.
He write the code of a library who load dynamically the functions.
You have some modifies to do at the source code.
See at the end of the files,all is explain.
Ml will prompt you with errors if you forgot somethings.
=====================================================
Usage is simple
Include the header
include the lib
add the two prototypes  xxx_SearchAdresse and xxx_FreeLibrary.
invoke xxx_SearchAdresse,addr "Name-of.dll"

Now you can use the fonctions of the header.

At the end,invoke xxx_FreeLibrary

corrected an error on the product code:
invoke GetProcAddress,Hlibrairie,esi
instead of :invoke GetProcAddress,Hdll,esi


Fa is a musical note to play with CL

jj2007

How would you do the following?

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   Dll "shimgvw"      ; load the shell image view dll aka Windows Picture and Fax Viewer Library
   Declare ImageView_Fullscreen, 4      ; ImageView_Fullscreen expects 4 dwords
   void ImageView_Fullscreen(0, 0, wCL$(1), SW_SHOW)   ; we need the wide version of the commandline arg
   Exit
end start

TouEnMasm


I don't see wath is the related matters with using the masm functions dynamically??????.
Sorry i don't know your basic !
"I give my tongue to the cat" ,french expression.
Fa is a musical note to play with CL

jj2007

tried to get your prog running, tested with msvcrt, but the result looks very cryptic, see below. So I wanted to give you a simple example...

StatDyn.exe with msvcrt:
; #########################################################################
.386                      ; force 32 bit code
.model flat, stdcall      ; memory model & calling convention
option casemap :none      ; case sensitive

include \masm32\include\windows.inc
; include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
; include \masm32\include\masm32.inc
include macros.txt


;
;Extern defines
; EXTERNDEF Copier :PROTO  :DWORD,:DWORD
; EXTERNDEF EtatMemoirePile :MEMORY_BASIC_INFORMATION
; EXTERNDEF PoriginePile:DWORD

; déclarations

.data
Hlibrairie dd 0
dd 0,0
.code

;used of the proc
;adress of the dll name IN
;example
;invoke xxx_SearchAdresse,SADR("user32.dll")
The xxx_ must be replaced by the name of the include
xxx_SearchAdresse PROC uses esi edi pNomDLL:DWORD
Local  retour:DWORD
Local  Hdll:DWORD
;Local    [LimiteMaxPhrase]:BYTE
      mov retour,0
invoke LoadLibrary,pNomDLL
mov Hlibrairie,eax
.if eax == 0
;invoke Finderrormessage, SADR("LoadLibrary failed")"
jmp FindeSearchAdresse
.endif
lea esi,ADR.. put here the name of the first data beginning by ADR
NouvelleAdresse:
mov edi,esi
add esi,4
invoke GetProcAddress,Hdll,esi
mov [edi],eax
.if eax == 0
;invoke Finderrormessage,esi
;jmp FindeSearchAdresse
.endif
;passer le nom
@@:
.if byte ptr [esi] != 0
inc esi
jmp @B
.endif
inc esi ;passe le zero de fin de nom
.if dword ptr [esi+4] != 0
jmp NouvelleAdresse
.endif
mov retour,1
FindeSearchAdresse:
         mov eax,retour
         ret
xxx_SearchAdresse endp



xxx_FreeLibrary PROC
invoke FreeLibrary,Hlibrairie
ret
xxx_FreeLibrary endp
end

TouEnMasm


If you want an answer,put here the file you try to use to made a dynamic library.
The file you use seem to have no define PROTOTYPES in it.
Fa is a musical note to play with CL

TouEnMasm


Here is a small demo (4k) using dynamically the crt(sprintf_s).
Show how to solve a problem with VARARG
Fa is a musical note to play with CL