home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / INSTVER / DLLENTRY.AS_ / DLLENTRY.AS
Encoding:
Text File  |  1993-02-08  |  2.3 KB  |  75 lines

  1. PAGE,132
  2. ;***************************************************************************
  3. ;*
  4. ;*   DLLENTRY.ASM
  5. ;*
  6. ;*    DLL Entry code
  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.     INCLUDE CMACROS.INC
  23.  
  24. externFP <LIBMAIN>               ;The C routine to be called
  25.  
  26. createSeg INIT_TEXT, INIT_TEXT, BYTE, PUBLIC, CODE
  27. sBegin    INIT_TEXT
  28. assumes CS,INIT_TEXT
  29.  
  30. ?PLM=0                           ;'C'naming
  31. externA  <_acrtused>             ;Ensures that Win DLL startup code is linked
  32.  
  33. ?PLM=1                           ;'PASCAL' naming
  34. externFP <LOCALINIT>             ;Windows heap init routine
  35.  
  36. cProc   LibEntry, <PUBLIC,FAR>   ;Entry point into DLL
  37.  
  38. cBegin
  39.         push    di               ;Handle of the module instance
  40.         push    ds               ;Library data segment
  41.         push    cx               ;Heap size
  42.         push    es               ;Command line segment
  43.         push    si               ;Command line offset
  44.  
  45.         ;** If we have some heap then initialize it
  46.         jcxz    callc            ;Jump if no heap specified
  47.  
  48.         ;** Call the Windows function LocalInit() to set up the heap
  49.         ;**    LocalInit((LPSTR)start, WORD cbHeap);
  50.         
  51.         xor     ax,ax
  52.         cCall   LOCALINIT <ds, ax, cx>
  53.         or      ax,ax            ;Did it do it ok ?
  54.         jz      error            ;Quit if it failed
  55.  
  56.         ;** Invoke the C routine to do any special initialization
  57.  
  58. callc:
  59.         call    LIBMAIN          ;Invoke the 'C' routine (result in AX)
  60.         jmp short exit           ;LibMain is responsible for stack clean up
  61.  
  62. error:
  63.     pop    si         ;Clean up stack on a LocalInit error
  64.         pop     es               
  65.         pop     cx               
  66.         pop     ds
  67.         pop     di
  68. exit:
  69.  
  70. cEnd
  71.  
  72. sEnd INIT_TEXT
  73.  
  74.     END LibEntry
  75.