MASM - Как вызвать функцию из API консоли в сборке? - PullRequest
0 голосов
/ 17 февраля 2020

(Консольный API, на который я ссылаюсь, здесь: https://docs.microsoft.com/en-us/windows/console/console-functions)

В настоящее время я пытаюсь написать программу Hello World на MASM, и мне нужно использовать функция из этого API (в частности, функция «WriteFunction»). Я оглянулся, чтобы найти, как я могу вызвать одну из этих функций из MASM, но не могу найти ответ, который работает в Visual Studio 2019.

Решение, которое я обнаружил, что не работает, использует операторы include, но когда я пытаюсь их использовать, программа говорит, что не может открыть ни один из файлов. Решение находится здесь: Вывод Hello World в MASM с использованием функций WIN32

.386 ; 386 Processor Instruction Set

.model flat,stdcall ; Flat memory model and stdcall method

option casemap:none ; Case Sensitive

;Libaries and Include files used in this project

; Windows.inc defines alias (such as NULL and STD_OUTPUT_HANDLE in this code
include \masm32\include\windows.inc 

; Functions that we use (GetStdHandle, WriteConsole, and ExitProcess)
; Listing of all available functions in kernel32.lib
include \masm32\include\kernel32.inc 
; Actuall byte code available of the functions
includelib \masm32\lib\kernel32.lib  

.data
; Labels that with the allocated data (in this case Hello World!...) that are aliases to memory.
output db "Hello World!", 0ah, 0h; This String Hello World! and then a the newline character \n (0ah) and then the null character 0h

.code 
start: 

; --------------------------------------------------------------------------------------------------------------------------------------
; Retrieves that handle to the output console
;
; ====Arguments===
;
; STD_OUTPUT_HANDLE - alias for -11 and indicates that we want the handle to 
;                     write to console output
;
invoke GetStdHandle, STD_OUTPUT_HANDLE
; --------------------------------------------------------------------------------------------------------------------------------------

; --------------------------------------------------------------------------------------------------------------------------------------
; Writes the text in output (.data section) to the console
;
; ====Arguments===
;
; eax - the handle to the console buffer
;
; addr output - pass by reference the text of output (Hello World!)
;
; sizeof output - the size of the string so that the WriteConsole knows when to 
;                 stop (doesn't support NULL terminated strings I guess);
;
; ebx - secondary "return" value that contains the number of bytes written (eax
;       is used for an error code)
;
; NULL - this is reserved and MSDN says just to pass NULL
;
; MSDN Link: http://msdn.microsoft.com/en-us/library/ms687401(v=VS.85).aspx
;
invoke WriteConsole, eax, addr output, sizeof output, ebx, NULL
; --------------------------------------------------------------------------------------------------------------------------------------

; --------------------------------------------------------------------------------------------------------------------------------------
; Exits the program with return code 0 (default one that usually is used to 
; indicate that the program did not error
;
; ====Arguments===
;
; 0 - the exit code
;
; MSDN Link: http://msdn.microsoft.com/en-us/library/ms682658(VS.85).aspx
;
invoke ExitProcess, 0
; --------------------------------------------------------------------------------------------------------------------------------------

end start 

Когда я пробую это решение, он говорит: «не удается открыть файл» \ masm32 \ include \ windows .in c "Я работаю из Microsoft Visual Studio 2019, с MASM, включенным в качестве зависимости сборки.

EDIT: два файла .in c не импортируются успешно, но файл .lib работает просто отлично.

EDIT2: Другая ошибка, которую я получаю, заключается в том, что WriteConsole (метод из API) является неопределенным символом

...