; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: Win32 import macros.
;
;  Target OS: Win32
;
;  Dependencies:
;
;  Notes: Only import_proto should be used in portable applications. Here we have some
;         old macros that needs revision or even removing.
;_________________________________________________________________________________________

; macroinstruction for making import section
macro library [name,string] {
forward
    local _label
    if name#.needed
    dd 0,0,0,RVA _label,RVA name
    end if
common
    dd 0,0,0,0,0
forward
    if name#.needed
    _label db string,0
    end if
 }


macro import name, [lbl, string]
 { common
    name:
   forward
    if used lbl
     local _label
     lbl dd RVA _label
    end if
   common
    if $ > name
     name#.needed = TRUE
     dd 0
    else
     name#.needed = FALSE
    end if
   forward
    if used lbl
    _label dw 0
           db string,0
    end if
  }



macro define_import_arguments [argument] {
common
  virtual at ebp+8
forward
  if ~ argument eq ...
    argument dd ?
  else
    label .more… dword
  end if
common
  end virtual
}



macro import_proto name, [lbl, arg, string] {
common
    name:
forward
    local ..lbl, ..used

    @label equ lbl

    ..used = 0
    if used lbl
      lbl dd RVA ..lbl
      ..used = 1
    else
      label lbl dword at 0
    end if

    if ~(arg eq NONE)
      if arg eq VOID
        .__info.argtype = 1
      else
        define_import_arguments arg
        .__info.argtype = 2
      end if
    else
     .__info.argtype = 0
    end if

common
    if $ > name
     name#.needed = TRUE
     dd 0
    else
     name#.needed = FALSE
    end if

forward
    if ..used
    ..lbl dw 0
          db string,0
    end if
}




