Search code examples
visual-studioassemblymasm

Include Files for MASM


So it would appear how to use MASM has changed about 50 times over the years because I found a huge number of answers and not one of them works.

What I'd like to know is how do you call something like exitprocess on MASM? What files do I include/where are they? I'm using the ml.exe built into VS2015 Community Edition. There is no MASM folder on either my root drive or with VS. VS does not come with any .inc files (I ran an exhaustive search on the drive). I just want to do something simple:

.386
.model flat, stdcall 
option casemap:none 
includelib ?????????????
include ?????????????
.data 
.code 
start: 
    invoke ExitProcess,0 
end start

I tried including just msvcrt.lib and this also does not work.


Solution

  • Hopefully someone has a better answer, but I fixed in by installing MASM from this site. It puts the masm32 folder in the root directory (C:\ for most of us)

    http://www.masm32.com/download.htm

    Edit: Also, the .inc files are just a bunch of function prototypes. So you could just prototype whatever function you want and then use includelib to call it.

    http://win32assembly.programminghorizon.com/tut2.html

    In our example above, we call a function exported by kernel32.dll, so we need to include the function prototypes from kernel32.dll. That file is kernel32.inc. If you open it with a text editor, you will see that it's full of function prototypes for kernel32.dll. If you don't include kernel32.inc, you can still call ExitProcess but only with simple call syntax. You won't be able to invoke the function. The point here is that: in order to invoke a function, you have to put its function prototype somewhere in the source code. In the above example, if you don't include kernel32.inc, you can define the function prototype for ExitProcess anywhere in the source code above the invoke command and it will work. The include files are there to save you the work of typing out the prototypes yourself so use them whenever you can.

    .386 
    .model flat, stdcall 
    option casemap:none 
    include C:\masm32\include\windows.inc 
    include C:\masm32\include\kernel32.inc 
    includelib C:\masm32\lib\kernel32.lib 
    .data 
    .code 
    start: 
        invoke ExitProcess,0 
    end start
    

    But I could just as easily remove the includes:

    .386 
    .model flat, stdcall 
    option casemap:none
    includelib C:\masm32\lib\kernel32.lib 
    .data 
    .code 
    start: 
        ExitProcess PROTO STDCALL :DWORD
        invoke ExitProcess,0 
    end start