td win32asm 311.asm
DESCRIPTION
Skola asemblera TD zakonTRANSCRIPT
td_win32asm_311.asm;==============================================================================; Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE 311;==============================================================================
;==============================================================================; ==> 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 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 D:\Masm32\include\windows.incincludelib kernel32.lib ;windows libraryincludelib user32.lib ;windows libraryincludelib td_win32asm_310.lib ;our own library (!)
;==============================================================================; Declaration of used API functions,take a look into WIN32.HLP and *.inc files;------------------------------------------------------------------------------GetModuleHandleA PROTO :DWORD ;windows API functionExitProcess PROTO :DWORD ;windows API functionDll_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;------------------------------------------------------------------------------.DataDll_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 Main = label of our program code;------------------------------------------------------------------------------.CodeMain:
;==============================================================================; Always get your program ID first (API=GetModuleHandleA);------------------------------------------------------------------------------push 0h ;lpModuleHandle, 0=get program handlecall 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 titelpush OFFSET Dll_Function_Parameter1 ;push the pointer to message box textcall Dll_Test01 ;- DLL Function -
;==============================================================================; Next we terminate our program (API=ExitProcess);------------------------------------------------------------------------------ExitPrg:push hInstance ;push our programm handle to exitcall 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