I have been having problems when using the inkey macro:
QuoteMicrosoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: C:\Users\Michael\Desktop\Console.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
masm32.lib(wait_key.obj) : error LNK2001: unresolved external symbol __imp___get
ch
masm32.lib(wait_key.obj) : error LNK2001: unresolved external symbol __imp___kbh
it
Console.exe : fatal error LNK1120: 2 unresolved externals
_
Link error
Press any key to continue . . .
The code I am using is:
.486
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\dialogs.inc
include \masm32\macros\macros.asm
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
.data
.data?
.code
Start:
xor ebx, ebx
inkey
invoke ExitProcess, ebx
end Start
I am just doing Project >> Console Assemble & Link. Could anyone help me out please ?
Include both the MSVCRT.INC file and use includelib for MSVCRT.LIB. :bg
Works flawlessly now ! Thanks very much hutch.
I came across another small problem just now also:
.486
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\gdi32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\shell32.inc
include \masm32\include\oleaut32.inc
include \masm32\include\dialogs.inc
include \masm32\include\MSVCRT.INC
include \masm32\macros\macros.asm
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\oleaut32.lib
includelib \masm32\lib\MSVCRT.LIB
.data
SelectYes db "Yes was selected",0
SelectNo db "No was selected",0
MakeSelection db "Please make your selection [Y/N] : ",0
ConsoleTitle db "Console Title",0
.data?
Selection byte ?
.code
Start:
xor ebx, ebx
invoke AllocConsole
invoke SetConsoleTitle, addr ConsoleTitle
Choice:
invoke StdOut, addr MakeSelection
invoke StdIn, addr Selection, 1
mov al, Selection
cmp al, 89
je YesWasSelected
cmp al, 121
je YesWasSelected
cmp al, 78
je NoWasSelected
cmp al, 110
je NoWasSelected
print " ", 13, 10
jmp Choice
YesWasSelected:
print " ", 13, 10
invoke StdOut, addr SelectYes
print " ", 13, 10
inkey
jmp FinishProgram
NoWasSelected:
print " ", 13, 10
invoke StdOut, addr SelectNo
print " ", 13, 10
inkey
FinishProgram:
invoke ExitProcess, ebx
end Start
As you can see, it just compares whether what you inputted was Y/y or N/y. If it is not either, then it will repeat the StdOut and StdIn call. My question is why that procedure is looped 3 times when the input is not Y or y or N or n. It should do it once only surely but when I stepped the code in Olly, I found that it does it 3 times too. I mean, if I needed to, I'm sure I could make it do a check whether that call has already been made (eg. set some sort of boolean byte to a certain value and test it) but I just want to see whether I'm somehow using these functions wrong or something.
I am currently thinking perhaps this is a problem with ReadFile which is called by StdIn. Perhaps this is why it is not pausing and waiting for input as expected.
Slugsnack,
Since your input buffer (Selection) is only one byte in length, Stdin is processing the carriage return and line feed that are in the standard input on the next call, thus the two additional loops. Make your input buffer at least large enough for the input character plus the CR and LF and you won't have that problem.
I'm not exactly sure what you are trying to do but if you are linking with /SUBSYSTEM:CONSOLE then the call to AllocConsole will fail, you don't need it. If you are linking with /SUBSYSTEM:WINDOWS then AllocConsole and your program work fine.
Yes I am using normal assemble + link so it is all good.
I will try your suggestion though, thanks for your help, probably wouldn't've figured that one out for a while :P