News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Alternate include style

Started by stanhebben, December 04, 2006, 10:26:13 AM

Previous topic - Next topic

stanhebben

Currently, if you want to include windows headers & libraries, you write the following:

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc

includelib \masm32\include\kernel32.lib
includelib \masm32\include\user32.lib
includelib \masm32\include\gdi32.lib


Also, header files (at least the ones in masm) don't prevent double inclusion.

So, I'd like to propose the following way to use header files.

Including libraries:


include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\gdi32.inc


Header files: (ex. kernel32.inc)

ifndef KERNEL32_INC
KERNEL32_INC equ <KERNEL32_INC>

includelib kernel32.lib

... original file ...

endif


Also, the libraries should be in the LIB path, so you can access them immediately with their name (without path). This doesn't make a difference when writing in pure assembly, but if you start making static libraries which depend on other static libraries, there is a pitfall which I encounter regularly. Simply said, it's been more than once that the C++ compiler couldn't find \masm32\lib\kernel32.lib .

It's just an idea that came up in mind. Tell me if you like it or not.

hutch--

Stan,

You must have an old version of the includes, they have had a duplicate lock for some time now.


  ; ===========================================
  ; certidl.inc copyright MASM32 1998 - 2005
  ; ===========================================

IFNDEF CERTIDL_INC
CERTIDL_INC equ <1>

CertServerRequest PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
MIDL_user_allocate PROTO :DWORD
MIDL_user_free PROTO :DWORD

ELSE
echo -----------------------------------------
echo WARNING Duplicate include file certidl.inc
echo -----------------------------------------
ENDIF
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

stanhebben

Ah, I see.  :red

I should wipe those old masm versions off my hard disk.

What do you think of the includelib idea?

ToutEnMasm

Hello,
Something useful
                         ToutEnMasm

Quote
LIB user32,gdi32,kernel32,shell32,comctl32,comdlg32,masm32,ole32,oleaut32

Quote
  ; ---------------------------------------------------
  ; return an arguments specified in "num" from a macro
  ; argument list or "-1" if the number is out of range
  ; ---------------------------------------------------
    getarg MACRO num:REQ,args:VARARG
      LOCAL cnt, txt
      cnt = 0
      FOR arg, <args>
        cnt = cnt + 1
        IF cnt EQ num
          txt TEXTEQU <arg>     ;; set "txt" to content of arg num
          EXITM
        ENDIF
      ENDM
      IFNDEF txt
        txt TEXTEQU <-1>        ;; return -1 if num out of range
      ENDIF
      EXITM txt
    ENDM
   
  ; -----------------------------------------------
  ; count the number of arguments passed to a macro
  ; This is a slightly modified 1990 MASM 6.0 macro
  ; -----------------------------------------------
    argcount MACRO args:VARARG
      LOCAL cnt
      cnt = 0
      FOR item, <args>
        cnt = cnt + 1
      ENDM
      EXITM %cnt                ;; return as a number
    ENDM      


LIB  MACRO args:VARARG
   LOCAL acnt,buffer,var,boucle,buf1
   acnt = argcount(args)         ;macro argcount , nb d'arguments
   var = 1
   :boucle
   buffer equ getarg(var,args)      ;macro getarg

   buf1 CATSTR <include \masm32\include\>,buffer,<.inc>
   buf1

   buf1 CATSTR <includelib \masm32\lib\>,buffer,<.lib>
   buf1

   var = var + 1
   IF var LE acnt
   goto boucle
   ENDIF
ENDM



Vortex

ToutEnMasm,

That's a nice idea :U

Jimg

I like Stan's idea about putting the includelib INSIDE the include file. :U  Why ever hassle with having to worry about it.

7of9[Noir]

... and if you drive this idea to maximum, you got this ...


;windows.inc file in \masm32\include
....
IFNDEF _wininc_
_wininc_ equ <1>

... definitions as given inside this file ...

; --- at the end of windows.inc, insert this :
; --- coder: toutenmasm
; ---------------------------------------------------
  ; return an arguments specified in "num" from a macro
  ; argument list or "-1" if the number is out of range
  ; ---------------------------------------------------
    getarg MACRO num:REQ,args:VARARG
      LOCAL cnt, txt
      cnt = 0
      FOR arg, <args>
        cnt = cnt + 1
        IF cnt EQ num
          txt TEXTEQU <arg>     ;; set "txt" to content of arg num
          EXITM
        ENDIF
      ENDM
      IFNDEF txt
        txt TEXTEQU <-1>        ;; return -1 if num out of range
      ENDIF
      EXITM txt
    ENDM
   
  ; -----------------------------------------------
  ; count the number of arguments passed to a macro
  ; This is a slightly modified 1990 MASM 6.0 macro
  ; -----------------------------------------------
    argcount MACRO args:VARARG
      LOCAL cnt
      cnt = 0
      FOR item, <args>
        cnt = cnt + 1
      ENDM
      EXITM %cnt                ;; return as a number
    ENDM     


LIB  MACRO args:VARARG
   LOCAL acnt,buffer,var,boucle,buf1
   acnt = argcount(args)         ;macro argcount , nb d'arguments
   var = 1
   :boucle
   buffer equ getarg(var,args)      ;macro getarg

   buf1 CATSTR <include >,buffer,<.inc>      ; MODIFIED !!
   buf1

   buf1 CATSTR <includelib >,buffer,<.lib>   ; MODIFIED !!
   buf1

   var = var + 1
   IF var LE acnt
   goto boucle
   ENDIF
ENDM

; simple add the files you need ...
LIB user32,gdi32,kernel32,shell32,comctl32,comdlg32,masm32,ole32,oleaut32

ELSE
echo ------------------------------------------
echo WARNING Duplicate include file windows.inc
echo ------------------------------------------
ENDIF


Now it's enough to inlude "windows.inc" to your source, the rest is included by the patch ...

daydreamer

looks like a great idea
my alternate includes, excludes gdi lib and makes a smaller .exe

zooba

Quote from: daydreamer on December 07, 2006, 05:02:13 PM
excludes gdi lib and makes a smaller .exe

Doesn't make a difference if you don't use it. The linker just doesn't include it.

Compile times can be reduced if you leave out WINDOWS.INC, though the amount of functionality lost is considerable and generally not worth it.

Cheers,

Zooba :U

hutch--

Guys,

All of this stuff is viable if you can get it to work properly but what is not viable is breaking some massive number of already written programs that use the existing system of a matching include and library file. It may be an extra typing issue but its not a performance issue and the other factor is the association between an include file and a matching library that is lost with burying the two together.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

u

My alternate include style is:

include \masm32\ultrano\bank\base.inc
start:
print "hello world"
invoke ExitProcess,0
end start

Here all usually-used includes/libs and OOP objects and my custom libs and macros get included. This code compiles in less than 200ms - so I see no point in trying to avoid windows.inc .

Instead of modifying the standardized contents of the masm32 package (like windows.inc in this case), it's much better to make an include-file to contain your custom macros.
Please use a smaller graphic in your signature.

Vortex

Hi Hucth,

I cannot understand why a simple macro simplifying the typing breaks the assocation between the include file and the import library. Is there any reason?

ToutEnMasm

Hello,

Quote
I cannot understand why a simple macro simplifying the typing breaks the assocation between the include file and the import library. Is there any reason?

I agree with that.
If the macros are included in windows.inc ,old codes couldn't be damage with that because ...they don't use them.
                                   ToutEnMasm

PBrennick

ToutenMasm,
You did a nice job with those macros! They are a little long, but they appear to be dependable.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Jimg

Something similar-

uselibx macro args:VARARG
    for arg,<args>
        include  arg.inc
        includelib arg.lib
    endm
EndM

uselibx user32,kernel32,shell32,comctl32,comdlg32,gdi32