News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Irvine32 library problem

Started by ieee2, June 16, 2013, 10:36:29 AM

Previous topic - Next topic

ieee2

Hi. I have Irvine book. I want to test some examples in the book. I downloaded the library and wrote this example. I write the code in MASM32 editor. I run my program using MASM32. My system is Windows 7 64-bit. My code file name is test.asm

Here is the code:


This program adds and subtracts 32-bit integers.

include "c:\masm32\include\Irvine32.inc"
includelib "c:\masm32\lib\irvine32.lib"
includelib "c:\masm32\lib\kernel32.lib"

.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs ; display registers
exit
main ENDP
END main


After trying to Assemble and Link it, I get the following error:

irvine32.lib <irvine32.obj> : error lnk2001: unresolved external symbol _MessageBoxA@16
test.exe fatal error : LNK1120: 1 unresolved externals


I correctly copied irvine .lib and .inc files in the masm32 include and lib folders.

Please, help me.

dedndave

what you are missing is kernel32.inc/lib
and, probably be nice to have windows.inc, as well

Kip is a good guy, and his book has merits - he just uses "non-standard" methods
however, it will be easier to learn assembler if you download and install the masm32 package
if your professor expects you to use Kip's library, then so be it
otherwise, it is better to become accustomed to standard ways of doing things

Antariy

Dave, you're almost right, but it's user32.lib :biggrin:

ieee2, after these lines in the source

include "c:\masm32\include\Irvine32.inc"
includelib "c:\masm32\lib\irvine32.lib"
includelib "c:\masm32\lib\kernel32.lib"


just add this line:

includelib "c:\masm32\lib\user32.lib"



ieee2

Thanks. The Assemble and Link worked fine after adding:
includelib c:\masm32\lib\user32.lib
But without quotations in all the include lines.

However, when I run, the console window appear and disappear so fast that I am not able to read anything. How can I fix this issue ? though I wrote the code exactly as the first example in Ch3 of the book.

MichaelW

One way would be to call WaitMsg before you exit.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

we usually fix that by use of the "inkey" macro (part of the masm32 package)
it waits for any key press before terminating

another way is to open the console window, then run the program by typing the name at the prompt
when you run a console-mode program this way, the console remains after termination

if none of that suits you, you can add your own "AnyKey" function

see the attached program

blobue

Hi All,

I have a similar problem when linking this example from the book.  I'm seeing the following errors when assembling:

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\masm32>ml AddSub.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: AddSub.asm
c:\masm32\lib\Irvine32.lib(1) : error A2008: syntax error : !
c:\masm32\lib\Irvine32.lib(2) : error A2044: invalid character in file
c:\masm32\lib\Irvine32.lib(3) : error A2044: invalid character in file
c:\masm32\lib\Irvine32.lib(3) : error A2039: line too long
c:\masm32\lib\Irvine32.lib(4) : error A2044: invalid character in file
c:\masm32\lib\Irvine32.lib(5) : error A2044: invalid character in file
c:\masm32\lib\Irvine32.lib(6) : error A2044: invalid character in file
c:\masm32\lib\Irvine32.lib(7) : error A2044: invalid character in file

until masm encounters 100 errors then quits.  Any ideas?  Corrupt library?

Thanks,
Brian

dedndave

that looks like you have used "include" with a "lib" file

for INC files (which are similar to ASM files), use INCLUDE
for LIB files (which are binary files), use INCLUDELIB

blobue

Thanks Dave that was the magic.  Can I ask where the 'inkey' macro is located?

Thanks

dedndave

not sure about Kip's library - or if he even has an "inkey" macro

there is one in the masm32 package - a different library   :P

most of the masm32 macros are in
\masm32\macros\macros.asm

EDIT:
Kip has a file named Macros.inc
as far as i can see, it does not have an inkey macro

you can use this function....
;***********************************************************************************************

AnyKey  PROC

;Wait for Any Console Key Press - DednDave
;version 1, 12-2011
;version 2, 2-2013
;
;  This function returns when any console key is pressed (bKeyDown = 1).
;A possible drawback is that all input event records are removed from
;the console input queue until a key is pressed. In many cases, this is
;not an issue. The virtual key code, virtual scan code, TCHAR character,
;and control key state values are returned in registers.

;Call With: Nothing
;
;  Returns: EAX = TCHAR character (high word of EAX = 0)
;           ECX = control key state flags
;               Bit   Name                Meaning
;                0    RIGHT_ALT_PRESSED   Right ALT key is pressed
;                1    LEFT_ALT_PRESSED    Left ALT key is pressed
;                2    RIGHT_CTRL_PRESSED  Right CTRL key is pressed
;                3    LEFT_CTRL_PRESSED   Left CTRL key is pressed
;                4    SHIFT_PRESSED       SHIFT key is pressed
;                5    NUMLOCK_ON          NUM LOCK light is on
;                6    SCROLLLOCK_ON       SCROLL LOCK light is on
;                7    CAPSLOCK_ON         CAPS LOCK light is on
;                8    ENHANCED_KEY        Key is enhanced
;           EDX:
;           low word (DX) = virtual key code
;               high word = virtual scan code
;
;           all other registers are preserved

;-------------------------------------------------

    LOCAL   ir          :INPUT_RECORD
    LOCAL   uRecCnt     :UINT
    LOCAL   hStdInp     :HANDLE

;-------------------------------------------------

    INVOKE  GetStdHandle,STD_INPUT_HANDLE
    mov     hStdInp,eax
    .repeat
        INVOKE  ReadConsoleInput,hStdInp,addr ir,1,addr uRecCnt
        movzx   ecx,word ptr ir.EventType
        mov     edx,dword ptr ir.KeyEvent.wVirtualKeyCode
    .until (ecx==KEY_EVENT) && (ecx==ir.KeyEvent.bKeyDown) && (dx!=VK_SHIFT) && (dx!=VK_CONTROL) && (dx!=VK_MENU)
    movzx   eax,word ptr ir.KeyEvent.UnicodeChar
    mov     ecx,ir.KeyEvent.dwControlKeyState
    ret

AnyKey  ENDP

;***********************************************************************************************

blobue

Thanks for the code snippet Dave.  I must be missing something because I can't seem to get any output from the program at all even with things like

AddSub > output or AddSub | more

and when I added your code I get these errors:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: C:\masm32\AddSub.asm
C:\masm32\AddSub.asm(57) : error A2006: undefined symbol : UINT
C:\masm32\AddSub.asm(57) : error A2195: parameter or local cannot have void typ

C:\masm32\AddSub.asm(68) : error A2006: undefined symbol : KeyEvent
C:\masm32\AddSub.asm(70) : error A2006: undefined symbol : KeyEvent

Looking at the book the UINT is called an SWORD and the KeyEvent structure seems to be defined somewhere else.  Sorry for all the beginner questions but I'm trying to get this working so I can turn in the class homework. 

Thanks

hutch--

I the short term you can equate UINT to a DWORD which is the correct MASM data size.

UINT equ <DWORD>

In the longer term you need to find where Kip defines his data types, probably in an include file.

MichaelW

There is no UINT type declaration in any of the Irvine32 files that I have, but there should be an INPUT_RECORD structure definition in smallwin.inc. It includes only the KeyEvent member but it should be workable.
Well Microsoft, here's another nice mess you've gotten us into.

blobue

Thanks for the suggestions.  I'll attach the code that finally built for me at the end.  Changing UINT to DWORD was fine.  The KeyEvent member of the INPUT_RECORD was called Event in smallwin.inc so I changed that.  The only remaining issue is that I still get no output.  I have a feeling this might be a Windows 8 issue.  I start the program from a command prompt and it seems to just return.  there is nothing to standard out.  If I open the task manager I see the process name running but have a feeling it just forked into the ether with no controlling terminal. 

This is frustrating for me as I'll likely have to drop the class since I won't be able to turn in the homework.  That being said all the help here has been great.  Here's my complete code so that maybe the next poor sucker might have a better result.

TITLE ADD and Subtract       (AddSub.asm)

; This program adds and subtracts 32-bit integers.

INCLUDE c:\masm32\include\Irvine32.inc
INCLUDELIB c:\masm32\lib\Irvine32.lib
INCLUDELIB c:\masm32\lib\kernel32.lib
INCLUDELIB c:\masm32\lib\user32.lib

.code
main PROC

mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
      call  AnyKey

      exit
main ENDP

;***********************************************************************************************

AnyKey  PROC

;Wait for Any Console Key Press - DednDave
;version 1, 12-2011
;version 2, 2-2013
;
;  This function returns when any console key is pressed (bKeyDown = 1).
;A possible drawback is that all input event records are removed from
;the console input queue until a key is pressed. In many cases, this is
;not an issue. The virtual key code, virtual scan code, TCHAR character,
;and control key state values are returned in registers.

;Call With: Nothing
;
;  Returns: EAX = TCHAR character (high word of EAX = 0)
;           ECX = control key state flags
;               Bit   Name                Meaning
;                0    RIGHT_ALT_PRESSED   Right ALT key is pressed
;                1    LEFT_ALT_PRESSED    Left ALT key is pressed
;                2    RIGHT_CTRL_PRESSED  Right CTRL key is pressed
;                3    LEFT_CTRL_PRESSED   Left CTRL key is pressed
;                4    SHIFT_PRESSED       SHIFT key is pressed
;                5    NUMLOCK_ON          NUM LOCK light is on
;                6    SCROLLLOCK_ON       SCROLL LOCK light is on
;                7    CAPSLOCK_ON         CAPS LOCK light is on
;                8    ENHANCED_KEY        Key is enhanced
;           EDX:
;           low word (DX) = virtual key code
;               high word = virtual scan code
;
;           all other registers are preserved

;-------------------------------------------------

    LOCAL   ir          :INPUT_RECORD
    LOCAL   uRecCnt     :DWORD
    LOCAL   hStdInp     :HANDLE

;-------------------------------------------------

    INVOKE  GetStdHandle,STD_INPUT_HANDLE
    mov     hStdInp,eax
    .repeat
        INVOKE  ReadConsoleInput,hStdInp,addr ir,1,addr uRecCnt
        movzx   ecx,word ptr ir.EventType
        mov     edx,dword ptr ir.Event.wVirtualKeyCode
    .until (ecx==KEY_EVENT) && (ecx==ir.Event.bKeyDown) && (dx!=VK_SHIFT) && (dx!=VK_CONTROL) && (dx!=VK_MENU)
    movzx   eax,word ptr ir.Event.UnicodeChar
    mov     ecx,ir.Event.dwControlKeyState
    ret

AnyKey  ENDP

;***********************************************************************************************

END main

MichaelW

It does not build for me. For an error ML indicates what the error is and where it is.

After changing the includes to match my installation there were two problems:

blobue.asm(60) : error A2006: undefined symbol : HANDLE
blobue.asm(60) : error A2195: parameter or local cannot have void type
blobue.asm(72) : error A2006: undefined symbol : UnicodeChar
>Exit code: 1


Since HANDLE is not defined, you need to replace it with DWORD.

UnicodeChar is being reported as undefined because the union has name:

KEY_EVENT_RECORD STRUCT
bKeyDown          DWORD ?
wRepeatCount      WORD  ?
wVirtualKeyCode   WORD  ?
wVirtualScanCode  WORD  ?
UNION uChar
  UnicodeChar     WORD  ?
  AsciiChar       BYTE  ?
ENDS
dwControlKeyState DWORD ?
KEY_EVENT_RECORD ENDS


You can fix this by including the union name in the reference.
Well Microsoft, here's another nice mess you've gotten us into.