extdll.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ;################################################################
  2. ; ExtDLL header for MASM32
  3. ;
  4. ; Author: Ramon
  5. ;
  6. ; Obs: This header must be included after windows.inc and kernel32.inc
  7. ; because it need the prototypes for lstrcpy, lstrcpyn,
  8. ; GlobalAlloc and GlobalFree
  9. ;
  10. ;################################################################
  11. stack_t struct
  12. next dd ?
  13. text dd ? ; 1 DUP(?) ; this should be the length of string_size
  14. stack_t ends
  15. .const
  16. ; For page showing plug-ins
  17. WM_NOTIFY_OUTER_NEXT equ (WM_USER+0x8)
  18. WM_NOTIFY_CUSTOM_READY equ (WM_USER+0xd)
  19. NOTIFY_BYE_BYE equ 'x'
  20. INST_0 EQU 0 ; $0
  21. INST_1 EQU 1 ; $1
  22. INST_2 EQU 2 ; $2
  23. INST_3 EQU 3 ; $3
  24. INST_4 EQU 4 ; $4
  25. INST_5 EQU 5 ; $5
  26. INST_6 EQU 6 ; $6
  27. INST_7 EQU 7 ; $7
  28. INST_8 EQU 8 ; $8
  29. INST_9 EQU 9 ; $9
  30. INST_R0 EQU 10 ; $R0
  31. INST_R1 EQU 11 ; $R1
  32. INST_R2 EQU 12 ; $R2
  33. INST_R3 EQU 13 ; $R3
  34. INST_R4 EQU 14 ; $R4
  35. INST_R5 EQU 15 ; $R5
  36. INST_R6 EQU 16 ; $R6
  37. INST_R7 EQU 17 ; $R7
  38. INST_R8 EQU 18 ; $R8
  39. INST_R9 EQU 19 ; $R9
  40. INST_CMDLINE EQU 20 ; $CMDLINE
  41. INST_INSTDIR EQU 21 ; $INSTDIR
  42. INST_OUTDIR EQU 22 ; $OUTDIR
  43. INST_EXEDIR EQU 23 ; $EXEDIR
  44. INST_LANG EQU 24 ; $LANGUAGE
  45. __INST_LAST EQU 25
  46. .data?
  47. g_stringsize dd ?
  48. g_stacktop dd ?
  49. g_variables dd ?
  50. m2m MACRO M1, M2
  51. push M2
  52. pop M1
  53. ENDM
  54. EXDLL_INIT MACRO
  55. m2m g_stringsize, string_size
  56. m2m g_stacktop, stacktop
  57. m2m g_variables, variables
  58. ENDM
  59. .code
  60. ; utility functions (not required but often useful)
  61. popstring proc uses edi pStr:DWORD
  62. LOCAL th:DWORD
  63. mov edi, g_stacktop
  64. cmp edi, 0
  65. jz STACK_ERR
  66. mov edi, [edi]
  67. cmp edi, 0
  68. jz STACK_ERR
  69. ASSUME edi:PTR stack_t
  70. invoke lstrcpy, pStr, ADDR [edi].text
  71. mov th , edi
  72. mov edi, [edi].next
  73. mov eax, g_stacktop
  74. mov [eax], edi
  75. invoke GlobalFree, th
  76. ASSUME edi:PTR NOTHING
  77. mov eax, 0
  78. ret
  79. STACK_ERR:
  80. mov eax, 1
  81. ret
  82. popstring endp
  83. pushstring proc uses edi pStr:DWORD
  84. cmp g_stacktop, 0
  85. jz STACK_ERR
  86. mov eax, sizeof stack_t
  87. add eax, g_stringsize
  88. invoke GlobalAlloc, GPTR, eax
  89. mov edi, eax
  90. assume edi:PTR stack_t
  91. invoke lstrcpyn, ADDR [edi].text, pStr, g_stringsize
  92. mov eax, g_stacktop
  93. push DWORD PTR[eax]
  94. mov [eax], edi
  95. pop eax
  96. ;lea edi, [edi].next ; Not needed [edi].next == edi
  97. mov DWORD PTR[edi], eax
  98. ASSUME edi:PTR NOTHING
  99. STACK_ERR:
  100. ret
  101. pushstring endp
  102. getuservariable proc varnum:DWORD
  103. .if varnum < 0 || varnum >= __INST_LAST
  104. xor eax, eax
  105. .else
  106. mov eax, varnum
  107. imul eax, g_stringsize
  108. add eax, g_variables
  109. .endif
  110. ret
  111. getuservariable endp
  112. setuservariable proc varnum:DWORD, var:DWORD
  113. .if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
  114. mov eax, varnum
  115. imul eax, g_stringsize
  116. add eax, g_variables
  117. invoke lstrcpy, eax, var
  118. .endif
  119. ret
  120. setuservariable endp