Is it possible using Tasm(16-bit or 32-bit?) Will Tlink work? I'm not sure if it should be Tlink32, if there is such a thing. And a sample code for a function that adds two parameters would be nice.
Printable View
Is it possible using Tasm(16-bit or 32-bit?) Will Tlink work? I'm not sure if it should be Tlink32, if there is such a thing. And a sample code for a function that adds two parameters would be nice.
Hmmmmm tasm is not my choice of assembler - won't masm or fasm do?
Ill have to read some tasm documentation. to answer that.
Cheers.
which is more Tasm-like, Masm or Fasm? How would you do it on those?
ahhh tricky - are you using tasm-ideal mode? or tasm's masm compatible mode :)
the masm compatible mode is very much like masm - fasm is similar to masm though it has a few changes to make the asm syntax more sensible.
Note: Lots of stuff about assembly is still about 16 bit assembly Make sure you're learning 32-bit assembly if you want to make DLLs and windows programs.
The best way is to check out FASM documentation and samples(which I'm pretty impressed with - as they show quite simply what you need for FASM)
Ok in FASM (taken out of its examples):
Code:; DLL creation example
format PE GUI 4.0 DLL
entry DllEntryPoint
include 'win32a.inc'
section '.code' code readable executable
proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
mov eax,TRUE
ret
endp
; VOID ShowErrorMessage(HWND hWnd,DWORD dwError);
proc ShowErrorMessage hWnd,dwError
local lpBuffer:DWORD
lea eax,[lpBuffer]
invoke FormatMessage,FORMAT_MESSAGE_ALLOCATE_BUFFER+FORMAT_MESSAGE_FROM_SYSTEM,0,[dwError],LANG_NEUTRAL,eax,0,0
invoke MessageBox,[hWnd],[lpBuffer],NULL,MB_ICONERROR+MB_OK
invoke LocalFree,[lpBuffer]
ret
endp
; VOID ShowLastError(HWND hWnd);
proc ShowLastError hWnd
invoke GetLastError
stdcall ShowErrorMessage,[hWnd],eax
ret
endp
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'
import kernel,\
GetLastError,'GetLastError',\
SetLastError,'SetLastError',\
FormatMessage,'FormatMessageA',\
LocalFree,'LocalFree'
import user,\
MessageBox,'MessageBoxA'
section '.edata' export data readable
export 'ERRORMSG.DLL',\
ShowErrorMessage,'ShowErrorMessage',\
ShowLastError,'ShowLastError'
section '.reloc' fixups data discardable
You don't need a linker for FASM(its built into the assembler - one of its benefits)
Ok - hopefully you'll find it straight forward.
Some FASM specific stuff:
is bit like .CODE directive in MASM/TASM except you can call it what you like and specify its properties. In MASM I don't think you can do that- so this does make it a bit more flexible. You can define any number of sections with different parameters.Code:section '.code' code readable executable
is the imports API -Code:import kernel,\
GetLastError,'GetLastError',\
SetLastError,'SetLastError',\
FormatMessage,'FormatMessageA',\
LocalFree,'LocalFree'
If you've used VB6
\ basically means line continuation (VB6's counterpart is '_' )
Public Declare Function GetLastError() Lib "kernel32.dll" as Long etc.
Note: you don't specify the parameters in FASM, you just have to do the right numbr of parameters when you are writing your invoke code.
btw, invoke is a macro - it expands to pushes, and a call
is exporting your functions- what you want :DCode:export 'ERRORMSG.DLL',\
ShowErrorMessage,'ShowErrorMessage',\
ShowLastError,'ShowLastError'
So it is - the name of your function,'alias name of function'
Cheers.
Hope this helps. - I learnt my asm from hard slog and I still go through references and documentation whenever I write assembly because despite the simplicity of the mnemonics, perhaps the human brain refuses to remember :D
Ralph
Thanks for your efforts. I see now how to use dll's, but is that code making a dll? If so, which are the exported functions?
ShowErrorMessage and ShowLastError are the functions, 'ShowErrorMessage' and 'ShowLastError' are their externally visible names.Code:export 'ERRORMSG.DLL',\
ShowErrorMessage,'ShowErrorMessage',\
ShowLastError,'ShowLastError'
thanks, I'll try it out. By the way, where can I download the FASM version your using?
FASM site:
http://flatassembler.net/
Download latest Windows version of the assembler:
http://flatassembler.net/download.php
you can find loads of documentation and some more examples on the site. The people in forum there are very helpful as well.
Cheers.
thanks.