flat assembler
Message board for the users of flat assembler.

Index > Windows > Good API reference

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
Ok im new to ASM programming and have just started win32 programming, i made this program:

format PE GUI 4.0
entry start
include 'win32a.inc'

section '.data' data readable writeable
_caption db 'hello world!',0
_message db 'Hello!!',0

section '.code' code readable executable
start:
begin:
push MB_YESNO
push _caption
push _message
push NULL
call [MessageBox]
cmp eax,IDYES
jnz begin
ret

section '.idata' import data readable writeable
library user,'USER32.dll'

import user,\
MessageBox,'MessageBoxA'

Now im looking for an API reference so I can do more than message boxes, anybody got any recommendations???
Post 05 Apr 2007, 21:14
View user's profile Send private message MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
Post 05 Apr 2007, 21:25
View user's profile Send private message MSN Messenger Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
but isn't that written for C++???
Post 05 Apr 2007, 21:26
View user's profile Send private message MSN Messenger Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
I dont really understand how to use what it says there in ASM, like in the program i posted
Post 05 Apr 2007, 21:30
View user's profile Send private message MSN Messenger Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
the
Code:
push MB_YESNO 
push _caption 
push _message 
push NULL 
call [MessageBox]
    

is same as
Code:
invoke MessageBox,NULL,_message,_caption,MB_YESNO
    

if you check on msdn or psdk for windows api reference, you would see it provide a C/C++ function prototype.
Code:
int MessageBox(
  HWND hWnd,          // handle to owner window
  LPCTSTR lpText,     // text in message box
  LPCTSTR lpCaption,  // message box title
  UINT uType          // message box style
);
    

now, the beauty of asm (assembly language) is, you don't have to care about HWND, LPCTSTR, UINT, coz they are ALL DWORD = 32bits. (period)
the int returned from the function is also a DWORD, which you could found in the EAX register after using the invoke winapiname or call [winapiname].

one of the confusion that generated for asm beginner is the concept of pointer and value.

i personally felt that this concept is actually more clearer depicted in asm rather than C or C++.

eg.
when you do
mytext db 'my string etc',0

now, when you
Code:
mov eax,mytext
    

what happened is, you move the reference (or address) of this string into register eax.

if you do,
Code:
mov eax,[mytext]
    

what happend is, it would move the 4 bytes of mytext, which is "my s" = the ascii value into EAX register.

to get more win api, i would recommend you download the free PSDK (help2 though), if you want old version, pm me, (i got those .chm version, but not so updated compare current psdk that probably provide windows vista api).
Post 05 Apr 2007, 23:07
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
btw, welcome to fasm board Wink
i am your host Twisted Evil Twisted Evil lol nah
try read the manual prepared by tomasz & teams Laughing and if you get stucked, then posting on board see if somebody free to help you Smile
Post 05 Apr 2007, 23:12
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt
You can also Try this: http://msdn2.microsoft.com/en-us/library/aa286531.aspx

And if you want to download the latest wndows (xp/vista) sdk (this is a HUGE file, so you will NEED high speed modem for this download!): http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en#QuickInfoContainer
Post 06 Apr 2007, 06:31
View user's profile Send private message Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
thank you everyone, umm two quick questions, is that PSDK the huge file thingy, and im still a little confused, could someone please tell how to put this:

HWND CreateWindow( LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent,
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);
into asm??
Post 06 Apr 2007, 19:32
View user's profile Send private message MSN Messenger Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
since we know, HWND, LPCTSTR, INT, HMENU, HINSTANCE & LPVOID, they are all just DWORD ... (see, fasm so sexy!!)
so

to use API in windows, as mentioned in my previous thread, u could use Invoke apiname, param1, param2 or push param2 push param1 then call [apiname]

so,
to use this CreateWindow api, you could.

lpClassName db 'myClassName',0
lpWindowName db 'mywindowname',0
dwStyle dd ?

mov [dwStyle], WS_VISIBLE + WS_CAPTION + ETC..

Invoke CreateWindow, lpClassName, lpWindowName, [dwStyle], x, y, w, h, [hwndparent], [hmenu], [hinstance], 0

to know what we should fill for the parameters in order to have a success return value in EAX, we just need to check the PSDK or MSDN or old win32 helpfile.

hope u see the sexiness of fasm Wink
Post 06 Apr 2007, 20:40
View user's profile Send private message Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
uh-huh I think I get it thnk you very very muchly
Post 06 Apr 2007, 20:51
View user's profile Send private message MSN Messenger Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
"uh-huh" doesn't sound so convincing
Laughing Laughing Laughing
Post 06 Apr 2007, 20:56
View user's profile Send private message Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
so umm I made this but when I run it it says entry point not found, how come??
Code:
format PE GUI 4.0
entry start 
include 'win32a.inc'

section '.data' data readable writeable 
lpWindowName db 'mywindowname',0
lpClassName db 'myclassname',0
dwStyle dd ?
hwndparent dd ?
hmenu dd ?
hinstance dd ?


section '.code' code readable executable 
start:
push 0
push [hinstance]
push [hmenu]
push [hwndparent]
push 100
push 50
push 13
push 13
push [dwStyle]
push lpWindowName
push lpClassName
call [CreateWindow]
ret 

section '.idata' import data readable writeable 
library user,'USER32.dll' 

import user,\ 
CreateWindow,'CreateWindowA'
    
Post 06 Apr 2007, 21:14
View user's profile Send private message MSN Messenger Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
I did some googling and found this program, http://www.nirsoft.net/utils/dll_export_viewer.html
it tells you the functions of a dll, do you think it will be useful to me??
Post 06 Apr 2007, 21:32
View user's profile Send private message MSN Messenger Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
a dll viewer is always a nice thing to have, i personally use depencency viewer
http://www.dependencywalker.com/

it let you inspect some function name that (assume you got no documentation) so, grab the function name and google would usually lead us to some info.

btw, to create your first window, you need to do lot of works, not just call CreateWindow and expect a window to pop up Wink
Post 06 Apr 2007, 22:08
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
ok, just did a simple one for you,
Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
hinst           dd ?
wtitle          db 'blobles in fasm',0
wclsname        db 'BLOBLES',0
wcls            WNDCLASS
wmsg            MSG
wh              dd ?

section '.code' code readable executable
start:
        invoke  GetModuleHandle,NULL
                mov     [hinst],eax
                mov     [wcls.hInstance],eax
                mov     [wcls.style],CS_HREDRAW + CS_VREDRAW
                mov     [wcls.lpfnWndProc],window_procedure
                mov     [wcls.lpszClassName],wclsname
                mov     [wcls.hbrBackground],COLOR_WINDOW + 1
        invoke  LoadIcon,NULL,IDI_APPLICATION
                push    eax
                pop     [wcls.hIcon]
        invoke  RegisterClass,wcls
        
        invoke  CreateWindowEx,0,wclsname,wtitle,WS_OVERLAPPEDWINDOW,\
                CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,\
                NULL,NULL,[hinst],NULL
                mov     [wh],eax
        invoke  ShowWindow,eax,SW_SHOW
        
        a1:
        invoke  GetMessage,wmsg,NULL,0,0
                or      eax,eax
                je      a2
        invoke  TranslateMessage,wmsg
        invoke  DispatchMessage,wmsg
                jmp     a1
        a2:
        invoke  ExitProcess,0

proc window_procedure uses ebx esi edi, hwnd, umsg, wparam, lparam
                cmp     [umsg],WM_DESTROY
                je      .wmdestroy
        
        .wmdefault:
                invoke  DefWindowProc,[hwnd],[umsg],[wparam],[lparam]
                        jmp     .wmbye
        .wmdestroy:
                invoke  PostQuitMessage,0
        .wmbye:
                        ret
endp

section '.idata' import data readable
        library kernel32,       'KERNEL32.DLL',\
                user32,         'USER32.DLL'
        include '%fasminc%\api\Kernel32.inc'
        include '%fasminc%\api\User32.inc'
    

tab at 8
Post 06 Apr 2007, 22:22
View user's profile Send private message Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
thank you very muchly
Post 07 Apr 2007, 20:33
View user's profile Send private message MSN Messenger Reply with quote
mrblobles



Joined: 05 Apr 2007
Posts: 41
mrblobles
hey this is my first 32bit program, what do you think http://www.freewebs.com/exactagecalculator/thirsty.zip
Post 08 Apr 2007, 20:00
View user's profile Send private message MSN Messenger Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 9130
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
he he
i don't have tada.wav, so i fake one Smile
all those default .wav were gone while nlite"ing"
Post 08 Apr 2007, 22:43
View user's profile Send private message Reply with quote
peter



Joined: 09 May 2006
Posts: 63
peter
Look at Iczelion's tutorials on Win32 Assembly:

http://win32assembly.online.fr/tutorials.html

Unfortunately, he uses MASM syntax, but the tutorials are still very useful for a beginner.
Post 09 Apr 2007, 01:06
View user's profile Send private message Visit poster's website Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
sleepsleep translated Iczelion's win32 asm tutorials to fasm already.


edit: http://board.flatassembler.net/topic.php?t=2158
Post 09 Apr 2007, 10:42
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.