home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / msysjour / vol05 / 06 / worddll / libentry.asm < prev    next >
Assembly Source File  |  1990-11-01  |  2KB  |  73 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 initializes 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 hInstance,
  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 initialization
  18. ;   successfully, FALSE if some error occurs.
  19. ;
  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.