home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / TASMEXMP.ZIP / DLLPROG.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  4.0 KB  |  130 lines

  1. ; Turbo Assembler    Copyright (c) 1988, 1991 By Borland International, Inc.
  2.  
  3. ; DLLPROG.ASM - Template for writing .DLL files.
  4.  
  5. ; From the Turbo Assembler Users Guide
  6.  
  7. P286               ;286 processor; the minimum if we're writing
  8.                    ; for protected mode
  9. WARN PRO           ;enable protected mode warning
  10. MODEL SMALL        ;this example is SMALL model; others are possible
  11. INCLUDELIB SDLLCEW ;standard library for SMALL model DLL's
  12.                    ; must match model
  13.  
  14. ;Include libraries
  15. INCLUDELIB LIBW          ;Windows library
  16. EXTRN C _ACRTUSED:ABS    ;Force library to be included in link
  17.  
  18. ;Include files
  19. INCLUDE WINDOWS.INC      ;WINDOWS.INC contains assembly language
  20.                          ; definitions for Windows data types, etc.
  21.  
  22. DATASEG
  23.    ;<<Initialized data goes here>>
  24.  
  25. UDATASEG
  26.    ;<<Uninitialized data goes here>>
  27.  
  28. CODESEG
  29. ;----------------------------------------------------------------------
  30. ;Dynamic link library initialization procedure.
  31. ;LibMain is called to initialize the DLL library routines in module.
  32. ;This routine should return a 1 in AX if the library is
  33. ;successfully initialized, 0 otherwise.
  34. ;----------------------------------------------------------------------
  35. LibMain PROC PASCAL FAR
  36. PUBLIC  PASCAL LibMain
  37. ARG     @@hInstance:WORD,   \Descriptor for instance of application
  38.    @@wDataSeg:WORD,         \Library's data segment
  39.    @@wHeapSize:WORD,        \Heap size
  40.    @@lpszCmdLine:DWORD      ;pointer to command line
  41. USES ES,SI,DI
  42.    ;<<User code that initializes library goes here>>
  43.    MOV AX,1                 ;signals successful initialization
  44.    RET
  45. LibMain ENDP
  46.  
  47. ;----------------------------------------------------------------------
  48. ;Dynamic link library de-initialization procedure.
  49. ;This routine is optional.
  50. ;The example here does nothing; it is included as a guide.
  51. ;Returns AX=1 if deinitialization was successful
  52. ;----------------------------------------------------------------------
  53. WEP PROC  WINDOWS PASCAL FAR
  54. PUBLICDLL PASCAL WEP
  55. ARG       @@nParameter      ;parameter; specifies situation in which
  56.                             ; WEP is called
  57. USES ES,SI,DI
  58.    ;<<De-initialization code goes here>>
  59.    MOV AX,1                 ;signals successful de-initialization
  60.    RET
  61. WEP ENDP
  62.  
  63. ;----------------------------------------------------------------------
  64. ;Dynamic Link Library Routines.
  65. ;All user-defined library routines must be declared as PASCAL FAR
  66. ;procedures, and must be published using the PUBLICDLL directive.
  67. ;The arguments passed to and returned from DLL procedures are
  68. ;determined entirely by the programmer.
  69. ;----------------------------------------------------------------------
  70. ;[SetHello]
  71. ;Copy string 'Hello, Windows!' into a buffer.
  72. ;Pass address of buffer.
  73. ;Return length of string in AX.
  74. SetHello  PROC WINDOWS PASCAL FAR
  75. PUBLICDLL PASCAL SetHello
  76. ARG       @@lpszParam:DWORD         ;storage for string
  77. USES ES,SI,DI
  78.    ;<<User code goes here - here's an example:>>
  79.  
  80. DATASEG
  81. @@Hello   DB 'Hello, Windows!',0
  82. @@HSize = $-@@Hello
  83.    CODESEG
  84.    MOV SI,OFFSET @@Hello
  85.    LES DI,@@lpszParam
  86.    MOV CX,@@Hsize
  87.    CLD
  88.    REP MOVSB
  89.    MOV AX,@@Hsize-1
  90.    RET
  91. SetHello ENDP
  92. END
  93. P8086          ;select the processor
  94. MODEL TINY     ;always must be TINY model
  95.  
  96. DATASEG
  97.    ;<<Any initialized data is defined here>>
  98.  
  99. UDATASEG
  100.    ;<<Any uninitialized data is defined here>>
  101.  
  102.    ;<<Set up room for user stack, if default stack is not desired>>
  103.    DW 100H DUP (?)
  104. MyStack  LABEL WORD
  105.  
  106. CODESEG        ;this marks the start of executable code
  107.    STARTUPCODE
  108.    ;COM has all available memory allocated to it
  109.  
  110.    ;Stack is already set up to top of 64K segment
  111.    ;We can move it if we want using the following instruction:
  112.    MOV SP,OFFSET MyStack
  113.  
  114.    ;Now execute user code
  115.    ;The code can be placed here, but it looks better to call it.
  116.    ;DoIt returns the exit code in AL.
  117.    CALL DoIt
  118.  
  119.    ;Exit to DOS when complete
  120.    MOV AH,4CH
  121.    INT 21H
  122.    RET
  123.  
  124. DoIt PROC NEAR
  125.    ;<<Your code goes here>>
  126.    MOV AL,1
  127.    RET
  128. DoIt ENDP
  129. END
  130.