home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / m / m248 / 4.ddi / LIBENTRY.AS_ / LIBENTRY.AS
Encoding:
Text File  |  1993-02-01  |  2.2 KB  |  73 lines

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