²Ä 20 ³¹¡@°ÊºA³sµ²µ{¦¡®w ( Dynamic-Link Library )


°ÊºA³sµ²µ{¦¡®w²¤¶

¦b DOS §@·~¨t²Îùتº²Õ¦X»y¨¥±Ð¾Ç¤¤¡A¤p¤ì°¸´¿¦b²Ä¤Q³¹¤¶²Ð¤F»s§@µ{¦¡®w ( ©Î½¦¨¨ç¦¡®w¡A­^¤å¬O library ) ªº¤èªk¡A³oºØµ{¦¡®w¬O¦b³sµ²¹Lµ{¤¤¡A¥Ñ³sµ²¾¹¦bµ{¦¡®wùØ´M§ä­n©I¥sªº°Æµ{¦¡¡A±µµÛ§â³o­Ó°Æµ{¦¡¾ã¬q¦a´O¤J¥Dµ{¦¡¦Ó²£¥Í¥i°õ¦æÀÉ¡C¹³³oºØª½±µ§â°Æµ{¦¡ªºµ{¦¡½X¼g¤J¨ì¥i°õ¦æÀɤ¤ªº³sµ²¤è¦¡ºÙ¬°ÀRºA³sµ²¡A¦Ó³Q³sµ²ªºµ{¦¡®wºÙ¬°ÀRºAµ{¦¡®w¡C·íÀRºA³sµ²µ{¦¡®w³Q´¡¤J¥Dµ{¦¡«á¡A§Y¨ÏÀRºA³sµ²µ{¦¡®w³Q§R±¼¡A¥Dµ{¦¡¤´¯à¥¿±`°õ¦æ¡C

ÀRºA³sµ²ªº¯ÊÂI¤j¬ù¦³¨â­Ó¡G²Ä¤@­Ó¬OÀRºA³sµ²·|¦û¾Ú¤ñ¸û¦hªºµwºÐªÅ¶¡©Î°O¾ÐÅé¡A°²¦p¦³ 100 ­Óµ{¦¡­n©I¥s¬Y¤@¬q°Æµ{¦¡¡A¨º»ò´N¦³ 100 ­Ó¬Û¦Pªº°Æµ{¦¡·|³Q¼g¤J¤£¦Pªºµ{¦¡¤¤¡A¥ç§Y¦bµwºÐ¾÷ùØ´N­«½Æ¤F³o 100 ­Ó°Æµ{¦¡¡C²Ä¤G­Ó¯ÊÂI¬OºûÅ@¤Wªº¤£«K¡A¦pªGµo²{¬Y¬q°Æµ{¦¡ªºµ{¦¡½X¿ù»~©ÎªÌ­n§ó·sª©¥»¡A¨º»ò¥u¯à§â©Ò¦³©I¥s³o¬q°Æµ{¦¡ªº¥Dµ{¦¡­«·s²ÕĶ¡B³sµ²¤~¯à­×¥¿¿ù»~¡A°²¦p¦³¤@­Óµ{¦¡¿òº|¤F¡A¨º»ò³o­Ó¿òº|ªº¥Dµ{¦¡ÁÙ¬O·|¨Ï¥Îª©©Î¿ù»~ªº°Æµ{¦¡¡C

¨º»ò¡AWindows §@·~¨t²Î¦³¨S¦³¤èªk§ï¶i³o¨â­Ó¯ÊÂI©O¡Hµª®×·íµM¬OªÖ©wªº¡A§_«h´N¤£·|¦³³o¤@³¹¤F¡CWindows ±Ä¥Î°ÊºA³sµ²ªº¤è¦¡©I¥s°Æµ{¦¡¡A¦Ó§â³o¨Ç°Æµ{¦¡¶°¦X°_¨Ó©Ò¦¨ªºµ{¦¡®w´N¥s°µ°ÊºA³sµ²µ{¦¡®w ( dynamic-link library¡AÁY¼g¬° DLL )¡A°ÊºA³sµ²µ{¦¡®wªº°ÆÀɦW³q±`¬O DLL¡A¦ý¬O¤]¦³¥H EXE¡BOCX µ¥¬°°ÆÀɦWªº°ÊºA³sµ²µ{¦¡®w¡C¥H³oºØ¤è¦¡©Ò²£¥Íªº¥Dµ{¦¡¦b³sµ²¶¥¬q¡A¨Ã¤£·|´O¤J°Æµ{¦¡ªºµ{¦¡½X¡A¦Ó¶È¶È§â°Æµ{¦¡©Ò¦bªºµ{¦¡®w ( °ÆÀɦW¬° DLL ) ¤Î°Æµ{¦¡¬ÛÃö°T®§ ( ¦p°Æµ{¦¡¦WºÙµ¥µ¥ ) ´¡¤Jµ{¦¡ùØ¡A¦Ó³o¨Ç³Q´¡¤J¸ê®Æ¬O¥Ñ°ÆÀɦW¬° LIB ªº¶×¤Jµ{¦¡®w´£¨Ñ¡C

¨Æ¹ê¤W¡AWindows §@·~¨t²Î´N¬O¥Ñ³\¦hªº°ÊºA³sµ²µ{¦¡®w©Ò²Õ¦¨ªº¡A¨Ò¦p³Ì¥D­nªº¤T­Ó°ÊºA³sµ²µ{¦¡®w¡G
¡@¡@1.USER32.DLL ¤¤ªº°Æµ{¦¡¡A¥D­n¬O±±¨î¨Ï¥ÎªÌ¬É­±
¡@¡@2.GDI32.DLL ¤¤ªº°Æµ{¦¡¡A¥D­n­t³d¹Ï§ÎªºÅã¥Ü¡B¾Þ§@
¡@¡@3.KERNEL32.DLL ¤¤ªº°Æµ{¦¡¡A¥D­n³B²z°O¾ÐÅéºÞ²z©M¤u§@½Õ«×

·í¥Dµ{¦¡³Q°õ¦æ®É¡A§@·~¨t²Î¤~·|§â©Ò»Ý­n¥Î¨ì°ÊºA³sµ²µ{¦¡®w¸ü¤J¦Ü°O¾ÐÅé¡A¦pªG³o­Ó°ÊºA³sµ²µ{¦¡®w¤w¸g¸ü¤J°O¾ÐÅé¤F¡A§@·~¨t²Î±N·|§â³o­Ó°Æµ{¦¡ªºµ{¦¡½X¬M®g¨ì¥Dµ{¦¡©Ò¦b°O¾ÐÅéªÅ¶¡¡A©Ò¥H¦b¹êÅé°O¾ÐÅ餤ÁÙ¬O¶È«O¦s¤@¥÷µ{¦¡½X¡C¦]¬°°ÊºA³sµ²µ{¦¡®wªºµ{¦¡½X¦ì§}¬O¬M®g¦Ü¥Dµ{¦¡ªº¦ì§}ªÅ¶¡¡A©Ò¥HºÙ¬°¡y°ÊºA¡z¡C°²¦p¨t²Î§ä¤£µÛ°ÊºA³sµ²µ{¦¡®w¡A¨º»òµ{¦¡´NµLªk°õ¦æ¡C

°ÊºA³sµ²µ{¦¡®wªº­ì©lÀÉ

°ÊºA³sµ²µ{¦¡®w¥i¥H¬Ý¦¨¬O¤@¨Ç°Æµ{¦¡ªº¶°¦X ( ¤£¹L¤]¦³¨Ò¥~¡A¤]¦³¨Ç¬O¬Y¨Ç¸ê·½ªº¶°¦X )¡A¤@¯ë¦Ó¨¥¡A³o¨Ç°Æµ{¦¡¬O³Q¨ä¥Lµ{¦¡©Ò©I¥s¡A©Ò¥H¤£»Ý­n«Ø¥ßµøµ¡¡A¤]¤£»Ý­n°T®§°j°é©Î²×µ²µøµ¡ªºµ{¦¡½X¡C¨C­Ó°ÊºA³sµ²µ{¦¡®w³£·|¦³¤@­ÓºÙ¬°¡y¶i¤J¡þÂ÷¶}°Æµ{¦¡¡zªº°Æµ{¦¡¡A¥¦ªº¦WºÙ¥i¥H¥ô·N­q©w¡A¥u­n²Å¦X©R¦W³W«h§Y¥i¡C¡y¶i¤J¡þÂ÷¶}°Æµ{¦¡¡z¨Ã¤£¹³°ÊºA³sµ²®wùتº¨ä¥L°Æµ{¦¡¤@¼Ëµ¹¨ä¥Lµ{¦¡©I¥s¡A¦Ó¬O§@·~¨t²Î¸ü¤J©Î¨ø¸ü°ÊºA³sµ²µ{¦¡®w®É¡A¥Ñ§@·~¨t²Î©I¥s¡AÅý§@·~¨t²Î¦³¾÷·|°µ¤@¨Ç¨Æ«e³B²z©Î¬OÂ÷¶}®É§@¤@¨Ç²M°£°Ê§@¥Îªº¡C¡y¶i¤J¡þÂ÷¶}°Æµ{¦¡¡z¦³©T©wªº®æ¦¡¡A°²¦p¤£»Ý­n°µ³o¨Ç°Ê§@ªº¸Ü¡A¡y¶i¤J¡þÂ÷¶}°Æµ{¦¡¡z¤]¥i¥H¥u¬O§â TRUE ¦s¤J EAX ùØ¡AµM«á§â TRUE ·í¦¨ªð¦^­È´N¸õÂ÷¡C¾ã­Ó°ÊºA³sµ²µ{¦¡®wªº¼Ë¤l¹³©³¤U³o¼Ë¡G

         .386
         .MODEL FLAT,STDCALL
         OPTION CASEMAP:NONE

;°²¦p»Ý­n¥Î¨ì¥]§tÀÉ¡A¨º»ò¥i¥H¦b¦¹³B©w¸q
INCLUDE          WINDOWS.INC
INCLUDE          USER32.INC
INCLUDE          KERNEL32.INC
INCLUDELIB       USER32.LIB
INCLUDELIB       KERNEL32.LIB

;*********************************************************************
         .DATA?
;¦¹³B©w¸q¥¼ªì©l¤ÆªºÅܼÆ
;*********************************************************************
         .CODE
;---------------------------------------------------------------------
;¶i¤J¡þÂ÷¶}°Æµ{¦¡ªº¶i¤JÂI
DLLEntry        PROC    hInstance,dwReason,dwReserved
                mov     eax,dwReason
.IF eax==DLL_PROCESS_ATTACH
        ;«O¦shInstance
        ;ªì©l¤Æ°ÊºA³sµ²µ{¦¡®w»Ý­nªº¦UºØ¸ê·½
   .IF  ;ªì©l¤Æ¦¨¥\
                mov     eax,TRUE
   .ELSE
                mov     eax,FALSE
   .ENDIF
.ELSEIF eax==DLL_THREAD_ATTACH
        ;ÄÀ©ñ°ÊºA³sµ²µ{¦¡®w¨Ï¥Îªº¸ê·½
.ELSEIF eax==DLL_THREAD_DETACH
        ;¬°·sªº°õ¦æºü¤À°t¸ê·½
.ELSEIF eax==DLL_PROCESS_DETACH
        ;¬°°õ¦æºüÄÀ©ñ¸ê·½
.ENDIF

DLLEntry        ENDP
;¶i¤J¡þÂ÷¶}°Æµ{¦¡µ²§ô
;---------------------------------------------------------------------
SubRoutine1     PROC    Param1,Param2   ;¦¹³B¬°²Ä¤@­Ó°Æµ{¦¡ªº°Ñ¼Æ
                        ;¦¹³B¬°²Ä¤@­Ó°Æµ{¦¡ªºµ{¦¡½X
                ret
SubRoutine1     ENDP
;---------------------------------------------------------------------
SubRoutine2     PROC    ParamA,ParamB   ;¦¹³B¬°²Ä¤G­Ó°Æµ{¦¡ªº°Ñ¼Æ
                        ;¦¹³B¬°²Ä¤G­Ó°Æµ{¦¡ªºµ{¦¡½X
                ret
SubRoutine2     ENDP
;---------------------------------------------------------------------
SubRoutine3     PROC    ParamX,ParamY   ;¦¹³B¬°²Ä¤T­Ó°Æµ{¦¡ªº°Ñ¼Æ
                        ;¦¹³B¬°²Ä¤T­Ó°Æµ{¦¡ªºµ{¦¡½X
                ret
SubRoutine3     ENDP
;*********************************************************************
         END    DLLEntry

¤W­±ªº³o­Ó¨Ò¤l¡A¡y¶i¤J¡þÂ÷¶}°Æµ{¦¡¡z¦W¦r¬O¡yDLLEntry¡z¡A¹ï©ó­n°µ¨Æ«e³B²z©Î²M²z°Ê§@ªº°ÊºA³sµ²µ{¦¡®w¡A¤À§O¥Ñ¤£¦Pªº±ø¥ó°µ³B²z¡A´N¬O¹³¤W­±ªº¡yDLLEntry¡z°Æµ{¦¡©Òªí¥Üªº¡C§@·~¨t²Î·|¶Ç¨Ó¤Tªº°Ñ¼Æ¡A¤À§O¬O hInstance¡BdwReason ¤Î dwReserved¡ChInstance ¬O°ÊºA³sµ²µ{¦¡®wªº¼Ò²Õ¥N½X¡A³o­Ó¼Ò²Õ¥N½X»P¥Dµ{¦¡ªº¼Ò²Õ¥N½X¤£¦P¡A©Ò¥HµLªk¥H GetModuleHandle ¨ú±o¡CdwReason ªí¥Ü¦]¬°­þ¤@ºØ­ì¦]¦Ó¨Ï±o§@·~¨t²Î¸ü¤J°ÊºA³sµ²µ{¦¡®w¡A§Ú­Ì¥i¦b¦¹³B°µ«e¸m³B²z©Î¬O²M°£°Ê§@¡AdwReason ¥i¤À¬°¥|ºØ­ì¦]¡G

  1. DLL_PROCESS_ATTACH¡Gªí¥Ü°ÊºA³sµ²µ{¦¡®w­è³Q¬M®g¨ì¥Dµ{¦¡ªº¦ì§}ªÅ¶¡¡A§Ú­Ì¥i¥H¦b¦¹°µ¤@¨Çµ{¦¡®w¸ü¤J®Éªºªì©l¤Æ¤u§@¡A¦pªG¦¨¥\«hªð¦^ TRUE¡F§_«hªð¦^ FALSE¡Aªí¥Üµ{¦¡®wµLªk¥¿±`¤u§@¡C·í¨Ï¥ÎªÌ¨Ï¥Î·Æ¹«¡A¦b®à­±¤WÂùÀ»¬Y¤@­Óµ{¦¡ªº¹Ï¥Ü®É¡AWindows §@·~¨t²Î·|¬°¸Óµ{¦¡«Ø¥ß¦ì§}ªÅ¶¡¡A±µµÛ§â³oµ{¦¡¥H¤Î©Ò»Ýªº°ÊºA³sµ²µ{¦¡®w¸ü¤J¶i­è«Ø¥ßªº¦ì§}ªÅ¶¡¡AµM«á¨t²Î·|¬°³o­Óµ{¦¡«Ø¥ß¥D°õ¦æºü¡A¦A¥Ñ³o­Ó¥D°õ¦æºü©I¥s¨C¤@­Ó°ÊºA³sµ²µ{¦¡®wªº¶i¤J¡þÂ÷¶}°Æµ{¦¡¡A¦¹®É dwReason °Ñ¼Æ´N¬O DLL_PROCESS_ATTACH¡C¥u­n¦³¤@­Ó°ÊºA³sµ²µ{¦¡®wªº¶Ç¦^­È¬O FALSE¡A¨º»ò¨t²Î·|²×¤îµ{¦¡Ä~Äò°õ¦æ¡C

  2. DLL_PROCESS_DETACH¡Gªí¥Üµ{¦¡®w³Q¨ø¸ü®É¡A¨t²Î·|¥H DLL_PROCESS_DETACH ¬° dwReason °Ñ¼Æ¤§­È¡A©I¥s°ÊºA³sµ²µ{¦¡®wªº¶i¤J¡þÂ÷¶}°Æµ{¦¡¡A¥i¥H¦b¦¹°µ¤@¨Ç²M°£ªº°Ê§@¡C¦Ûµ{¦¡®w¸ü¤J¨ì¨ø¸üªº¹Lµ{¤¤¡ADLL_PROCESS_ATTACH ©M DLL_PROCESS_DETACH °T®§¥uµo¥Í¤@¦¸¡C

  3. DLL_THREAD_ATTACH¡G·í¥Dµ{¦¡«Ø¥ß¤F·sªº°õ¦æºü®É¡A¨t²Î·|¥H DLL_THREAD_ATTACH ¬°°Ñ¼Æ©I¥s°ÊºA³sµ²°Æµ{¦¡¡A¥H¨Ïµ{¦¡¦³¾÷·|§@ªì©l¤Æ°õ¦æºüªº¤u§@¡C

  4. DLL_THREAD_DETACH¡G·í¥Dµ{¦¡²×¤î°õ¦æºü®É¡A¨t²Î·|¥H DLL_THREAD_DETACH ¬°°Ñ¼Æ©I¥s°ÊºA³sµ²°Æµ{¦¡¡C¦pªG¨S¦³«Ø¥ß°õ¦æºü¡ADLL_THREAD_ATTACH¡BDLL_THREAD_DETACH ´N¤£·|µo¥Í¡C

°ÊºA³sµ²µ{¦¡®w ( DLL ÀÉ ) ªº®æ¦¡»Pµøµ¡¥i°õ¦æÀÉ ( EXE ÀÉ ) ¤@¼Ë¡A³£¬O 32 ¦ì¤¸µøµ¡ªº¥i°õ¦æÀÉ¡A¤]´N¬O PE ®æ¦¡ ( portable executable )¡A©Ò¥H DLL Àɤ]¹³ EXE Àɤ@¼Ë¡A¥i¥H¥]§tµ{¦¡½X¡B¸ê®Æ©M¸ê·½¡A¦ý¬O DLL ÀÉ»P EXE ÀÉÁÙ¬O¦³¤£¦Pªº¦a¤è¡A¨º´N¬O DLL Àɤ¤§t¦³¤@­ÓºÙ¬°¶×¥Xªí³æªºªí®æ¡A¥u¦³¦b³o­Óªí®æ¤¤©Ò¦C¥Xªº°Æµ{¦¡¤~¯à¬°¨ä¥Lµ{¦¡©Ò©I¥s¡C¨º»ò­n«ç»ò¼Ë°µ¡A¦b DLL Àɤ¤ªº°Æµ{¦¡¤~¯à³Q¥~³¡µ{¦¡©I¥s©O¡Hµª®×¬O¥Ñ¼Ò²Õ©w¸qÀɤ¤©w¸q¡C

¼Ò²Õ©w¸qÀÉ ( DEF ÀÉ )

¼Ò²Õ©w¸qÀÉ ( Module-Definition File ) ªº°ÆÀɦW¬O DEF¡A¥¦¬O¦b³sµ²¶¥¬q¡A¥Î¨Ó«ü©w°ÊºA³sµ²µ{¦¡®w¤¤ªº­þ¨Ç°Æµ{¦¡¥i¥H¬°¥~³¡¥Dµ{¦¡©Ò©I¥s¡A¨Ã¥Ñ³sµ²¾¹³sµ²¼g¤J¨ì¶×¥Xªí³æùØ¡CDEF Àɪº®æ¦¡¬O¥Ñ´X­Ó¬q¸¨²Õ¦¨¡A¨C­Ó¬q¸¨³£¬O¥Ñ¤@­ÓÃöÁä¦r¶}©l¡A³o¨ÇÃöÁä¦r¦³ LIBRARY¡BEXPORT¡BSECTIONS µ¥µ¥¡CDEF Àɤ]¥i¥H¥[¤Jµù¸Ñ¡A»P²Õ¦X»y¨¥­ì©l½X¬Û¦P¡A¡y;¡z¤§«á´N¬Oµù¸Ñ¡C¨ä¥LÁÙ¦³³\¦hÃöÁä¦r¡A½Ð°Ñ¦Ò·L³nªº MSDN ºô¯¸¡C©³¤U¬O´X­Ó¦b¼Ò²Õ©w¸qÀɤ¤±`¨£ªºÃöÁä¦r¡G


¹ê§@¤@­Ó DLL ¨Ã´ú¸Õ

¹ê§@ BCDDLL

Á¿¤F³o»ò¬\ÀêµL¨ýªº²z½×¡A¦pªG¤£¹ê»Ú¾Þ§@¤@µf¡AµS¦p¯È¤W½Í§L¡A²@µL·N¸q¡A©³¤U¤p¤ì°¸´Nºt¥Ü»s§@°ÊºA³sµ²µ{¦¡®wªº¹Lµ{¡C©³¤U¤p¤ì°¸§âªþ¿ý¤Tªº¤j¼Æªº¥[ªk»P­¼ªk»s§@¦¨°ÊºA³sµ²µ{¦¡®w¬°¨Ò¡A»¡©ú¨ä»s§@¨BÆJ¡C

­º¥ý¡A¨Ì·Ó¤W­z®æ¦¡¡A¼¶¼g©³¤U¤j¼Æ¥[ªk»P¤j¼Æ­¼ªk°Æµ{¦¡¡A¨Ã¨Ì·Ó¤W­z®æ¦¡¦s¦¨ UBCDDLL.ASM¡G

        .586
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

;¥]§tÀÉ»P¶×¤Jµ{¦¡®w
INCLUDE         KERNEL32.INC
INCLUDELIB      KERNEL32.LIB

TRUE            EQU     1
GMEM_SHARE      EQU     2000h
GMEM_FIXED      EQU     0h
GMEM_ZEROINIT   EQU     40h
GPTR            EQU     GMEM_FIXED OR GMEM_ZEROINIT
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
;¶i¤J¡þÂ÷¶}°Æµ{¦¡
DLLEntry        PROC    hInstDLL,dwReason,dwReserved
                mov     eax,TRUE        ;¤£»Ý¨Æ«e³B²z©Î¨Æ«á²M²z¡A¬G¶Èªð¦^TRUE
                ret
DLLEntry        ENDP
;-------------------------------------------------------------------------------
ubcd_add        PROC    USES ebx edx esi edi lpLow1,lpLow2,lpSum,n1,n2
;­pºâ¨â«D»E¶°BCD¼Æ¤§©M
;¿é¤J¡GlpLow1¡G³Q¥[¼Æ³Ì§C¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      lpLow2¡G¥[¼Æ³Ì§C¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      lpSum¡G©M³Ì§C¦ì§}
;      n1¡G³Q¥[¼Æ¦ì¼Æ
;      n2¡G¥[¼Æ¦ì¼Æ
;¿é¥X¡GEAX¡G¬°©M©ÒÀx¦sªº¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      ECX¡G©Mªºªø«×¡A§Y¦ì¼Æ
;      EBX¡BEDX¡BESI¡BEDI§¡³Q«O¦s°_¨Ó
        mov     esi,lpLow1      ;ESI=³Q¥[¼Æ³Ì§C¦ì§}
        mov     ebx,lpLow2      ;EBX=¥[¼Æ³Ì§C¦ì§}
        mov     eax,n1
        cmp     eax,n2  ;¤ñ¸û³Q¥[¼Æ»P¥[¼Æ¨º¤@­Ó¦ì¼Æ¤j
        jae     u_a0
        xchg    eax,n2  ;­Y¥[¼Æ¦ì¼Æ¤j¡A«h¨Ï³Q¥[¼Æ»P¥[¼Æ¥æ´«³Ì§C¦ì§}
        xchg    esi,ebx ;(ESI»PEBX)¡A¦P®É¤]¥æ´«¦ì¼Æ(n1¡Nn2)
        mov     n1,eax
        mov     lpLow2,esi
        mov     lpLow1,ebx

;¶}©l¬Û¥[®É¡AESI«ü¦V¨â¼Æ¦ì¼Æ¸û¤jªÌªº¦ì§}¡An1¬°¨ä¦ì¼Æ
u_a0:   sub     eax,n2
        mov     n1,eax  ;n1¡×­«Å|³¡¥÷ªº¦ì¼Æ
        mov     edi,lpSum

;­pºâ­«Å|³¡¥÷¡A¨Ò¦p
;  987654
;+    912
;---------
;  988566
;³Q¥[¼Æ¡B¥[¼Æ³£¦³­Ó¦ì¡B¤Q¦ì¡B¦Ê¦ì¼Æ¡A©Ò¥H¬O­«Å|ªº³¡¥÷¡C
        clc
        sub     eax,eax
u_a1:   lodsb           ;¨ú±o¥[¼Æ¤¤ªº¤@¦ì
        add     al,ah   ;¥[¤W¶i¦ìªº¼Æ
        cbw
        add     al,[ebx]
        aaa             ;¥[ªk½Õ¾ã¡A­Y¦³¶i¦ì¡A·|¦s¦bAHùØ
        stosb           ;¦s¤J©M¤º
        inc     ebx
        dec     n2
        jnz     u_a1
        cmp     n1,0
        jz      u_a3    ;°²¦p³Q¥[¼Æ»P¥[¼Æ¦ì¼Æ¬Û¦P®É¡An1·|µ¥©ó¹s

;­pºâ¥u¦³¸û¤j¦ì¼Æ³¡¥÷¡A¥H¤W­±¬°¨Ò¡A§Y­pºâ
;  987654
;+ 000912
;---------
;  988566
;987+000ªº³¡¥÷
u_a2:   lodsb
        add     al,ah    ;AH¡×­pºâ­«Å|³¡¥÷«áªº¶i¦ì
        cbw
        aaa
        stosb
        dec     n1
        jnz     u_a2

;³B²z³Ì¤j¦ì¼Æ¶i¦ì
u_a3:   sub     al,al   ;¨ÏALµ¥©ó¹s
        add     al,ah   ;AH¡×¶i¦ì¡A¥[¤W¶i¦ì
        or      al,al
        jz      u_a4
        stosb
u_a4:   mov     ecx,edi
        mov     eax,lpSum
        sub     ecx,eax
        ret
ubcd_add        ENDP
;-------------------------------------------------------------------------------
ubcd_mul        PROC    USES ebx edx esi edi lpLow1,lpLow2,Product,n1,n2
;­pºâ¨â«D»E¶°BCD¾ã¼Æ¤§­¼¿n
;¿é¤J¡GlpLow1¡G³Q­¼¼Æ³Ì§C¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      lpLow2¡G­¼¼Æ(multiplier)³Ì§C¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      Product¡G­¼¿n³Ì§C¦ì§}
;      n1¡G³Q­¼¼Æ¦ì¼Æ
;      n2¡G­¼¼Æ¦ì¼Æ
;¿é¥X¡GEAX¡G¬°­¼¿n©ÒÀx¦s¦ì§}¡A¥H¥¼»E¶°BCD¤è¦¡Àx¦s¡A¤j¦ì¼Æ¦b°ª¦ì§}
;      ECX¡G­¼¿nªº¦ì¼Æ
;      EBX¡BEDX¡BESI¡BEDI§¡³Q«O¦s°_¨Ó
;­ì²z¡G­¼¿n¦ì¼Æ¡AnProduct¡A¥i¯à¬O(n1¡Ïn2)©Î(n1¡Ïn2¡Ð1)¡A¥ý°²³]nProduct¡×(n1¡Ïn2)¡A³Ì«á¦A
;¡@¡@¡@½Õ¾ã¡C§@ª½¦¡­¼ªk»Ý­n°t¸m°O¾ÐÅé§@¬°¼È¦s°Ï¡A©Ò°t¸m°O¾ÐÅ骺¤j¤p¬°
;¡@¡@¡@SizeTemp¡×­¼¿n¦ì¼Æ¡Ñ(­¼¼Æ¦ì¼Æ¡Ï1)­Ó¦ì¤¸²Õ
;¡@¡@¡@¥H987654*912=900740448¬°¨Ò¡AnProduct¬°9¡A¶·°t¸m°O¾ÐÅé(9¡Ñ3¡Ï9)­Ó¦ì¤¸²Õ¡C
;         987654 ³Q­¼¼Æ¡A¦s©ó©Ò°t¸m°O¾ÐÅé¦ì§}ªº0¡ã(SizeTemp-1)³B¡A¤]¬O­¼¿n©Ò¦s©ñ³B¡A¦@¦³n1¦ì¼Æ
;       x    912 ­¼¼Æ¡A¦s©ó©Ò°t¸m°O¾ÐÅé¦ì§}ªºLARGEST¡ã(SizeTemp+3FH)³B¡A¦@¦³n2¦ì¼Æ¡A¦¹¨Òn2=3
;      ----------
;      zz1975308 ¼È¦s°Ï¡A¥Ñ©Ò°t¸m°O¾ÐÅé¦ì§}ªº(LARFEST+40H)³B¶}©l¡A¹ï¨C¤@¦ì­¼¼Æ¦Ó¨¥
;      z0987654z ¡A§¡¦û¾Ún1+n2¦ì¼Æ¡A¦¹¨Òn1+n2¦@9¦ì¼Æ¡A­¼¿n¤]¬O9¦ì¼Æ
;      8888886zz
;      ----------
;      900740448
;³Q­¼¼Æ·|³Q¤T¦ì­¼¼Æ­¼¤T¦¸¡A¨C¤@¦¸³£¥i¤À¦¨¤T³¡¥÷¡G³Ì¥kÃä­n¶ñ¤J0¡A¬Û­¼¡A°µ¥ªÃä¤]­n¶ñ¤J0
;©³¤Uªº°Ï°ìÅܼơAlpHi1,lpHi2,nProduct¤À§Oªí¥Ü³Q­¼¼Æ³Ì°ª¦ì§}¡B­¼¼Æ³Ì°ª¦ì§}¡B­¼¿n¦ì¼Æ
        LOCAL   lpHi1,lpHi2,nProduct:DWORD
        LOCAL   lpTemp:DWORD    ;°t¸m°O¾ÐÅé¦ì§}
        clc
        mov     ecx,n1          ;­pºâ­¼¿n¦ì¼Æ¡A¨Ã¦s©ónProduct
        mov     eax,n2          ;­¼¼Æ¦ì¼Æ
        add     ecx,eax         ;ECX¡×­¼¿n¦ì¼Æ
        mov     nProduct,ecx
        inc     eax             ;­¼¼Æ¦ì¼Æ¡Ï1
        sub     edx,edx
        mul     ecx             ;EAX¡×­¼¿n¦ì¼Æ¡Ñ(­¼¼Æ¦ì¼Æ¡Ï1)
        INVOKE  GlobalAlloc,GMEM_SHARE or GPTR,eax
        mov     lpTemp,eax

        mov     eax,lpLow1      ;­pºâ³Q­¼¼Æ¡B­¼¼Æ³Ì¤j¦ì¼Æ©Ò¦b¦ì§}¡A
        mov     ebx,lpLow2      ;¨Ã¦s©ólpHi1¡BlpHi2
        add     eax,n1
        add     ebx,n2
        mov     lpHi1,eax
        mov     lpHi2,ebx

;²Ä¤@¶¥¬q¡A³B²z¨C¤@¦ì­¼¼Æ¥h­¼³Q­¼¼Æ
        mov     edi,lpTemp      ;EDI«ü¦V¼È¦s°Ï(¦s©ñ¨C¤@¦ì­¼¼Æ¬Û­¼«áªºµ²ªG)
        mov     esi,lpLow2      ;¨C¦¸­pºâ­¼¼Æ¤@¦ì¼Æ­¼³Q­¼¼Æµ²ªG¤§°j°é¶}©l
m1:     sub     eax,eax         ;²M°£EAX¡NEDX¨Ï©¹«áªºAAM¡NAAA«ü¥O¯à¥¿½T¹Bºâ
        mov     edx,eax

        mov     ecx,esi         ;¤p¦ì¼Æªº¶ñ¹s³¡¤À¡AECX¬°¶ñ¹sªº­Ó¼Æ
        sub     ecx,lpLow2
        mov     ebx,lpLow1      ;­pºâ­¼¼Æ¨C¦ì¼Æ­¼³Q­¼¼Æ³¡¤À
        push    ecx
        jcxz    m3
m2:     stosb
        loop    m2

m3:     mov     al,[ebx]        ;BX«ü¦V³Q­¼¼Æ
        mul     BYTE PTR [esi]
        aam
        add     al,dh           ;¥[¤W«e¤@¦¸ªº¶i¦ì
        aaa
        mov     dh,ah           ;¶i¦ì¦s©óDH
        stosb
        inc     ebx
        cmp     ebx,lpHi1
        jne     m3

        mov     [edi],dh        ;³B²z¶i¦ì³¡¤À
        inc     edi

        pop     eax             ;³B²z¤j¦ì¼Æ¶ñ¹s³¡¤À
        mov     ecx,nProduct
        sub     ebx,lpLow1
        sub     ecx,eax
        sub     ecx,ebx
        dec     ecx             ;ECX¬°¶ñ¹sªº­Ó¼Æ
        jcxz    m5
m4:     mov     BYTE PTR [edi],0
        inc     edi
        loop    m4

m5:     inc     esi             ;«ü¦V­¼¼Æªº¤U¤@¦ì
        cmp     esi,lpHi2       ;Àˬd­¼¼Æ¬O§_³£¤wºâ§¹
        jne     m1

;²Ä¤G¶¥¬q¡A³B²z¦b¼È¦s°Ï¤¤¨C¤@¦ì­¼¼Æ­¼¿n¤§©M
        mov     edi,Product
        mov     ecx,nProduct
        xor     eax,eax
        inc     ecx
        rep     stosb           ;²M°£­¼¿nªº©U§£¸ê®Æ

        mov     esi,Product     ;ESI=­¼¿n¦ì§}
        mov     ebx,lpTemp      ;EBX¬°¼È¦s°Ï¦ì§}
        mov     edx,nProduct
m6:     INVOKE  ubcd_add,esi,ebx,esi,edx,edx    ;ESI=ESI+EBX
        add     ebx,edx
        dec     n2              ;n2=­¼¼Æ¦ì¼Æ¡A§Y­n¬Û¥[¦¸¼Æ
        jnz     m6
        INVOKE  GlobalFree,lpTemp
        mov     eax,Product
        mov     ecx,nProduct
        cmp     BYTE PTR [eax+ecx-1],0  ;Àˬd³Ì°ª¦ì¼Æ¬O§_¬°¹s
        jnz     m7
        dec     ecx             ;­Y¨S¦³¶i¦ì¡A«h­¼¿n¦ì¼Æ´î¤@
m7:     ret
ubcd_mul        ENDP
;*******************************************************************************
                END     DLLEntry

²Ä¤G¨B¡A¼¶¼g©³¤Uªº UBCDDLL.DEF ÀÉ¡G

EXPORTS
        UBCD_ADDS=ubcd_add
        UBCD_MULS=ubcd_mul

¦¹³B¤p¤ì°¸¥H UBCD_ADDS¡BUBCD_MULS ¨ú¥N­ì¥ýªº°Æµ{¦¡ ubcd_add¡Bubcd_mul ¦WºÙ¡C

²Ä¤T¨B¡A±Ò°Ê¡y©R¥O´£¥Ü¦r¤¸¡z¡A°õ¦æ²ÕĶ¡B³sµ²¦Ó²£¥Í¤T­ÓÀɮסAUBCDDLL.DLL¡BUBCDDLL.LIB ¤Î UBCDDLL.EXP¡C¶}±Ò XP ªº©R¥O´£¥Ü¦r¤¸¡A¿é¤J¤U¦C«ü¥O¡G(¡uml /c¡v¤¤ªº¡u/c¡v¬O«ü¥Ü ML.EXE ¥u²ÕĶ¤£³sµ² )

E:\HomePage\SOURCE\Win32\DLL>ml /c ubcddll.asm [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: ubcddll.asm

E:\HomePage\SOURCE\Win32\DLL>link /DLL /SUBSYSTEM:WINDOWS /DEF:ubcddll.def ubcddll.obj [Enter]
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

   Creating library ubcddll.lib and object ubcddll.exp

E:\HomePage\SOURCE\Win32\DLL>

²Ä¥|¨B¡A¤]¬O³Ì«á¤@¨B¡A¬°­è«Ø¥ß¦nªº°ÊºA³sµ²µ{¦¡®w¼¶¼g¥]§tÀÉ ( INC ÀÉ ) ¤Î»¡©ú¡A¦b³o­Ó¨Ò¤lùØ¡A¥]§tÀÉ¡AUDCDDLL.INC¡A¤º®e¦p¤U¡G

UBCD_ADDS       PROTO   :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
UBCD_MULS       PROTO   :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

¦pªG·Q§â¦Û¤vªº³Ç§@µo§Gµ¹¨ä¥L¦P¦n¨Ï¥Î¡AÀ³¸Ó­n¥]§t INC ÀÉ¡BDLL ÀÉ¡BLIB Àɤλ¡©úÀÉ¡C»¡©úÀÉ¥i¥Î¯Â¤å¦r®æ¦¡¡AÀx¦s¦¨ TXT ÀÉ¡A©Î¬O HTML ®æ¦¡¡C¦p¯àªþ¤W­ì©l½X¡AÅý¤j®aÆ[¼¯±zªºµ{¦¡¡A¤]¬O¤£¿ù¡C

´ú¸Õ DLL ÀÉ

¤p¤ì°¸¤w§¹¦¨¤@­Ó°ÊºA³sµ²®w¡A©³¤U´N¨Ó¥Ü½d¦p¦ó¨Ï¥Î¥¦¡C©³¤U³o­Óµ{¦¡¡ATEST.ASM¡A°õ¦æ«á·|¦b®à­±¤W¥X²{¤@­Ó¹ï¸Ü²°¡A¥i¥H°µ«Ü¤j¦ì¼Æªº¥[ªk¤Î­¼ªk¡A¥¦·|©I¥s°ÊºA³sµ²µ{¦¡®w¡AUBCDDLL.DLL¡A¹ê²{¤j¦ì¼Æªº¥[ªk¤Î­¼ªk¡C¨ä­ì©l½X¦p¤U¡G

;¦¹µ{¦¡½X¬O¬°¤F´ú¸Õ°ÊºA³sµ²µ{¦¡®w¦Ó»s§@ªº¡A¥]§t¨â­Óµ{¦¡¡A­pºâ¤j¦ì¾ã¼Æªº¥[ªk»P­pºâ¤j¦ì¾ã¼Æªº­¼ªk
        .586
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

INCLUDE         WINDOWS.INC
INCLUDE         USER32.INC
INCLUDE         KERNEL32.INC
INCLUDELIB      USER32.LIB
INCLUDELIB      KERNEL32.LIB
INCLUDE         UBCDDLL.INC     ;¤p¤ì°¸»s§@ªºUBCDDLL.INC¥]§tÀÉ
INCLUDELIB      UBCDDLL.LIB     ;¤p¤ì°¸»s§@ªºUBCDDLL.DLL°ÊºA³sµ²µ{¦¡®w

IDC_CALC        EQU             2001
IDC_EXIT        EQU             2002
IDC_N1          EQU             2003
IDC_N2          EQU             2004
IDC_ANSWER      EQU             2005
IDC_OP          EQU             2006

MAX_DIGIT       EQU             20

;*******************************************************************************
.DATA
hInstance       HINSTANCE       ?
index           DWORD           ?       ;³Q¿ï©wªº¹Bºâ¤l¡G¥[ªk¡G0¡A­¼ªk¡G1
szDlgName       BYTE            'AddNMul',0
szAdd           BYTE            '¡Ï',0
szMul           BYTE            '¡Ñ',0
ubcdN1          BYTE            MAX_DIGIT+1 DUP (?)
ubcdN2          BYTE            MAX_DIGIT+1 DUP (?)
buffer          BYTE            2*MAX_DIGIT+1 DUP (?)
nN1             DWORD           ?
nN2             DWORD           ?
szAnswer        BYTE            '='
answer          BYTE            2*MAX_DIGIT+1 DUP (?)
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
get_number      PROC    USES esi edi hDia:HANDLE,ID:DWORD,adrOperand:DWORD
        LOCAL   szuBcd[MAX_DIGIT+2]:BYTE
        LOCAL   nBcd:DWORD
        INVOKE  GetDlgItemText,hDia,ID,ADDR szuBcd,MAX_DIGIT+1
        mov     nBcd,eax
        mov     ecx,eax
        jecxz   no_n
        lea     esi,szuBcd
        mov     edi,adrOperand
        add     esi,ecx
        dec     esi
        clc
next:   mov     al,[esi]
        and     al,0fh
        dec     esi
        stosb
        loop    next
        mov     eax,ecx
        stosb
        mov     eax,nBcd
no_n:   ret
get_number      ENDP
;-------------------------------------------------------------------------------
DlgProc PROC    hDlg:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        LOCAL   hOperator:HANDLE
.IF uMsg==WM_INITDIALOG
        ;¸ü¤J¹Ï¥Ü
                INVOKE  LoadIcon,hInstance,OFFSET szDlgName
                INVOKE  SendMessage,hDlg,WM_SETICON,ICON_SMALL,eax
        ;§â¥[¡B­¼ªk¹Bºâ¤l¥[¤J½Æ¦X®ØùØ
                INVOKE  GetDlgItem,hDlg,IDC_OP
                mov     hOperator,eax
                INVOKE  SendMessage,hOperator,CB_ADDSTRING,NULL,OFFSET szAdd
                INVOKE  SendMessage,hOperator,CB_ADDSTRING,NULL,OFFSET szMul
        ;³]©w½s¿è®Ø³Ì¦h¿é¤J¦ì¼Æ
                INVOKE  GetDlgItem,hDlg,IDC_N1
                INVOKE  SendMessage,eax,EM_SETLIMITTEXT,MAX_DIGIT,NULL
                INVOKE  GetDlgItem,hDlg,IDC_N2
                INVOKE  SendMessage,eax,EM_SETLIMITTEXT,MAX_DIGIT,NULL

.ELSEIF uMsg==WM_COMMAND
                mov     edx,wParam
                mov     eax,wParam
                shr     edx,10h         ;EDX=³qª¾½X
                and     eax,0ffffh      ;EAX=±±¨î¤¸¥óÃѧO½X
   .IF dx==BN_CLICKED
      .IF ax==IDC_EXIT
                jmp     exit
      .ELSEIF ax==IDC_CALC
                INVOKE  get_number,hDlg,IDC_N1,OFFSET ubcdN1
                mov     nN1,eax
                or      eax,eax
                jz      no_input
                INVOKE  get_number,hDlg,IDC_N2,OFFSET ubcdN2
                mov     nN2,eax
                or      eax,eax
                jz      no_input
         .IF index==0
                INVOKE  UBCD_ADDS,OFFSET ubcdN1,OFFSET ubcdN2,OFFSET buffer,nN1,nN2 ;©I¥sUDCDDLL.DLLùتºubcd_add°Æµ{¦¡
         .ELSEIF index==1
                INVOKE  UBCD_MULS,OFFSET ubcdN1,OFFSET ubcdN2,OFFSET buffer,nN1,nN2 ;©I¥sUDCDDLL.DLLùتºubcd_mul°Æµ{¦¡
         .ELSE
                jmp     no_input
         .ENDIF
                mov     edx,OFFSET buffer
                mov     edi,OFFSET answer
                add     edx,ecx
                dec     edx
@@:             mov     al,[edx]
                or      al,'0'
                dec     edx
                stosb
                dec     ecx
                jnz     @b
                mov     al,cl
                stosb
                INVOKE  SetDlgItemText,hDlg,IDC_ANSWER,OFFSET szAnswer
      .ENDIF
   .ELSEIF dx==CBN_SELENDOK
                INVOKE  SendDlgItemMessage,hDlg,IDC_OP,CB_GETCURSEL,0,0
                mov     index,eax
   .ENDIF
no_input:

.ELSEIF uMsg==WM_CLOSE
exit:   INVOKE  EndDialog,hDlg,NULL 

;¨ä¥L°T®§
.ELSE
        mov     eax,FALSE
        ret
.ENDIF
        mov     eax,TRUE
        ret
DlgProc ENDP
;-------------------------------------------------------------------------------
start:  INVOKE  GetModuleHandle,NULL
        mov     hInstance,eax
        INVOKE  DialogBoxParam,hInstance,OFFSET szDlgName,NULL,OFFSET DlgProc,NULL
        INVOKE  ExitProcess,eax
;*******************************************************************************
        END     start

§â¥¦¦s¦¨ TEST.ASM ÀÉ¡CµM«á¼¶¼g¸ê·½´y­zÀÉ¡ATEST.RC¡G

#include "c:\masm32\include\resource.h"

#define IDC_CALC    2001
#define IDC_EXIT    2002
#define IDC_N1      2003
#define IDC_N2      2004
#define IDC_ANSWER  2005
#define IDC_OP      2006

AddNMul         ICON    exclamation01.ico

AddNMul         DIALOG  6, 15, 185, 90
STYLE           DS_MODALFRAME|WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU
CAPTION         "­pºâ¤j¾ã¼Æ¥[ªk»P­¼ªk"
FONT            8,"MS Sans Serif"
{
 EDITTEXT       IDC_N1,      5, 13, 70, 12,WS_TABSTOP|ES_NUMBER|ES_RIGHT|ES_AUTOHSCROLL
 COMBOBOX       IDC_OP,     77, 13, 28, 40,CBS_DROPDOWNLIST|WS_VSCROLL
 EDITTEXT       IDC_N2,    105, 13, 70, 12,WS_TABSTOP|ES_NUMBER|ES_RIGHT|ES_AUTOHSCROLL
 LTEXT          "=",IDC_ANSWER,  5, 30,160, 12
 DEFPUSHBUTTON  "­pºâ",IDC_CALC,10, 55, 80, 20
 PUSHBUTTON     "Â÷¶}",IDC_EXIT,95, 55, 80, 20
}

¹³¥H«e²ÕĶ¡B³sµ²µ{¦¡¤@¼Ë¡A§â¹Ï¥ÜÀÉ ( exclamation01.ico )¡B­ì©l½X ( TEST.ASM ) ©M¸ê·½´y­zÀÉ ( TEST.RC ) ©ñ¦b¦P¤@¸ê®Æ§¨ùØ¡A¦b©R¥O´£¥Ü¦r¤¸¤¤¡A¤U¹F¤U¦C«ü¥O¡G

E:\HomePage\SOURCE\DLL>rc test.rc [Enter]

E:\HomePage\SOURCE\DLL>ml test.asm /link test.res [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: test.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"test.obj" /DEBUG
"/OUT:test.exe"
"test.res"

E:\HomePage\SOURCE\DLL>test [Enter] ¡÷°õ¦æ¡I

¤U¹Ï¬O°õ¦æ®Éªºµe­±¡A±z¥i¥H¦b¨â­Ó½s¿è®ØùØ¿é¤Jªü©Ô§B¼Æ¦r¡A¦b½Æ¦X®Ø¤¤¿ï¨ú¥[ªk©Î´îªk¹Bºâ¤l¡A«ö¤U¡y­pºâ¡z«ö¶s±o¨ìµ²ªG¡C

¦b TEST.ASM ùØ¡Aµ{¦¡³B²z¤F¨â­Ó±±¨î¤¸¥óªº³qª¾½X¡A¤@­Ó¬O BN_CLICKED¡A¥t¤@­Ó¬O CBN_SELENDOK ¡C·í¨Ï¥ÎªÌ«ö¤U¥ô¦ó¤@­Ó«ö¶s®É¡A¨t²Î·|µo¥X BN_CLICKED ³qª¾½Xµ¹µ{¦¡¡AµM«á¦b¥hÀˬd¬O­þ¤@­Ó«ö¶s³Q«ö¤U¡A¦pªG¬O IDC_EXIT ³Q«ö¤U¡A«hÂ÷¶}µ{¦¡¡F¦pªG¬O IDC_CALC ³Q«ö¤U¡A«h­pºâµ²ªG¡C·í¨Ï¥ÎªÌ¿ï©w½Æ¦X®Ø²M³æ¤ºªº¿ï¶µ®É¡A¨t²Îµo¥X CBN_SELENDOK ³qª¾½X¡Aµ{¦¡­n¨ú±o¨Ï¥ÎªÌ¿ï¾Ü¥[ªkÁÙ¬O­¼ªk¡C³o¬qµ{¦¡³£¦b³B²z WM_COMMAND °T®§¤¤¹ê§@¥X¨Ó¤F¡C


°õ¦æ®É°ÊºA³sµ² DLL

¨Æ¹ê¤W¡A©I¥s DLL Àɤ¤ªº°Æµ{¦¡¡A¦³¨âºØ¤è¦¡¡A²Ä¤@ºØ¤è¦¡´N¬O«e­z©Ò¨Ï¥Îªº¤è¦¡¡AºÙ¬°¡y¸ü¤J®É°ÊºA³sµ²¡z ( load-time dynamic linking¡A¤S¥s·t¥Ü©Ê³sµ² )¡F²Ä¤GºØ¤è¦¡«hºÙ¬°¡y°õ¦æ®É°ÊºA³sµ² ¡z( Run-Time Dynamic Linking¡A¤S¥s©ú½T©Ê³sµ² )¡C°õ¦æ®É°ÊºA¸ü¤J DLL¡A¤£»Ý­n«ü©w¥]§tÀɤζפJµ{¦¡®w¡A¨º»ò«ç»òª¾¹D­n¸ü¤J­þ¤@­Óµ{¦¡®w©O¡H­ì¨Ó²Ä¤@­Ó¨BÆJ±o¦b­ì©l½X¤¤©I¥s LoadLibrary ©Î LoadLibraryEx API¡A¥Ñµ{¦¡¦Û¤v¸ü¤J DLL¡C°²¦p¸ü¤J¦¨¥\¡A²Ä¤G­Ó¨BÆJ¬O©I¥s GetProcAddress Àò±o°ÊºAµ{¦¡®w¤¤°Æµ{¦¡ªº¦ì§}¡C²Ä¤T­Ó¨BÆJ¡A·í­n©I¥s¸Ó°Æµ{¦¡®É¡A¥i¥Î 80x86 ªº push «ü¥O§â°Ñ¼Æ±À¤J°ïÅ|¡A¦A¥Î call «ü¥O©I¥s¸Ó°Æµ{¦¡ªº¦ì§}¡C³Ì«á¡A¦pªG¤£¦A»Ý­n°ÊºA³sµ²µ{¦¡®w®É ( ¨Ò¦pµ{¦¡µ²§ô®É )¡A©I¥s FreeLibrary ¨ø¸ü¦¹µ{¦¡®w¡C©³¤U¥ý¬Ý¬Ý©Ò¥Î¨ìªº API¡C

LoadLibrary API

LoadLibrary ­ì«¬¬O

HINSTANCE LoadLibrary(
   LPCTSTR  lpLibFileName       // address of filename of executable module 
   );

°Ñ¼Æ lpLibFileName ¬O«ü¦V *.DLL ©Î *.EXE ÀɮצWºÙ©Ò¦bªº¦r¦ê¦ì§}¡A°²¦p¦¹¦r¦ê¥]§t¸ô®|¡A¶·¥H¡y\¡z¤À¹j¨C­Ó¤l¥Ø¿ý¦W¦r¡A³Ì«á³o­Ó¦r¦ê¥H 0 µ²§À¡C¦pªGÀɦW¥u¦C¥X¥DÀɦW¡A·|¦Û°Ê¥[¤W¡y.DLL¡z¡A¦ý¸U¤@°ÊºA³sµ²µ{¦¡®w¯uªº¨S¦³°ÆÀɦW¡A¨º»ò´N­n¦bÀɦW«á¥[¤W¡y.¡zªí¥Üµ²§À¨S°ÆÀɦW¡C¦pªG¨S¦³¸ô®|¦WºÙ¡ALoadLibrary ·|¨Ì¤U­±¶¶§Ç·j´M DLL ÀÉ¡G

  1. ¥Dµ{¦¡©Ò¦b¥Ø¿ý¡C
  2. ²{¦bªº¤u§@¥Ø¿ý¡C
  3. Windows ¨t²Î¥Ø¿ý¡C¹ï XP ¦Ó¨¥¡A¤º©wªº¨t²Î¥Ø¿ý¦W¬O¡yC:\WINDOWS\SYSTEM32¡z¡C
  4. Windows ¥Ø¿ý¡C¹ï XP ¦Ó¨¥¡A¤º©wªº Windows ¥Ø¿ý¦W¬O¡yC:\WINDOWS¡z¡C
  5. Àô¹ÒÅÜ¼Æ PATH ©Ò¦CÁ|ªº¥Ø¿ý¡C

°²¦p LoadLibrary ¦¨¥\¦a§ä¨ì¨Ã¸ü¤J DLL ÀÉ¡AEAX ¤¤·|¶Ç¦^¼Ò²Õ¥N½X¡F¦pªG¥¢±Ñ¡AEAX ·|¶Ç¦^ NULL¡C

LoadLibraryEx API

HINSTANCE LoadLibraryEx(
    LPCTSTR     lpLibFileName,  // points to name of executable module
    HANDLE      hFile,          // reserved, must be NULL 
    DWORD       dwFlags         // entry-point execution flag 
   );

LoadLibraryEx ªº²Ä¤@­Ó°Ñ¼Æ»P LoadLibrary ¬Û¦P¡ChFile ³Q«O¯dµ¹¥H«á¨Ï¥Î¡A¥²¶·¬° NULL¡C°Ñ¼Æ dwFlags ¬O¥Î¨Ó¸ü¤J°ÊºA³sµ²µ{¦¡®w¤§«áµo¥Íªº°Ê§@¡A¥i¥H¬O¤U­±´X¶µ

LoadLibraryEx ¦pªG¦¨¥\ªº¸ü¤J DLL ÀÉ¡A·|¶Ç¦^¼Ò²Õ¥N½X¡F¦pªG¥¢±Ñ¡AEAX ·|¶Ç¦^ NULL¡C

GetProcAddress API

GetProcAddress ¬O¥Î¨Ó¨ú±o°ÊºA³sµ²µ{¦¡®w¤¤¬Y­Ó¶×¥X°Æµ{¦¡©ÎÅܼƪº¦ì§}¡A¨ä­ì«¬¦p¤U¡G

FARPROC GetProcAddress(
    HMODULE hModule,    // handle to DLL module  
    LPCSTR  lpProcName  // name of function 
   );

°Ñ¼Æ¡AhModule¡A¬O°ÊºA³sµ²µ{¦¡®wªº¼Ò²Õ¥N½X¡A¤]´N¬O LoadLibrary ©Î LoadLibraryEx ªº¶Ç¦^­È¡ClpProcName ¬O¬Y­Ó°Æµ{¦¡©ÎÅܼƪº¦WºÙ¡A¶·¥H¹s¬°µ²§À¡A¨ä¦r¥À«÷ªk¤Î¤j¤p¼g¬O¨Ì¾Ú¼Ò²Õ©w¸qÀɤ¤ EXPORT ¬q¸¨¤¤©Ò´y­zªº¡AlpProcName ¤]¥i¥H¬O§Ç¼Æ¡C¦pªG GetProcAddress °õ¦æ¦¨¥\¡A·|¶Ç¦^ DLL ªº°Æµ{¦¡¶i¤JÂI¦ì§}¡F¦pªG¥¢±Ñ«h¶Ç¦^ NULL¡CµM«á§Ú­Ì§â³o­Ó¶i¤JÂIªº¦ì§}°O¿ý¦b¬Y­ÓÅܼÆùØ¡A¨Ò¦p lpProc ÅܼơA·í¥Dµ{¦¡­n©I¥s°ÊºA³sµ²µ{¦¡®w¤¤ªº°Æµ{¦¡®É¡A´N¥H¤U­±¤è¦¡©I¥s°Æµ{¦¡¡G

                push    °Ñ¼Æ¤@
                push    °Ñ¼Æ¤G
                ¡K¡K
                call    lpProc

¦pªG­n¨Ï¥Î INVOKE °²«ü¥O©I¥sªº¸Ü¡A±o¨Æ¥ý«Å§i¡A¥i¥H§Q¥Î¨â¦¸ TYPEDEF °²«ü¥O¡G

UBCD_PROTO      TYPEDEF         PROTO   :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
UBCD_PROC       TYPEDEF         PTR UBCD_PROTO

²Ä¤@¥y¬O¥Î¨Ó«Å§i¤­­Ó°Ñ¼Æªº­ì«¬©w¸q¦¨ UBCD_PROTO¡A²Ä¤G¥y¦A§â UBCD_PROC «ü©w¬° UBCD_PROTO ªº«ü¼Ð¡A±µµÛ´N¥i¥H¦b¸ê®Æ¬q©w¸q°Æµ{¦¡¦ì§}¡A¦p­n©I¥s®É¡A´N¥i¥Î INVOKE ©I¥s¤F¡C¤j·§ªºµ{¦¡½X¦p¤U¡G

.DATA
lpMulProc       UBCD_PROC       ?
¡K¡K¡K¡K
.CDOE
¡K¡K¡K¡K
    INVOKE  GetProcAddress,hModule,OFFSET szBigMul
 .IF eax
    mov     lpMulProc,eax
¡K¡K¡K¡K
    INVOKE  lpMulProc,OFFSET ubcdN1,OFFSET ubcdN2,OFFSET buffer,nN1,nN2

FreeLibrary

FreeLibrary ªº­ì«¬¬O

BOOL FreeLibrary(
    HMODULE hLibModule 	        // handle to loaded library module  
   );

hLibModele ¬O°ÊºA³sµ²µ{¦¡®wªº¼Ò²Õ¥N½X¡A¥ç§Y©I¥s LoadLibrary «áªº¶Ç¦^­È¡C·íµ{¦¡µ²§ô©Î¤£¦A©I¥s DLL ®É¡A´N¥i¥H§â¥¦±q¦Û¤vªº°O¾ÐÅé¦ì§}ªÅ¶¡¨ø¸ü¡A´N¥i¥H©I¥s FreeLibrary¡C

·í¨Ï¥Î¡y°õ¦æ®É°ÊºA³sµ²¡z¤è¦¡©I¥s°ÊºA³sµ²µ{¦¡®w¤¤ªº°Æµ{¦¡®É¡A³£À³¸ÓÀˬd LoadLibrary¡BGetProcAddress ¬O§_¦¨¥\ªº¥¿½T°õ¦æ¡A¨Ã¶Ç¦^¥¿½T­È¡F§_«h¶Ç¦^ NULL ¦Ó¤£Àˬd¡A«Ü®e©ö³y¦¨¿ù»~¡C¦]¬°¦pªG¸ü¤J°ÊºA³sµ²µ{¦¡®w¿ù»~©Î¨ú±o°Æµ{¦¡¦ì§}¿ù»~¡A³£·|¤Þµoµ{¦¡¸õ¨ì¿ù»~¦ì§}°õ¦æ¡A¥²©w¤Þµoµ{¦¡²×¤î¡C¥¿¦]¬°¦³¾÷·|Àˬd°ÊºA³sµ²µ{¦¡®w©Î¨ä¤¤ªº°Æµ{¦¡¬O§_¥¿½T¡A©Ò¥H§Y¨Ï§ä¤£¨ì°ÊºA³sµ²µ{¦¡®w©Î°Æµ{¦¡¡A¤]¤£­P¨Ï¥Dµ{¦¡§¹¥þ¤£¯à°õ¦æ¡A§Ú­Ì¥i¥H¤p¤ßªº¼¶¼g¯Ê¤Ö¦³Ãö¸Ó°ÊºA³sµ²µ{¦¡®wªº¥\¯à¡A¦Ó¤£·|¼vÅT¨ìªº¥\¯à¤´¯à°õ¦æ¡C

¹¢ºt¡y°õ¦æ®É°ÊºA³sµ²¡z

©³¤Uªº TEST2.ASM ¬O§Q¥Î¡y°õ¦æ®É°ÊºA³sµ²¡z©I¥s DLL¡A­ì©l½X¦p¤U¡G

.586
        .MODEL  FLAT,STDCALL
        OPTION  CASEMAP:NONE

INCLUDE         WINDOWS.INC
INCLUDE         USER32.INC
INCLUDE         KERNEL32.INC
INCLUDELIB      USER32.LIB
INCLUDELIB      KERNEL32.LIB

IDC_CALC        EQU             2001
IDC_EXIT        EQU             2002
IDC_N1          EQU             2003
IDC_N2          EQU             2004
IDC_ANSWER      EQU             2005
IDC_OP          EQU             2006

MAX_DIGIT       EQU             40      ;¥i­pºâ40¦ì¼Æªº¥[ªk©Î­¼ªk

;©³¤U¨â¦æ¥i¥H¦b©I¥s DLL °Æµ{¦¡®É¨Ï¥Î INVOKE¡A¤£¹L¦¹µ{¦¡¤¤¤p¤ì°¸¥Î call ©I¥s¤j¼Æ¥[ªk¡A¥Î INVOKE ©I¥s­¼ªk
UBCD_PROTO      TYPEDEF         PROTO   :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
UBCD_PROC       TYPEDEF PTR     UBCD_PROTO

;*******************************************************************************
.CONST
szUBCDDLL       BYTE            'UBCDDLL.DLL',0 ;©w¸q DLL ÀɦW¥H¤Î°Æµ{¦¡¦WºÙ
szBigAdd        BYTE            'UBCD_ADDS',0   ;©w¸q°Æµ{¦¡¦WºÙ¡A¦]¬°¦b¼Ò²Õ©w¸qÀÉ¡A¥HUBCD_ADDS¥N
szBigMul        BYTE            'UBCD_MULS',0   ;´Àubcd_add¡F¥HUBCD_MULS¥N´Àubcd_mul
szDlgName       BYTE            'AddNMul',0
szAdd           BYTE            '¡Ï',0
szMul           BYTE            '¡Ñ',0
szDllLoadFail   BYTE            'UBCDDLL.DLL¸ü¤J¥¢±Ñ¡I',0dh,0ah,'¬Y¨Ç¥\¯àµLªk°õ¦æ¡C',0
szAddFail       BYTE            '¥[ªk¥\¯à¥¢®Ä',0
szMulFail       BYTE            '­¼ªk¥\¯à¥¢®Ä',0
;*******************************************************************************
.DATA
hInstance       HINSTANCE       ?
hModule         HANDLE          0       ;°ÊºA³sµ²µ{¦¡®w(UBCDDLL.DLL)ªº¼Ò²Õ¥N½X
lpAddProc       DWORD           ?       ;UBCD_ADDS°Æµ{¦¡¶i¤JÂI¦ì§}
lpMulProc       UBCD_PROC       ?       ;UBCD_MULS°Æµ{¦¡¶i¤JÂI¦ì§}
index           DWORD           ?       ;³Q¿ï©wªº¹Bºâ¤l¡G¥[ªk¡G¡Ï¡A­¼ªk¡G¡Ñ
ubcdN1          BYTE            MAX_DIGIT+1 DUP (?)
ubcdN2          BYTE            MAX_DIGIT+1 DUP (?)
buffer          BYTE            2*MAX_DIGIT+1 DUP (?)
nN1             DWORD           ?
nN2             DWORD           ?
szAnswer        BYTE            '='
answer          BYTE            2*MAX_DIGIT+1 DUP (?)
;*******************************************************************************
.CODE
;-------------------------------------------------------------------------------
get_number      PROC    USES esi edi hDia:HANDLE,ID:DWORD,adrOperand:DWORD
        LOCAL   szuBcd[MAX_DIGIT+2]:BYTE
        LOCAL   nBcd:DWORD
        INVOKE  GetDlgItemText,hDia,ID,ADDR szuBcd,MAX_DIGIT+1
        mov     nBcd,eax
        mov     ecx,eax
        jecxz   no_n
        lea     esi,szuBcd
        mov     edi,adrOperand
        add     esi,ecx
        dec     esi
        clc
next:   mov     al,[esi]
        and     al,0fh
        dec     esi
        stosb
        loop    next
        mov     eax,ecx
        stosb
        mov     eax,nBcd
no_n:   ret
get_number      ENDP
;-------------------------------------------------------------------------------
DlgProc PROC    hDlg:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
        LOCAL   hOperator:HANDLE
.IF uMsg==WM_INITDIALOG
        ;¸ü¤J¹Ï¥Ü
                INVOKE  LoadIcon,hInstance,OFFSET szDlgName
                INVOKE  SendMessage,hDlg,WM_SETICON,ICON_SMALL,eax
        ;³]©w½s¿è®Ø³Ì¦h¿é¤J¦ì¼Æ
                INVOKE  GetDlgItem,hDlg,IDC_N1
                INVOKE  SendMessage,eax,EM_SETLIMITTEXT,MAX_DIGIT,NULL
                INVOKE  GetDlgItem,hDlg,IDC_N2
                INVOKE  SendMessage,eax,EM_SETLIMITTEXT,MAX_DIGIT,NULL
        ;¨ú±o´_¦X®Ø¥N½X
                INVOKE  GetDlgItem,hDlg,IDC_OP
                mov     hOperator,eax
        ;¨Ï¡y­pºâ¡z«ö¶s¥¢®Ä
                INVOKE  GetDlgItem,hDlg,IDC_CALC
                INVOKE  EnableWindow,eax,FALSE
        ;¸ü¤JUBCDDLL.DLLÀÉ
                INVOKE  LoadLibrary,OFFSET szUBCDDLL
   .IF eax
                mov     hModule,eax
                INVOKE  GetProcAddress,eax,OFFSET szBigAdd
         .IF eax
                mov     lpAddProc,eax
                INVOKE  SendMessage,hOperator,CB_ADDSTRING,NULL,OFFSET szAdd    ;§â¥[ªk¹Bºâ¤l¥[¤J½Æ¦X®ØùØ
                INVOKE  GetDlgItem,hDlg,IDC_CALC                                ;¨Ï¡y­pºâ¡z«ö¶s¥¿±`
                INVOKE  EnableWindow,eax,TRUE
         .ELSE
                INVOKE  MessageBox,hDlg,OFFSET szAddFail,NULL,MB_OK or MB_ICONWARNING
         .ENDIF
                INVOKE  GetProcAddress,hModule,OFFSET szBigMul
         .IF eax
                mov     lpMulProc,eax
                INVOKE  SendMessage,hOperator,CB_ADDSTRING,NULL,OFFSET szMul    ;§â¥[ªk¹Bºâ¤l¥[¤J½Æ¦X®ØùØ
                INVOKE  GetDlgItem,hDlg,IDC_CALC                                ;¨Ï¡y­pºâ¡z«ö¶s¥¿±`
                INVOKE  EnableWindow,eax,TRUE
         .ELSE
                INVOKE  MessageBox,hDlg,OFFSET szMulFail,NULL,MB_OK or MB_ICONWARNING
         .ENDIF
   .ELSE
                INVOKE  MessageBox,hDlg,OFFSET szDllLoadFail,NULL,MB_OK or MB_ICONWARNING
   .ENDIF

.ELSEIF uMsg==WM_COMMAND
                mov     edx,wParam
                mov     eax,wParam
                shr     edx,10h         ;EDX=³qª¾½X
                and     eax,0ffffh      ;EAX=±±¨î¤¸¥óÃѧO½X
   .IF dx==BN_CLICKED
      .IF ax==IDC_EXIT
                jmp     exit
      .ELSEIF ax==IDC_CALC
                INVOKE  get_number,hDlg,IDC_N1,OFFSET ubcdN1
                mov     nN1,eax
                or      eax,eax
                jz      no_input
                INVOKE  get_number,hDlg,IDC_N2,OFFSET ubcdN2
                mov     nN2,eax
                or      eax,eax
                jz      no_input
         .IF WORD PTR index==0cfa1h     ;0cfa1h='¡Ï'
                push    nN2
                push    nN1
                push    OFFSET buffer
                push    OFFSET ubcdN2
                push    OFFSET ubcdN1
                call    lpAddProc
         .ELSEIF WORD PTR index==0d1a1h ;0d1a1h='¡Ñ'
                INVOKE  lpMulProc,OFFSET ubcdN1,OFFSET ubcdN2,OFFSET buffer,nN1,nN2
         .ELSE
                jmp     no_input
         .ENDIF
                mov     edx,OFFSET buffer
                mov     edi,OFFSET answer
                add     edx,ecx
                dec     edx
@@:             mov     al,[edx]
                or      al,'0'
                dec     edx
                stosb
                dec     ecx
                jnz     @b
                mov     al,cl
                stosb
                INVOKE  SetDlgItemText,hDlg,IDC_ANSWER,OFFSET szAnswer
      .ENDIF
   .ELSEIF dx==CBN_SELENDOK
                INVOKE  SendDlgItemMessage,hDlg,IDC_OP,CB_GETCURSEL,0,0
                INVOKE  SendDlgItemMessage,hDlg,IDC_OP,CB_GETLBTEXT,eax,OFFSET index
   .ENDIF
no_input:

.ELSEIF uMsg==WM_CLOSE
exit:    .IF hModule
                INVOKE  FreeLibrary,hModule
         .ENDIF
                INVOKE  EndDialog,hDlg,NULL 

;¨ä¥L°T®§
.ELSE
        mov     eax,FALSE
        ret
.ENDIF
        mov     eax,TRUE
        ret
DlgProc ENDP
;-------------------------------------------------------------------------------
start:  INVOKE  GetModuleHandle,NULL
        mov     hInstance,eax
        INVOKE  DialogBoxParam,hInstance,OFFSET szDlgName,NULL,OFFSET DlgProc,NULL
        INVOKE  ExitProcess,eax
;*******************************************************************************
        END     start

±µµÛ¦b¡y©R¥O´£¥Ü¦r¤¸¡z¤¤¡A¿é¤J¡G

E:\HomePage\SOURCE\DLL>ml test2.asm /link test.res [Enter]
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: test2.asm
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/SUBSYSTEM:WINDOWS
"test2.obj" /DEBUG
"/OUT:test2.exe"
"test.res"

E:\HomePage\SOURCE\DLL>

¦]¬°¬O°õ¦æ®É¤~°ÊºAªº³sµ² ubcddll.dll µ{¦¡®w¡A©Ò¥H³sµ²®É¤£»Ý­n¶×¤Jµ{¦¡®w´£¨Ñ¸ê®Æ¡A¬G­ì©lµ{¦¡¤¤¤]¤£»Ý­n§t¤J¥]§tÀÉ¡A©Ò¥H§â

INCLUDE         UBCDDLL.INC     ;¤p¤ì°¸»s§@ªºUBCDDLL.INC¥]§tÀÉ
INCLUDELIB      UBCDDLL.LIB     ;¤p¤ì°¸»s§@ªºUBCDDLL.DLL°ÊºA³sµ²µ{¦¡®w

¨â¦æµ¹§R±¼¤F¡A°h¤@¨B¨Ó»¡¡A§Y¨ÏºÏºÐùØ¡A¨S¡yUBCDDLL.INC¡z©M¡yUBCDDLL.LIB¡z¤]¨SÃö«Y¡C¦ý¬O¥²¶·¦b¸ê®Æ¬qùئۦæ©w¸q°ÊºA³sµ²µ{¦¡®wªºÀɦW¥H¤Î°Æµ{¦¡¦WºÙ¡G

szUBCDDLL       BYTE            'UBCDDLL.DLL',0
szBigAdd        BYTE            'UBCD_ADDS',0
szBigMul        BYTE            'UBCD_MULS',0

·íµ{¦¡¥H LoadLibrary ¸ü¤J UBCDDLL.DLL «á¡A¤p¤ì°¸Àˬd¤F¶Ç¦^­È¬O§_¬° NULL¡A¦pªG¬Oªº¸Ü¡A·|¦b¿Ã¹õ¤W¥X²{

¦ý¤£·|²×¤îµ{¦¡¡AÁÙ¬O¯à¿é¤J¼Æ¦r¡C°²¦p±z§â UBCDDLL.DEF ¤¤ªº¶×¥X°Æµ{¦¡§R°£¤@­Ó¡AÅܦ¨¡G

EXPORTS
        UBCD_MULS=ubcd_mul

¨Ì«eªk²ÕĶ³sµ²«á¡A°õ¦æ TEST.EXE¡A·|¥X²{¤U­±ªº¹ï¸Ü²°¡A·í«ö¤U½T©w«á¡Aµ{¦¡¥ß§Y²×¤î¡C

¦ý¬O¦pªG°õ¦æ TEST2.EXE¡A¤]·|¥X²{¤@­Ó¹ï¸Ü²°¡A¦p¤U¹Ï¥ª¡A§i¶D¨Ï¥ÎªÌ¡A¶È¶È¥[ªk¥¢®Ä¡A«ö¤U½T©w«á¡Aµ{¦¡¤´Ä~Äò°õ¦æ¡A­¼ªk¥\¯àÁÙ¬O¦³®Ä¡A¦p¤U¹Ï¥k¡C

¡@

¦b TEST2.ASM ùØ¡A¦]¬°¥²¶·¦Ò¼{¥|ºØ±¡§Î¡G¥i¯à¥[ªk¥\¯à¥¢®Ä¦Ó­¼ªk¥\¯à¥¿±`¡A¤]¥i¯à¤Ï¹L¨Ó­¼ªk¥\¯à¥¢®Ä¦Ó¥[ªk¥\¯à¥¿±`¡A©Î¨âªÌ³£¥¿±`©Î³£¥¢®Ä¡C©Ò¥H¤p¤ì°¸¤£¬O¥HÀˬd index ¤§¼Æ­È¨Ó§PÂ_¨Ï¥ÎªÌ¿ï¾Ü¥[ªkÁÙ¬O­¼ªk¡A¦Ó¬OÀˬd¡y¦r¤¸¡z¬°¡y¡Ï¡zªí¥Ü¨Ï¥ÎªÌ¿ï¾Ü¥[ªk¹Bºâ¡A¡y¡Ñ¡zªí¥Ü­¼ªk¹Bºâ¡C±ý¨ú±o¨Ï¥ÎªÌ¦b½Æ¦X®Ø¤¤ªº½s¿è®Ø©Ò¿ï©wªº¤º®e¦r¦ê¤èªk¬O¡A¦b³B²z CBN_SELENDOK ³qª¾½Xªº®É­Ô¡A¥ýÀò±o¨Ï¥ÎªÌ¿ï©wªº¶µ¥Ø¯Á¤Þ ( ¤]´N¬O¨Ï¥ÎªÌ¿ï©w¤F²M³æ¤ºªº²Ä´X­Ó¶µ¥Ø ( ¥Ñ¹s¶}©l ) )¡A¦A¥Ñ¦¹¶µ¥Ø¯Á¤Þ¶Ç¦^¦r¦ê¡A¤èªk¦p¤U¡G

   .ELSEIF dx==CBN_SELENDOK
                INVOKE  SendDlgItemMessage,hDlg,IDC_OP,CB_GETCURSEL,0,0
                INVOKE  SendDlgItemMessage,hDlg,IDC_OP,CB_GETLBTEXT,eax,OFFSET index

©Ò¥H¦b TEST2.ASM ùتº index¡A¨ä¹ê¬O¤@­ÓÂù¦ì¤¸²Õªº¦r¦ê¡A¥Nªí¡y¡Ï¡z©Î¡y¡Ñ¡z¡A³oÂI»P TEST.ASM ¤£¦P¡C


DUMPBIN.EXE

°²¦p±z±qºô»Úºô¸ô¤W¤U¸ü¤F¤@­Ó°ÊºA³sµ²µ{¦¡®w¡A·QÆ[¹î¥¦¦³­þ¨Ç°Æµ{¦¡¥i¥H³Q¥Dµ{¦¡©I¥s¡A¥i¥H¨Ï¥Î DUMPBIN.EXE¡C¥¦¬O¤@­Ó¤G¶i¦ìÀɮ׶ɦL¤u¨ã¡A¥i¥HÆ[¹î COFF ®æ¦¡ªº¥ØªºÀÉ¡BCOFF ª«¥óªº¼Ð·Çµ{¦¡®w¡B¥i°õ¦æÀÉ¡A©M°ÊºA³sµ²µ{¦¡®w (DLL)¡CDUMPBIN.EXE ¥i¥H¦b MASM32\BIN ¤l¥Ø¿ýùاä¨ì¡C

DUMPBIN ¥u¯à¦b¡y©R¥O´£¥Ü¦r¤¸¡z¤¤°õ¦æ¡A¨ä¥Îªk¬O¡G

DUMPBIN ¿ï¶µ ÀɦW

¤W¦¡¤¤ªº¡y¿ï¶µ¡z¥i¥H¤£¥u¨Ï¥Î¤@­Ó¡A¨C¤@­Ó¿ï¶µ³£¥H¡y/¡z©Î¡y-¡z¶}©l¡A°²¦p­n¬d¬Ý DLL ÀÉùØ­±­þ¨Ç°Æµ{¦¡¥i¥H³Q©I¥s¡A¥i¥H¥Î¡y/exports¡z¿ï¶µ¡C©³¤Uªº¨Ò¤l¬O¬d¬Ý UBCDDLL.DLL ùئ³­þ¨Ç°Æµ{¦¡¥i¨Ñ¨ä¥Lµ{¦¡©I¥s¡G

E:\HomePage\SOURCE\DLL>c:\masm32\bin\dumpbin /exports ubcddll.dll [Enter]

E:\HomePage\SOURCE\DLL>Microsoft (R) COFF Binary File Dumper Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file ubcddll.dll

File Type: DLL

  Section contains the following exports for ubcddll.dll

           0 characteristics
    4C95C7A6 time date stamp Sun Sep 19 16:19:50 2010
        0.00 version
           1 ordinal base
           2 number of functions
           2 number of names

    ordinal hint RVA      name

          1    0 0000100C UBCD_ADDS
          2    1 00001074 UBCD_MULS

  Summary

        1000 .rdata
        1000 .reloc
        1000 .text

E:\HomePage\SOURCE\DLL>

¤W­±ªº¡yordinal hint RVA name¡zªí®æ¤¤ªº¡yname¡zÄæ¦ì§i¶D§Ú­Ì³o­Ó DLL ÀÉ®×¥]§t¤F­þ¨Ç°Æµ{¦¡¡C¡yRVA¡z¬O¡yRelative Virtual Address¡zªºÁY¼g¡A¥ç§Y¬Û¹ïµêÀÀ¦ì§}¡A±q 1000H ¶}©l¡A¦]¬° UBCDDLL.ASM ªº DLLEntry ¥Î¥h¤F 0CH ¦ì¤¸²Õ¡A¬G UBCD_ADDS ¬O±q 100CH ¶}©l¡C¦Ó DLLEntry ¤£³Q¨ä¥Lµ{¦¡©I¥s¡A¨Ã¨S¦³¦C¦b¼Ò²Õ©w¸qÀɪº¡yEXPORTS¡z¬q¸¨¤º¡A©Ò¥H¦¹³B¤£·|³Q¦C¥X¨Ó¡C¡yhint¡z¬O°Æµ{¦¡¦b name Äæ¦ìªº¦ì¸m¡A¥Ñ¹s¶}©l»¼¼W¡C¡yordinal¡z¬O§Ç¸¹¡A¥i¥H¦b¼Ò²Õ©w¸qÀɪº¡yEXPORTS¡z¬q¸¨¤ºªº¶µ¥Ø¤¤«ü©w¡A¤]¥i¥H¤£«ü©w¡A¥i¥H¥H§Ç¸¹¥N´À°Æµ{¦¡¦WºÙ¨Ó©I¥s°Æµ{¦¡¡C

°²¦p±z·Q¬Ý¬Ýµ{¦¡©I¥s¤F­þ¨Ç°Æµ{¦¡¡A¤]¥i¥H¥Î DUMPBIN¡A¦¹®É¨Ï¥Î¡y/IMPORTS¡z¿ï¶µ¡C©³¤U¬O¹î¬Ý TEST.EXE ©I¥s¤F­þ¨Ç°Æµ{¦¡¡A¦Ó³o¨Ç°Æµ{¦¡¤S¥]§t¦b­þ¨Ç°ÊºA³sµ²µ{¦¡®wùØ¡C

E:\HomePage\SOURCE\DLL>c:\masm32\bin\dumpbin /imports test.exe [Enter]

E:\HomePage\SOURCE\DLL>Microsoft (R) COFF Binary File Dumper Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file test.exe

File Type: EXECUTABLE IMAGE

  Section contains the following imports:

    USER32.dll
                40513C Import Address Table
                405084 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                 19B  LoadIconA
                 100  GetDlgItem
                 210  SendMessageA
                 228  SetDlgItemTextA
                  B8  EndDialog
                 20B  SendDlgItemMessageA
                 102  GetDlgItemTextA
                  92  DialogBoxParamA

    KERNEL32.dll
                405108 Import Address Table
                405050 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                  75  ExitProcess
                 111  GetModuleHandleA

    ubcddll.dll
                40518C Import Address Table
                4050D4 Import Name Table
                     0 time date stamp
                     0 Index of first forwarder reference

                   1  UBCD_MULS
                   0  UBCD_ADDS

  Summary

        1000 .data
        1000 .idata
        1000 .rdata
        1000 .reloc
        1000 .rsrc
        2000 .text

E:\HomePage\SOURCE\DLL>

¨ì²Ä¤Q¤E³¹¡A ¦^¨ì­º­¶¡A ¨ì²Ä¤G¤Q¤@³¹