The MASM Forum

General => The Campus => Topic started by: Pokerice on December 11, 2014, 02:04:58 AM

Title: include files
Post by: Pokerice on December 11, 2014, 02:04:58 AM
Hi guys, so i am a little confused on the include files. I thought they were only needed for their prototypes if you want to use invoke.
But whatever functions I am using from the libraries (like kernel32.lib or user32.lib) will give me the "undefined symbol error" whenever the include files are omitted.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc


;include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
.code
start:
call ExitProcess      ; I also tried ExitProcessW and ExitProcessA but still doesn't work
end start

Could someone explain this?
Title: Re: include files
Post by: jj2007 on December 11, 2014, 02:35:45 AM
Your code chokes in the assembly phase because ML/JWasm don't know the symbol.

ExitProcess PROTO :DWORD
push 0
call ExitProcess

There are no ANSI or UNICODE versions - no strings passed. And it works definitely better with kernel32.lib ;-)
Title: Re: include files
Post by: dedndave on December 11, 2014, 10:54:28 AM
include files may have all sorts of things in them
true enough, that Hutch has arranged them so that constants, structures, etc are all in windows.inc (and winextra.inc)
most of the others contain only prototypes

that's not always the case for other library packages
Title: Re: include files
Post by: Pokerice on December 11, 2014, 11:26:29 AM
So does that mean you must have a prototype for a function before you can use it because the tutorial I am following states that you don't have to include files if you don't plan to invoke. Also, how come if I declare my own using proc, I can call it without prototyping?
Title: Re: include files
Post by: dedndave on December 11, 2014, 11:37:18 AM
it doesn't need a prototype to be CALL'ed
it does need one to be INVOKE'd

even so, externals need to be defined, in some way
so - if not by PROTO, then by EXTERN or EXTERNDEF
externals meaning library or dll functions
this is one thing that is different for your own PROC's

better to use a PROTO and INVOKE if it has parameters
the assembler insures that you have the correct number and size of parameters

notice that for
    INVOKE  ExitProcess,0
the assembler actually generates
    push    0
    call    ExitProcess
Title: Re: include files
Post by: Pokerice on December 11, 2014, 12:21:26 PM
thank you all especially dedndave, I understand now :biggrin:
So it is kind of like the declarations needed in the header files in c++?
Title: Re: include files
Post by: dedndave on December 11, 2014, 12:42:48 PM
exactly   :t