WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Sponsors
Articles
Programming Quick Start
32-bit Assembler is Easy
Porting Iczelion tutorials
What is FASM
Hard Drive Recovery
Wiring your own LAN
Personal menu
Welcome Guest
User:
Pass:
Register!
Resend Validation Email
 
Forum
Pages (3) [1] 2 3   ( Go to first unread post )

Calling API Functions, how do we call API Functions in pure assembly (MASM32) at such a low level?

shadyike
Quote Post


New Member
*

Group: Members
Posts: 9
Member No.: 5716
Joined: 26-December 07


I don't understand something about masm32 here is a basic program to call a messagebox

CODE


.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc  
include user32.inc
includelib kernel32.lib  
includelib user32.lib

.data
MsgBoxCaption  db "Simple MessageBox Program",0
MsgBoxText     db "Hello World!",0

.code
start:
invoke MessageBox, NULL, addr MsgBoxText, addr MsgBoxCaption, MB_OK  
invoke ExitProcess,0
end start


My question is why can't we use pure assembly to call this message box is it possible to call a message box on such a low level

CODE

push 0

push "Title"

push "Text"

push 0

call User32.MessageBoxA



To me the code above seems easier than the mess at the top i just want to know if its possible to code a message box like this.


EDIT*****

Here is my idea for calling a message box it does not work could some one tell me why

CODE


.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc  
include user32.inc
includelib kernel32.lib  
includelib user32.lib


.data



.data?

db ?
.code
start:

push 0

push push 0

push push 0

push 0

call User32.MessageBoxA


invoke ExitProcess,0
end start




I'm pretty new to coding with asm i understand asm but i don't know how to code with it.

PMEmail Poster
Top
shoorick
Quote Post


Extremely Active Member
******

Group: Admins
Posts: 2301
Member No.: 160
Joined: 22-June 04


1.sure, you can use push/call instead of invoke, the main reason is readability of code - invoke takes usually single line in text.

2.what a sense to use prefix of dll name? api names designed so their names are not repeated in different dlls in general.
PMEmail PosterUsers Website
Top
samael
Quote Post


Typo-lord
******

Group: Moderators
Posts: 404
Member No.: 5187
Joined: 10-June 07


You spent too much time staring at debuggers... tongue.gif

The dllname.Function in debuggers, is a convention in order to show the module the function is located to, in order to make your life easier locating bugs.

When you program something, you are supposed to know where the function you are about to call is located.

This is about as low as it can be:

CODE
.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc  
include user32.inc
includelib kernel32.lib  
includelib user32.lib

.data



.data?

db ?
.code
start:

push 0
push 0
push 0
push 0
call MessageBoxA


invoke ExitProcess,0
end start
PM
Top
shadyike
Quote Post


New Member
*

Group: Members
Posts: 9
Member No.: 5716
Joined: 26-December 07


Thanks for the info i find this lower level easier to understand then the higher level.

If i wanted to add a title and text in the msg box in your example code do i have to define the strings as var?

This post has been edited by samael on Dec 26 2007, 03:26 AM
PMEmail Poster
Top
samael
Quote Post


Typo-lord
******

Group: Moderators
Posts: 404
Member No.: 5187
Joined: 10-June 07


CODE
.386
.model flat, stdcall
option casemap:none

include windows.inc
include kernel32.inc  
include user32.inc
includelib kernel32.lib  
includelib user32.lib

.data

szCaption    db "Caption",0; Must be zero-terminated
szText       db "Hi, i'm the messagebox text",0  ; Must be zero-terminated too

;db stands for BYTE
;dw stands for WORD
;dd stands for DWORD


.data?


.code
start:

push MB_OK             ;uType
push OFFSET szCaption  ;pszCaption : Pointer to the caption string
push OFFSET  szText    ;pszText : Pointer to the text string
push 0                 ;HWND
call MessageBoxA


invoke ExitProcess,0
end start


To start smooth with assembly, consider spending some time reading Iczelion's Tutorials.

http://www.winasm.net/index.php?ind=downlo...ry_view&iden=47
PM
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages (3) [1] 2 3  Reply to this topicStart new topicStart Poll

 

Sponsors
Computer Science

Internet
C/C++
Hardware & PC maintenance

HiEditor

General Discussions
Suggestions/Bug Reports
WinAsm Studio

General Discussions
Suggestions/Bug Reports
WinAsm Studio FAQ
Multilingual User Interface
Add-Ins
Assembly Programming

Main
Newbies
Projects
Custom Controls
Snippets
Announcements & Rules

Announcements

General

Online Degrees - Distance Learning
The Heap
Russian
Google