home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d009_2 / 1.ddi / SAMPLES / TRAPS / LIBENTRY.AS$ / LIBENTRY.bin
Encoding:
Text File  |  1992-02-03  |  2.1 KB  |  75 lines

  1.     PAGE    ,132
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;
  4. ;       LIBENTRY.ASM
  5. ;
  6. ;       Windows dynamic link library entry routine
  7. ;
  8. ;   This module generates a code segment called INIT_TEXT.
  9. ;   It initialises the local heap if one exists and then calls
  10. ;   the C routine LibMain() which should have the form:
  11. ;   BOOL FAR PASCAL LibMain(HANDLE hModule,
  12. ;                           WORD   wDataSeg,
  13. ;                           WORD   cbHeap,
  14. ;                           LPSTR  lpszCmdLine);
  15. ;        
  16. ;   The result of the call to LibMain is returned to Windows.
  17. ;   The C routine should return TRUE if it completes initialisation
  18. ;   successfully, FALSE if some error occurs.
  19. ;
  20. ;   Copyright (c) 1990-1992 Microsoft Corp.
  21. ;
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23.  
  24.         extrn LibMain:far           ; the C routine to be called
  25.     extrn LocalInit:far        ; Windows heap init routine
  26.         extrn __acrtused:abs
  27.         public LibEntry             ; entry point for the DLL
  28.  
  29. INIT_TEXT segment byte public 'CODE'
  30.         assume cs:INIT_TEXT
  31.  
  32. LibEntry proc far
  33.         
  34.     push    di         ; handle of the module instance
  35.         push    ds               ; library data segment
  36.     push    cx         ; heap size
  37.     push    es         ; command line segment
  38.     push    si         ; command line offset
  39.  
  40.     ; if we have some heap then initialise it
  41.     jcxz    callc         ; jump if no heap specified
  42.  
  43.     ; call the Windows function LocalInit() to set up the heap
  44.     ; LocalInit((LPSTR)start, WORD cbHeap);
  45.  
  46.     push    ds         ; Heap segment
  47.         xor     ax,ax
  48.     push    ax         ; Heap start offset in segment
  49.     push    cx         ; Heap end offset in segment
  50.     call    LocalInit     ; try to initialise it
  51.     or    ax,ax         ; did it do it ok ?
  52.         jz      CleanUp          ; quit if it failed
  53.  
  54.     ; invoke the C routine to do any special initialisation
  55.  
  56. callc:
  57.     call    LibMain         ; invoke the 'C' routine (result in AX)
  58.         jmp     short exit
  59.  
  60. CleanUp:
  61.         pop     si
  62.         pop     es
  63.         pop     cx
  64.         pop     ds
  65.         pop     di
  66. exit:
  67.  
  68.     ret             ; return the result
  69.  
  70. LibEntry endp
  71.  
  72. INIT_TEXT       ends
  73.  
  74.         end LibEntry
  75.