---------------------------------------------------------------------------
    -----------------------------------------------------------------------
            - A L W A Y S   U N D E R    C O N S T R U C T I O N -

           $$$$$$$$   $$$$$$$$  $$$$$$$$$$$$$   $$$$$$$$   $$$$$$$$
          $$$$$ $$$$ $$$$$ $$$$ $$$$$ $$$$ $$$ $$$$$ $$$$ $$$$$ $$$$
          $$$$$ $$$$ $$$$$      $$$$$ $$$$ $$$       $$$$       $$$$
          $$$$$$$$$$  $$$$$$$$  $$$$$ $$$$ $$$  $$$$$$$$   $$$$$$$$
          $$$$$ $$$$       $$$$ $$$$$ $$$$ $$$       $$$$ $$$$$
          $$$$$ $$$$ $$$$$ $$$$ $$$$$ $$$$ $$$ $$$$$ $$$$ $$$$$ $$$$
          $$$$$ $$$$  $$$$$$$$  $$$$$ $$$$ $$$  $$$$$$$$  $$$$$$$$$$

                    How to program for windows 95 in asm32
                          Lesson 0 : The Introduction
                   by _HaK_ and corrected by Nemrod and ReN
                          (Sorry : no asm this time)

    -----------------------------------------------------------------------
  ---------------------------------------------------------------------------


  1.Introduction :
  ----------------

      With  this  tutorials, I will try to  explain you how to produce an
      application  with windows, menus and  dialogs for Microsoft Windows
      95 and 98 in full ASM.

      I  decided  to do this, because  after I released my first freeware
      ICU,  which  is written in full  ASM,  some people on #WIN32ASM (on
      EFNET) asked me for a tutorial on GUI interface !

      I  write  application  for windows in  ASM  because ASM is the only
      language I already had practiced a bit. All informations given here
      are  only  for  those who understand a  bit  of  asm (at least they
      should know how one or two ASM instructions works).

      I can't be held responsable for any damage this text or his content
      could do !



  2.What you will need :
  ----------------------


      First thing will be an assembler. This tutorial is written for TASM
      5.0 from Borland (www.inprise.com).

      Other  assembler could be supported  with some modifications to the
      sources, but my purpose isn't to do this. So if you want to convert
      the  files,  do it, but send me  them  back once you have finish, I
      will include them in this Pack for the other.

      In  addition  you  will need some  ASM  knowledge  : understand all
      instructions (maybe not all but moreless the most used).

      In  complement  of  TASM, you will  need  a resource editor such as
      Borland  Resource Workshop or the MS  dialog editor included in the
      platformSDK  tool pack (download it at www.microsoft.com/msdn/sdk).
      This  will be needed in the future  for dialog box edition and menu
      implementation.

      To conclude you will need the famous "Win32 programmer's reference"
      Help file, bewhich explain all the Windows API.

      Most  of  the  tool  you will need  can  be  found on the following
      adresses:

          http://lastninja.home.ml.org/
          http://cracking.home.ml.org/
          http://www.aquanet.co.il/vip/fresh/tools.htm
          http://members.xoom.com/foxcore/tasm



  3.All the files types :
  ----------------------

    3.1.Short description:
    ----------------------

      .ASM     : the main file it contains the real source code !

      .INC     : (optional can be included in the .ASM) complement
                 of the .asm can be used to define datavalue, ...

      .RC      : the  resource file,  a new file type for windows !
                 this file  include all the  resource needed by the
                 application such as menu,dialog box, icon, bitmap,
                 et cetera, ...
                 Similar to a data file.

      .DEF     : help the linker for the linking : define the exe type,
                 exports, imports fonctions, ...

      makefile : used for compiling the whole application.


    3.2.The .RC files:
    ------------------

      This  files  include all the  resources  needed by the application.
      They are similar to a data file, because every resources have to be
      loaded within the application.

      They  must  be compiled too. For  those  who have TASM by BRC32.exe
      Once  compiled they become .RES which  are ready for LINKING. There
      will be a whole lesson on them in the future (lesson 4)


    3.3.The .DEF file:
    ------------------

      This file define the options for the linking.
      It is composed by :
      (this is an example and works perfectly for ICU)


      ;--- Start of ICU.DEF --->8

        NAME           ICU             ; define the name of the application
        DESCRIPTION    'ASM program'   ; give a short description
        EXETYPE        WINDOWS         ; define the EXETYPE : windows
        CODE           PRELOAD MOVEABLE ;type of the code segment
        DATA           PRELOAD MOVEABLE MULTIPLE  ; type of data segment

      ;8<- EOF ICU.DEF ---


      other parameters exist :

       * STUB           'Winstub.exe'

          It  gives  the famous dos  message when windows not running
          and if not included say that we need win32. Seems we can do
          our own message !

       * EXPORTS        WndProc

          It   defines  which  are  the   exported  fonction  by  the
          application.

       * IMPORTS        DLLPROG.SetWinAPI

          It   defines  which  are  the   imported  fonction  by  the
          application.  It  doesn't  be necessar  if  we link with an
          import library (here import32.lib see below)

       * HEAPSIZE       8192

          It  define the size of the heap : didn't understand what it
          is, but can be 0 for a DLL.

       * STACKSIZE      8192

          It define the size of the stack.

       * LIBRARY        DLLPROG

          It  define  that  the  prog is a  DLL  and  the name of the
          library.  If  you  decide to do  a  library  : DATA must be
          SINGLE  and  not  MULTIPLE It Seems  that  a library has no
          NAME.

       * DATA and CODE can have for parameters

           (not sure about signification)
           - PRELOAD        : autoloaded, loaded when the progs run ?
           - MOVEABLE       : can be moved within memory ?
           - FIXED          : cant be moved within memory ?
           - SINGLE         : Single segment ?
           - MULTIPLE       : Multiple segment ?
           - NONDISCARDABLE : ?

       *  It  seems  to be more  options  (after  a fast look into
          link32.exe) I'm  always searching info  on this, so if u
          have some : contact me !


    3.4.The makefile file:
    ----------------------

      This file is a sort of Batch used for the compilation ! example :


      ;--- Start of MakeFile --->8

        # TASM32.EXE, TLINK32.EXE, BRC32.EXE, MAKE.EXE
        # are from TASM v5.0. Make sure the path points to them.
        # Path only  needs  to  point to  \bin  subdirectory,
        # TLINK32 finds IMPORT32.LIB in the \lib subdirectory ok.

        # TLINK32 switches: /Tpa = build 32-bit EXE,
        #                   /aa  = target Windows 32-bit application,
        #                   /v   = include debug info.

        #TASM32 switches:   /Zi  = include debug info,
        #                   /m2 = 2 passes while compiling.

        # the last  parameter is the resource  file  to be bound to the
        # executable. the 2nd last param. is the definition file.

        # make -B          Will build .EXE
        # make -B -DDEBUG 	Will build the debug version.

        NAME = ICU
        OBJS = $(NAME).obj
        DEF  = $(NAME).def

        !if $d(DEBUG)
          TASMDEBUG=/zi
          LINKDEBUG=/v
        !else
          TASMDEBUG=
          LINKDEBUG=
        !endif

        !if $d(MAKEDIR)
          IMPORT=$(MAKEDIR)\..\lib\import32
        !else
          IMPORT=import32
        !endif

        $(NAME).EXE: $(OBJS) $(DEF)
          tlink32 /Tpe /aa /c $(LINKDEBUG) $(OBJS),$(NAME),, $(IMPORT), $(DEF), $(NAME)

        .asm.obj:
           tasm32 $(TASMDEBUG) /ml /m2 $&.asm
           brc32 -r $(NAME).rc

      ;8<- EOF MakeFile ---

      Replace  the NAME variable by the  name of the file of application.
      All the filename must be the same : here ICU.DEF, ICU.ASM, ICU.RC

      If  you  want  to build the exe  :  type  "make" (but the \tasm\bin
      directory      must      be      in      the      PATH     :     ex
      :PATH=c:\windows;d:\tasm\bin;...)

      While  linking you will need the import32.lib which is in the "lib"
      subdirectory of tasm. This file is used to link the apicalls in the
      .ASM file and the real api address in memory.



  4.How to use the Win32 programmer's reference :
  -----------------------------------------------

    As  said before, this HLP contain all the Windows API. The problems are
    that  on the one hand there is to  much API that we can't know them all
    and on the other hand we can't find the one we are searching for.

    To  find  the API we are searching for,  if it exists, we could use the
    search  engine  included  within the help, but  I  never get it to work
    (always crash befor finishing the indexation), so we have to go on with
    the INDEX and the SOMMAIRE.

    My method consist to search mainly with the index :

      - once   you  know what you want to  do,  find  the main idea : for
        exemple  if you want to trace a circle, what you want to do is to
        trace, draw or paint something (synonyms are usefull)

      - try  by  typing  the main idea  in  the  index to  find something
        similar.

        On my exemple with trace : found nothing
                      with draw  : found "drawing ****"
                      with paint : found "painting and drawing ****"

      - now let see what we found, and try to come to the nearest to what
        you  are searching : what we want  is drawing a circle so drawing
        something  (a  special  shape)  on the  screen  :  we try drawing
        rectangles

      - here  don't panic: it's  not  what  we are  searching for, but by
        reading a bit we found something : to draw a rectangle we can use
        the   api   "Rectangle",  we  click  on   it  so  we  obtain  the
        documentation of it.

      - hey what is that button at the top : "Group", let's click on it !

      - now  what  we see: a  list  of  fonction  who all draw a  special
        filled  shape  : there is a  fonction call "Ellipse" that's it we
        found it ! (the circle is a particular case of an ellipse)

    Here we have seen that we need some luck, intuition and some idea.

    Another  method  to  find  what  we  are  searching  for  is using some
    generalities :

      (Quite) All Things where you want to get something begin by Get......
      (Quite) All things where you want to set something begin by Set......

      And the rest is sometimes in relation with it does.

    For example to Get the coordinate of the mouse :
      - we want to get something so : Get.....
      - a mouse(real, hardware) is  always represented by a cursor(virtual,
        image of the mouse) : GetCursor
      - we want the coordinate, the position of the Cursor : GetCursorPos

    Another  way is the reverse engeering of apps which does what you want.
    For example to know how to access the registry disasm the "regedit.exe"
    and try to understand how does it work.

    The last method is the NET : try on #Win32asm there should be people to
    listen   to   you  !  or  try   with  a  news  searcher  like  dejanews
    (www.dejanews.com) or reference (www.reference.com)

    But at all: synonyms are the best way to find something !


    OK, now we have found the API we are searching, It's mainly represented
    under this form :

      'type0' APINAME (
              type    parameters,
              type    parameters,
              type    parameters,
              type    parameters
                     )

      The type0 define what's the returned value type (mainly in eax) is.
      The type define what's the paramter values type are.

      Sometimes  the  type of a paramter  consist  of a special structure
      (like  point  and rect), this say that  all  the structure is to be
      given too !

      All the type are DWORD:
        * any HANDLE (HWND,HDC,HMENU,HKEY,...)
        * any INT, BOOL, UINT, ...
        * any Long Pointer (LP*)

      My aim is not to define all the existing type If they aren't DWORD,
      they are defined as what they are !

      There is 3 main types of LP :
        * LPvoid points on a procedure
        * LPctstr points on a null terminated string
        * LP*STRUCT points to a structure

      The parameters are often defined with names and not value : to find
      the value corresponding to the names (TASM doesn't recognize them),
      see  in  the \TASM\INCLUDE directory,  in the WINDOWS.INC but  they
      aren't  all  here ! The best way to  find  them is to search in the
      PlatformSDK from Microsoft in all the include files (.h)



  5.Conclusion
  ------------

    After  all this reading you thing that's was inutile. But I don't think
    so:  I  prefere  to define everything once,  and  then to answer to the
    question by updating this text. Every thing that is sayed here never be
    sayed  again in any of my others lessons. This lessons is a sort of big
    introduction  defining needed tools, how to use the "Win32 programmer's
    reference" HELP and a short description of the uncommon file.


  6.Here there are : ThE CrEdItZ :
  --------------------------------

    Thanx to _masta_ for the tutorials :
             It made me begun to program for Win95 in ASM
          to Nemrod for his correction :
             the punishement just begun ! ( ]:-) <- it's the devil)
          to my beta tester (and friend) ReN

  7.Where to find me :
  --------------------

    On #Win32ASM (on EFNET) : _HaK_ mainly on Sundays !

    And wait for the next lesson : a stupid hello world message box !