;==============================================================================
;	    Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE	311
;==============================================================================

;==============================================================================
; ==> ASM example calling a function inside a DLL indirectly ( implicit ) !
;------------------------------------------------------------------------------
; 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__310.lib ) !
; We declare our function ( Dll_Test01		PROTO :DWORD,:DWORD ) !
; 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			; specifies the processor our program want run on
.Model Flat ,StdCall	; always the same for Win95 (32 Bit)
option casemap:none	; case sensitive !!!

;==============================================================================
; Include all files where API functions resist you want use, set correct path !
;------------------------------------------------------------------------------
include \masm32\include\windows.inc
includelib \masm32\lib\kernel32.lib		;windows library
includelib \masm32\lib\user32.lib		;windows library
includelib td__310.lib				;our own library (!)

;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;------------------------------------------------------------------------------
GetModuleHandleA	PROTO :DWORD		;windows API function
ExitProcess		PROTO :DWORD		;windows API function
Dll_Test01		PROTO :DWORD,:DWORD	;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;
hInstance		dd 0h		;

;==============================================================================
; .Data?	= the data? area starts here, not defined and not fixed
;------------------------------------------------------------------------------
.data?

;==============================================================================
; .CODE	= our code area starts here	Main = label of our program code
;------------------------------------------------------------------------------
.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__311.asm					;asm command
; link.exe /subsystem:windows td__311.obj			;link command
;==============================================================================