Вы находитесь на странице: 1из 2

td_win32asm_311.asm

;==============================================================================

; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE

;==============================================================================

;==============================================================================

; ==> Part 311 : ASM example calling a function inside a DLL indirectly !

;------------------------------------------------------------------------------

; Thanks to Arnulfo for the idea to write this ASM / DLL example.

; If you encounter any ERROR please email me.

; OK, let's go :

; Because we are focussed to learn the DLL stuff here is no Main Window.

; This source code is like a standard asm file.

; We include our library ( td_win32asm_310.lib ) !

; We declare our function ( Dll_Test01

; API GetModuleHandleA gets our program ID.

; Now we call our function.

; API=ExitProcess terminates our program.

; Look to the end of this file how to create the EXE file.

;==============================================================================

; Assembler directives

;------------------------------------------------------------------------------

.386

311

PROTO :DWORD,:DWORD ) !

; specifies the processor our program want run on ; always the same for Win95 (32 Bit) ; case sensitive !!!

.Model Flat ,StdCall option casemap:none

;==============================================================================

; Include all files where API functions resist you want use, set correct path !

;------------------------------------------------------------------------------

include D:\Masm32\include\windows.inc

includelib kernel32.lib includelib user32.lib includelib td_win32asm_310.lib

;windows library ;windows library ;our own library (!)

;==============================================================================

; Declaration of used API functions,take a look into WIN32.HLP and *.inc files

;------------------------------------------------------------------------------

GetModuleHandleA ExitProcess

Dll_Test01

PROTO :DWORD PROTO :DWORD PROTO :DWORD,:DWORD

;windows API function ;windows API function ;our own function (!)

;==============================================================================

; .const = the constants area starts here, constants are defined & fixed

;------------------------------------------------------------------------------

.const

;==============================================================================

; .Data = the data area starts here, datas are defined but not fixed

;------------------------------------------------------------------------------

.Data Dll_Function_Parameter2 db "Message Box inside DLL",0; Dll_Function_Parameter1 db "inside a DLL, the pointer to this text",13,10; db "is given to the DLL as a parameter.",0; Page 1

td_win32asm_311.asm

;==============================================================================

; .Data? = the data? area starts here, not defined and not fixed

;------------------------------------------------------------------------------

.data?

hInstance

dd ?

;

;==============================================================================

; .CODE = our code area starts here

;------------------------------------------------------------------------------

.Code

Main = label of our program code

Main:

;==============================================================================

; Always get your program ID first (API=GetModuleHandleA)

;------------------------------------------------------------------------------

push

0h

;lpModuleHandle, 0=get program handle

call

GetModuleHandleA

;- API Function -

mov

hInstance,eax

;return value in eax=handle of program

;==============================================================================

; Here we call our function in our own DLL with 2 parameter.

; Our function inside the DLL creates a message box with an OK button.

; We transfer the pointer to the message box titel to the function (Parameter2)

; We transfer the pointer to the message box text to the function (Parameter1)

;------------------------------------------------------------------------------

push

OFFSET Dll_Function_Parameter2 ;push the pointer to message box titel

push

OFFSET Dll_Function_Parameter1 ;push the pointer to message box text

call

Dll_Test01

;- DLL Function -

;==============================================================================

; Next we terminate our program (API=ExitProcess)

;------------------------------------------------------------------------------

ExitPrg:

push

hInstance

;push our programm handle to exit

call

ExitProcess

;- API Function -

;==============================================================================

; end Main

;------------------------------------------------------------------------------

= end of our program code

end Main

;end of our program code, entry point

;==============================================================================

; To create the exe file use this commands with your Microsoft Assembler/Linker

;------------------------------------------------------------------------------

; ml.exe /c /coff td_win32asm_311.asm

;asm command

; link.exe /subsystem:windows td_win32asm_311.obj

;link command

;==============================================================================

Page 2