0%

MASM : MS-Windows Programming (1)

用書:Assembly Language for x86 Processors 7th Edition, Global Edition
Chapter 11: MS-Windows Programming

- Classifying Console Functions 分類終端機函式

Text-oriented (high-level) console functions 文本導向(高階)的終端機函式

  • Read character streams from input buffer 從輸入緩衝器讀取字元
  • Write character streams to screen buffer 寫入字元到屏幕緩衝器
  • Redirect input and output 將輸入輸出重新導向

Event-oriented (low-level) console functions 事件導向(低階)的終端機函式

  • Retrieve keyboard and mouse events 取得鍵盤跟滑鼠的事件
  • Detect user interactions with the console window 偵測使用者所在的終端機視窗
  • Control window size & position, text colors 控制視窗大小,位置,字的顏色

- API and SDK 應用程式介面&軟體開發工具包

Microsoft Win32 Application Programming Interface

  • API: a collection of types, constants, and functions that provide a way to directly manipulate objects through

Microsoft Platform Software Development Kit

  • SDK: a collection of tools, libraries, sample code, and documentation that helps programmers create
    applications
  • Platform: an operating system or a group of closely

- Translating Windows Data Types 對照windows的資料型別

Windows Type(s) MASM Type
BOOL DWORD
LONG SDWORD
COLORREF,HANDLE,LPARAM,LRESULT,UINT,WNDPROC DWORD
LPTSTR PTR WORD
WORD WORD

- Standard Console Handles 標準console處理

  • A handle is an unsigned 32-bit integer.
  • The following MS-Windows constants are predefined to specify the type of handle requested:

STD_INPUT_HANDLE : standard input
STD_OUTPUT_HANDLE : standard output
STD_ERROR_HANDLE : standard error output

- GetStdHandle

  • GetStdHandle returns a handle to a console stream
  • Specify handle type
  • The handle is returned in EAX
  • Prototype:
1
2
GetStdHandle PROTO,
nStdHandle:DWORD ; handle type
  • Sample call:
1
2
INVOKE GetStdHandle, STD_OUTPUT_HANDLE
mov myHandle, eax

- Console Input

  • The ReadConsole function provides a convenient way to read text input and put it in a buffer.
  • Prototype:
1
2
3
4
5
6
ReadConsole PROTO,
handle:DWORD, ; input handle
pBuffer:PTR BYTE, ; pointer to buffer
maxBytes:DWORD, ; number of chars to read
pBytesRead:PTR DWORD, ; ptr to num bytes read
notUsed:DWORD ; (not used)

- WriteConsole

  • The WriteConsole function writes a string to the screen, using the console output handle. It acts upon standard ASCII control characters such as tab, carriage return, and line feed.
  • Prototype:
1
2
3
4
5
6
WriteConsole PROTO,
handle:DWORD, ; output handle
pBuffer:PTR BYTE, ; pointer to buffer
bufsize:DWORD, ; size of buffer
pCount:PTR DWORD, ; output count
lpReserved:DWORD ; (not used)