|
-
Apr 26th, 2006, 11:00 AM
#1
Thread Starter
Frenzied Member
How to create a dll in assembly...
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.
-
Apr 26th, 2006, 11:48 AM
#2
Addicted Member
Re: How to create a dll in assembly...
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.
-
Apr 26th, 2006, 12:21 PM
#3
Thread Starter
Frenzied Member
Re: How to create a dll in assembly...
which is more Tasm-like, Masm or Fasm? How would you do it on those?
-
Apr 27th, 2006, 09:00 AM
#4
Addicted Member
Re: How to create a dll in assembly...
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:
Code:
section '.code' code readable executable
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:
import kernel,\
GetLastError,'GetLastError',\
SetLastError,'SetLastError',\
FormatMessage,'FormatMessageA',\
LocalFree,'LocalFree'
is the imports API -
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
Code:
export 'ERRORMSG.DLL',\
ShowErrorMessage,'ShowErrorMessage',\
ShowLastError,'ShowLastError'
is exporting your functions- what you want 
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 
Ralph
-
Apr 27th, 2006, 01:54 PM
#5
Thread Starter
Frenzied Member
Re: How to create a dll in assembly...
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?
-
Apr 27th, 2006, 04:25 PM
#6
Re: How to create a dll in assembly...
Code:
export 'ERRORMSG.DLL',\
ShowErrorMessage,'ShowErrorMessage',\
ShowLastError,'ShowLastError'
ShowErrorMessage and ShowLastError are the functions, 'ShowErrorMessage' and 'ShowLastError' are their externally visible names.
-
Apr 28th, 2006, 01:27 AM
#7
Thread Starter
Frenzied Member
Re: How to create a dll in assembly...
thanks, I'll try it out. By the way, where can I download the FASM version your using?
-
Apr 28th, 2006, 07:11 AM
#8
Addicted Member
Re: How to create a dll in assembly...
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.
-
May 1st, 2006, 06:10 PM
#9
Thread Starter
Frenzied Member
Re: How to create a dll in assembly...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|