The MASM Forum

Projects => MASM32 => Full SDK Include Project => Topic started by: TouEnMasm on August 16, 2012, 05:57:20 AM

Title: Using functions dynamically.A library making dynamic load
Post by: TouEnMasm on August 16, 2012, 05:57:20 AM
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


Title: Re: Using functions dynamically.A library making dynamic load
Post by: jj2007 on August 16, 2012, 06:16:04 AM
How would you do the following?

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
   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
Title: Re: Using functions dynamically.A library making dynamic load
Post by: TouEnMasm on August 16, 2012, 07:15:23 AM

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.
Title: Re: Using functions dynamically.A library making dynamic load
Post by: jj2007 on August 16, 2012, 07:38:42 AM
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
Title: Re: Using functions dynamically.A library making dynamic load
Post by: TouEnMasm on August 16, 2012, 03:22:36 PM

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.
Title: Re: Using functions dynamically.A library making dynamic load
Post by: TouEnMasm on August 17, 2012, 03:51:02 AM

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