16. ActiveX ¤¸¥ó
COM ²¤¶
¡@
µ§ªÌ¤£·Q²`¤J¤¶²ÐÃö©ó COM ªº§Þ¥©¡A¦ý¬On¤F¸Ñ Visual Basic ¦b¦¹»â°ìªº¼ç¯à¡A±z¦Ü¤Ö»Ýn¤F¸Ñ¤@¨Ç¥Dnªº·§©À¡C
ªø¸Üµu»¡
¡@
·í Microsoft ¶}©lµo°â Windows ®É¡A¥¦¦¨¬°²Ä¤@ºØ¥i¥H¦b¦P¤@®É¶¡¤º°õ¦æ¦h«À³¥Îµ{¦¡ªº§@·~¨t²Î¡A¨CÓ¤H³£¤F¸Ñ Microsoft »Ýn³]p¤@Ó¥i¥H¦bÀ³¥Îµ{¦¡¤§¶¡¥æ´«¸ê®Æ©M·¾³qªº¨t²Î¡AClipboard ¾A¦X±q¨Æ¦¹Â²³æªº°Å¶K¡]cut-and-paste¡^°Ê§@¡A¦ý¬O Clipboard ¤Ó¹L©ó²³æ¦ÓµLªk³B²z Microsoft ¥Ø«e©Ò´£¥X¤j³¡¤ÀÄYVªº»Ý¨D¡C
¥H¦¹¬°ì«h¡A²Ä¤@Ó«n¹Á¸Õ´N¬O°ÊºA¸ê®Æ¥æ´«¡]DDE¡^¡A¤@ÓÅýÀ³¥Îµ{¦¡¤§¶¡¤¬¬Û©I¥sªº¨ó©w¡ADDE ¨Ã¤£¬O«D±`ªº¦¨¥\¡A¥i¯à¦b©ó¨ä¯Ê¥F¥i¾a«×¡CÁöµM DDE ÂX®i¦¨¬°¥i¤u§@©ó°Ï°ìºô¸ô¡]Network DDE¡^¡A¦Ó¥i¥H³sµ²¤£¦P¤u§@¯¸ªºÀ³¥Îµ{¦¡¡A¦ý¬O¥u¦³¤Ö¼Æªº Windows À³¥Îµ{¦¡¹ê§@³oÓ¥\¯à¡C¡]Visual Basic¹ï©ó DDE ´£¨Ñ¦³ªº¤ä´©¡A¦ý¬Oµ§ªÌ¨S¦³±N¨ä¥]§t¦b¦¹®Ñ¤¤¡C¡^
¤ä´© Windows 3.1 ªº²Ä¤@Ó OLE¡]Object Linking and Embedding¡^ª©¥»©l©ó 1992 ¦~¨Ã¥B§Q¥Î DDE §@¬°À³¥Îµ{¦¡¤§¶¡¬Û¤¬³q°Tªº°ò¦¡COLE ¬O²Ä¤@Ó¥i¥HÅý¨Ï¥ÎªÌ¥H¤Îµ{¦¡³]p¤Hû«Ø¥ß½Æ¦X¤å¥ó¡]compound documents¡^ªº¨ó©w¡A½Æ¦X¤å¥ó´N¬O¤å¥ó¤¤¥]§t¤£¦PÀ³¥Îµ{¦¡ªº¸ê®Æ®æ¦¡¡]Á|¨Ò¨Ó»¡¡AWord ¤å¥ó¥]§t¤F Excel ¤u§@ªí¡^¡C¨Ì·ÓÀ³¥Îµ{¦¡ªº»Ý¨D¦Ó©w¡A½Æ¦X¤å¥ó¥i¥H§¹¾ãªº¥]§t¨ä¥L²³æªº¤å¥ó¡]¤º´O Embedding¡^¡A©Î¬O³æ¯Âªº¥]§t¤w¦s¦b¤å¥óªºÃöÁp¡]³sµ² Linking¡^¡C·í¨Ï¥ÎªÌÂI¨ú½Æ¦X¤å¥ó¤¤´O¤J©Î¬O³sµ²ªº¤å¥ó¡AWindows ´N·|°õ¦æ¦³¯à¤O³B²z¦¹¯S®í¤å¥óªºÀ³¥Îµ{¦¡¡C
OLE2 µoªí©ó 1993 ¦~¡A¬O²Ä¤@¦¸¥]§t¤F¹ï©Ò¦b¦ì¸m±Ò°Ê¡]in-place activation¡^ªº¤ä´©¡A´N¬Oµ¹¤©¨Ï¥ÎªÌ¥i¥H¤£¥Î¶}±Ò¥t¤@ Windows ´N¥i¥H½s¿è½Æ¦X¤å¥óªº¯à¤O¡CÁ|¨Ò¨Ó»¡¡AOLE2 ¨Ï±z¥i¥H¤£nÂ÷¶} word ªºÀô¹Ò¦Ó½s¿è¦b word ¤å¥ó¤¤ªº excel ¤u§@ªí¡C¦ý¬O±z¥u¯à¬Ý¨ì excel ªº¥\¯àªí¡A·í±z½s¿è´O¤J¦¡¸ê®Æªº®ÉÔ¡Aexcel ªº¥\¯àªí¥N´À¤F word ªº¥\¯àªí¡COLE2 ¬O¤@Ó«nªº¶¥¬q¡A¦]¬° OLE2 ¥Nªí¤F©ñ±ó¥H DDE §@¬°³q°T¨ó©w¦Óʾa¤@Ó¥H¤¸¥ó¬°°ò¦ªº·s¬[ºc¡G¤¸¥óª«¥ó¼Ò«¬¡]COM¡GComponent Object Model¡^¡C
¶V¨Ó¶V©úÅã¦a¡ACOM ªº°ò¦¬[ºc¤ñ³sµ²¥H¤Î´O¤Jªº§Þ³N¨Óªº«n¡C¥H¨Ï¥ÎªÌªºÆ[ÂI¨Ó¬Ý¡A·í«Ø¥ß½Æ¦X¤å¥óªº¯à¤O¤é¯q±j¤j®É¡A¶}µoªÌµo²{¥LÌ¥un§Q¥Î COM ´N¥i¥H¶}µo¤j«¬À³¥Îµ{¦¡¡C¨Æ¹ê¤W¡ACOM «P¶i¤F¥H¤¸¥ó¬°°ò¦ªº¶}µoÆ[©À¡A¨Ï±z±N¤j«¬À³¥Îµ{¦¡¤À³Î¦¨¸û¤pªº³æ¦ì¡AÅý±z¦bºûÅ@¥H¤Î³¡¸p³o¨Ç¤p³æ¦ìªº¤¸¥ó¤W¤ñ°_¾ãÓ¤j«¬À³¥Îµ{¦¡®e©ö¡COLE ¤¤Åýµ{¦¡¶¡¤¬¬Û³q°Tªº³¡¤À´N¬O OLE Automation¡C³\¦hµ{¦¡»y¨¥¥i¥H¥H OLE Automation «È¤áºÝªº¨¤À¡A±±¨î¨ä¥L§@¬° OLE Automation ¦øªA¾¹ªºÀ³¥Îµ{¦¡¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H¦b Visual Basic 3 ©Î¬O¤§«áªºª©¥»¤§¥~¡A§Q¥Î VBScript ¨Ó±±¨î Excel ¥H¤Î Word¡C
³oÓ·sµ{¦¡³]p¨å½dªº¼ç¤O¡A¦b Microsoft µo¦æ Visual Basic 4 ¥ø·~ª©«á¡AÅܪº§ó¬°©úÅã¡CVisual Basic 4 ¥ø·~ª©¤¤¥]§t¤F¹ï Remote Automation ªº¤ä´©¡CVisual Basic µ{¦¡³]p¤Hû³Ì«á¤£¶Èn«Ø¥ß COM ¤¸¥ó¡A¨Ã¥B¤]¬O³z¹Lºô¸ô¤Wªº ¹q¸£¡]¨Ï¥Î¨ä CPU¡B°O¾ÐÅé¥H¤Î¨ä¥L¸ê·½¡^©R¥O¥H¤Î°õ¦æ¤¸¥óªº¥ýÅXªÌ¡C¦¹®É¤À´²¦¡¹Bºâªì¦¸¦b Windows ¥¥x¤WÅS±¡C
¦b Visual Basic 4 µo¦æ®É¡A¥t¤@ºØ¤¸¥óªºÃþ«¬ªì¦¸¥X²{¡ROLE ±±¨î¶µ¡]OLE controls¡^¡C³o¬O VBX ±±¨î¶µªºÄ~©ÓªÌ¡AVBX ±±¨î¶µ¹ï Visual Basic ªº´¶¤Î¦³«Ü¤jªº§U¯q¡CVBX ±±¨î¶µªº°ÝÃD¦b©ó¨ä¿W¦³ªº¬[ºc¡B©R¦W¤è¦¡¡B¥H¤Î Visual Basic ªºÀô¹Ò¡A¨Ï±o VBX ±±¨î¶µ´X¥G¤£¯à³Q¨ä¥Lªºµ{¦¡»y¨¥©Ò¨Ï¥Î¡C·íÂà´«¨ì 32 ¦ì¤¸¥¥x®É¡AMicrosoft ¨M©w«Ø¥ß¤@Ó¥H¥i¥H³Q¨ä¥L¼t°Ó±Ä¯Ç¥H¤Î¤ä´©¡A¨Ã¥B¥H OLE ¬°°ò¦ªº·s«¬ºAªº±±¨î¶µ¡C
Remote Automation ¥u¬O¤U¤@Ó§Þ³N¡Ð¤]´N¬O¤À´²¦¡ COM¡B©Î¬O²ºÙ DCOM¡Aªº´ú¸Õ¹Lµ{¡CDCOM ¦b 1996 ¦~ÀHµÛ Microsoft Windows NT 4.0 ¥¿¦¡µo¦æ¡A³\¦hµ{¦¡³]p¤HûÄ~Äò¨Ï¥Î¤F Remote Automation ¤@¬q®É¶¡¡Aª½¨ì 1997 ¦~ Microsoft µo¦æ DCOM95.EXE¡A³o¬O¤@Ó¼W¥[¦b Windows 95 ¤W¤ä´© DCOM ªºµ{¦¡¡CDCOM ÃÒ©ú¤F¤ñ Remote Automation §ó¦³®Ä²v©Méw¡A¦Ó Microsoft ¤£¦A×q Remote Automation ªºª©¥»¡CRemote Automation °ß¤@ªºªø³B´N¬O¤ä´© 16 ¦ì¤¸ªº¥¥x¡C´«¥y¸Ü»¡¡A¦pªG±z¥¿¦b§Q¥Î Visual Basic 5 ¥H¤Î 6 µo®iÀ³¥Îµ{¦¡¡A±z¤º©wªº©w§}¼Ò¦¡¥u¦³ 32 ¦ì¤¸ªº¥¥x¡A±z±N¤£¯à¦b¨Ï¥Î Remote Automation¡C
Microsoft ¹êÅç«Çµo¦æªº³Ì·sªº¤@Ó§Þ³N´N¬O ActiveX¡C¦b¬YºØ·N¸q¤W¡AActiveX ´N¬O Microsoft ¹ï©óºô»Úºô¸ô·s¬D¾Ôªº¤@Óµª®×¡CÁ|¨Ò¨Ó»¡¡AOLE ±±¨î¶µ¤Ó¥¨¤j¥H¦Ü©óµLªk¦bºô¸ô¤W¶Ç»¼¡A©Ò¥H Microsoft »Ýn³]p¤@ºØ·sªº±±¨î¶µ¡C¦p¤µ¡AActiveX ¦¨¬°¤@ºØ OLE ªº¦P¸qµü¡A¨Ã¥B±z¥i¥H§â COM ¤¸¥óµø¬° ActiveX ¤¸¥ó¡C¦ñÀHµÛ ActiveX ªº¥X²{¡AOLE Automation ¤]§ï¦W²ºÙ¬°Automation¡CActiveX ¹ï©ó¤£Â_¦¨ªøªº¶}µoªÌ¦r¨å¤]´£¥X¤F·sªº¦Wµü¡GActiveX ±±¨î¶µ¥H¤ÎActiveX ¤å¥ó¡CActiveX ±±¨î¶µ¤w¸g¨ú¥N¤F OLE ±±¨î¶µ¡A¦P®É ActiveX ¤å¥ó¤]¤w¸g¨ú¥N¤F OLE ¤å¥ó¨Ã¥B¤¹³\µ{¦¡³]p¤Hû¦b¦¬¯Ç¾¹¤¤¡]Á|¨Ò¨Ó»¡¡AMicrosoft Internet Explore¡^«Ø¥ß ActiveX ¤å¥ó¡CVisual Basic 5 ¥H¤Î 6 ¥i¥H«Ø¥ß ActiveX ±±¨î¶µ¥H¤Î¤å¥ó¡C
COM ¤¸¥óªºÃþ«¬
¡@
±z¥i¥H¨Ì¾Úµ{¦¡°õ¦æªº¦aÂI¡A±N COM µ{¦¡½X¤¸¥ó¤À¦¨¤TºØÃþ«¬¡C
In-process ¦øªA¾¹¡]DLL¡^
¡@
COM ¤¸¥ó¤¤³Ì²³æªºÃþ«¬´N¬O»P¨Ï¥Î¤¸¥óªºÀ³¥Îµ{¦¡¦ì©ó¦P¤@¦ì§}ªÅ¶¡ªº DLL¡C¦]¬°¦b 32 ¦ì¤¸ªº¥¥x¤W¨CÓ³B²z§Ç¡]process¡^¦³¦Û¤vªº¦ì§}ªÅ¶¡¡A©Ò¥H¨CÓ³B²z§Çt³d³B²z¤¸¥óªº¤£¦P°õ¦æÓÅé¡C³o¨Ç¤¸¥ó¨Ã¨S¦³³z¹L COM ªºÀ°§U¦Óª½±µ»P«È¤áºÝÁpô¡A¦]¦¹·í³t«×¬°«nªº¦]¯À®É¡A¥¦Ì¬O³Ì¾A·íªº¿ï¾Ü¡C¥¦Ìªº¥Dn¯ÊÂI´N¬O«È¤áºÝ¹ï©ó¦øªAºÝªº¬G»Ù¨S¦³¨¾Å@¡C¦pªG¤¸¥óµo¥ÍP©Rªº¿ù»~¡A¨ä«È¤áºÝ±N·|·´·l¡C
ActiveX ±±¨î¶µ¬O¥i¥H³Q ActiveX ¦¬¯Ç¾¹¡]¦p Visual Basic ªºªí³æ¡^¥]®eªº¤@ºØ¦p¦P³B²z§Ç¤¸¥óªººØÃþ¡Cn²Å¦X ActiveX ±±¨î¶µªº³W®æ¡A¤¸¥ó¥²¶·¹ê§@¥X ActiveX ³W®æ©Òq©wªº´XÓ¤¶±¡CµM¦Ó¡A¨¬° Visual Basic ªºµ{¦¡³]p¤Hû¡A±z¤£»Ýn¾á¤ß³o¨Çªþ¥[ªº¤¶±¡A¦]¬° Visual Basic ¬°±z°µ¦n¤F©Ò¦³ªº¨Æ±¡¡C²Ä¤Q¤C³¹±N±ÔzActiveX ±±¨î¶µ¡C
¥»¾÷ out-of-process ¦øªA¾¹¡]EXE¡^
¡@
±z¤]¥i¥H±N ActiveX ¤¸¥ó½sĶ¦¨¤@Ó EXE ªºµ{¦¡¡C·í±z·Qn«Ø¥ß¤@Ó¿W¥ß§@·~ªºÀ³¥Îµ{¦¡¨Ã¥B¥i¥H¦P®É´£¨Ñ¥~¬É¤@Ó¥iµ{¦¡¤Æªºª«¥ó®É¡A±N¤¸¥ó½sĶ¦¨ EXE µ{¦¡¬O¦X©yªº¡C³oºØ¦øªA¾¹³Ì¦nªº¨Ò¤l´N¬O Microsoft Office ¨t¦C¡G±z¥i¥H¿W¥ß¨Ï¥Î Excel ©Î Word À³¥Îµ{¦¡¡F©Î¬O¦b±zªºÀ³¥Îµ{¦¡¤¤¡A±N¥¦Ì·í§@¬O¤¸¥óªº´£¨ÑªÌ¡CEXE ¦øªA¾¹¦b¦Û¤vªº¦ì§}ªÅ¶¡¤¤°õ¦æ¡A¦p¦¹¨Ï±o»P¥¦Ìªº«È¤áºÝÁpôªº³t«×¤ñ°_¦P³B²z§Ç¤¸¥ó¡]In-process component¡^ºC¡C¥t¤@¤è±¡AActiveX EXE ¦øªA¾¹¸û¦P³B²z§Ç¦øªA¾¹¡]In-process server¡^¦w¥þ¤@ÂI¡C¦pªG¦³¤@Ó¤¸¥ó·´·l¡A«È¤áºÝªºÀ³¥Îµ{¦¡³q±`¥i¥H´_ì¡C
»·ºÝ out-of-process ¦øªA¾¹¡]EXE¡^
¡@
»·ºÝ¦øªA¾¹¬O¤@Ó¤£¦b«È¤áºÝÀ³¥Îµ{¦¡ªº¹q¸£¤W°õ¦æªº EXE µ{¦¡¡C«È¤áºÝ»P¦øªA¾¹³z¹L DCOM¡]©Î¬O Remote Automation¡^°µÁpô¡C¤£¥Î»¡¡A¥¦Ì¤§¶¡Ápôªº³t«×¤ñ¥»¾÷¦øªA¾¹ÁÙnºC¡A¦ý¬O»·ºÝ¤¸¥ó´£¨Ñ«Ø¥ß¯u¹ê¤À´²¦¡À³¥Îµ{¦¡ªº¯à¤O¡C¤@Ó°õ¦æ¦b»·ºÝ¹q¸£ªº»·ºÝ¦øªA¾¹µ{¦¡¤£·|®¿¥h«È¤áºÝÀ³¥Îµ{¦¡ªº CPU ®É¶¡¥H¤Î°O¾ÐÅéªÅ¶¡¡A¦]¦¹±z¥i¥H±N½ÆÂøªºµ{¦¡¤À´²¨ì±zºô¸ô¤Wªº©Ò¦³¹q¸£¤W¡C§ó¶i¤@¨B¦a¡A¦pªG±z»Ýn§¹¦¨¤@¶µ¯Ó¶Oºô¸ô¤W¬Y¥x¹q¸£¸ê·½ªº¤u§@¡]Á|¨Ò¨Ó»¡¡A¤@Ó½ÆÂøªº¸ê®Æ®w¬d¸ß©Î¬O¤@Ó¤¹ªøªº¦C¦L¤u§@¡^¡A±N¤u§@©e°Uµ¹¹ê»Ú¤W¸ê·½©Ò¦bªº¹q¸£ªº»·ºÝ¤¸¥ó¥h°õ¦æ¬O§ó¤è«K¾A¦Xªº¡C
»·ºÝ¦øªA¾¹ªº¤@Ó¦n³B´N¬O¥¦Ì©M¥»¾÷ EXE ¦øªA¾¹§¹¥þ¤@¼Ë¡C¨Æ¹ê¤W¡A¦P¤@Ó¦øªA¾¹¥i¥H´£¨ÑªA°Èµ¹¥»¾÷¹q¸£ªºÀ³¥Îµ{¦¡¡]¦p¦¹¥H¥»¾÷¦øªA¾¹Ãþ«¬¤u§@¡^¡A¤]¥i¥H´£¨ÑªA°Èµ¹°õ¦æ¦b»·ºÝ¹q¸£ªºÀ³¥Îµ{¦¡¡]¦p¦¹¥H»·ºÝ¦øªA¾¹¤u§@¡^¡C
±z¤]¥i¥H§â DLL ·í§@»·ºÝ¦øªA¾¹¨Ó°õ¦æ¡Cn¤¹³\ DLL ¦s¦b©ó¤@Ó¿W¥ßªº¥Í©R¶g´Á¡A±z»Ýn½T©w DLL ¬O±H±J¦b»·ºÝ¹q¸£ªº DLL ¥N²z³B²z§Ç¤¤¡]DLL surrogate process¡^¡C³o¬O¨Ì¾Ú¥H Microsoft Transaction Server ¬°°ò¦ªº¤¸¥ó©Ò©wªºì«h¡Cµ§ªÌ¤]¨S¦³¦b¦¹®Ñ¤¤²[»\ MTS ªºµ{¦¡³]p¡C
¨Ï¥Î¬J¦³ªº¤¸¥ó
¡@
¬°¤FÅý±zÅéÅç¨ì¥H¤¸¥ó¬°°ò¦ªºµ{¦¡³]pªº«Â¤O¡Aµ§ªÌ±N·|Åý±zª¾¹D¦b Visual Basic ¤¤¥[¤J¤@Ó«÷¦rÀˬd¥\¯à¬O¤@¥ó«Ü²³æªº¨Æ¡Cµo®i¤@Ó«÷¦rÀˬdªºµ{¦¡¤£¬O¤@¥ó´¶³qªº¤u§@¡A³o¥i¯ànªá¤W±z¼ÆӤ몺®É¶¡¡C«Ü©¯¹B¦a¡AMicrosoft Word ¤w¸g¥]§t¤F¤@ӫܦnªº«÷¦rÀˬd¤¸¥ó¡A¨Ã¥B§ó«nªº¬O¡AWord ³z¹L Automation ±NÀˬd¤¸¥ó´£¨Ñ¥X¨Ó¡A´N¦p¦P¤@Ó¥iµ{¦¡¤Æªºª«¥ó¤@¯ë¡C±z©Òn°µªº´N¬O§Q¥Î¦¹¶µ¥\¯à¨Ã¥B§Q¥Î Word ¬°¦øªA¾¹«Ø¥ß¤@ÓÀ³¥Îµ{¦¡¡C
n¨Ï¥Î¥ô¦ó Automation ¤¸¥óº¥ýn°µªº´N¬O¦b ³]©w¤Þ¥Î¶µ¥Ø¹ï¸Ü¤è¶ô ¤¤¥[¤J¤@Ó ¤Þ¥Î¶µ¥Ø ¦Ü ª«¥óµ{¦¡®w ¤¤¡A±z¥i¥H±q ±M®× ¥\¯àªí¤¤§ä¨ì¦¹¥\¯à¡CÂsÄý ¥i¤Þ¥Î¶µ¥Ø ªº²M³æ¡A¨Ã¥B®Ö¨ú Microsoft Word 8.0 Object library ¡C¡]³oÓ¨Ò¤l°²³]±z¤w¸g¦b±zªº¹q¸£¤¤¦w¸Ë¤F Word 97¡C¡^¦b±z°µ¦n¦¹¨BÆJ«á¡A±z¥i¥H§Q¥Î ÂsÄýª«¥ó ¨ÓÀ˵ø©Ò¦³ Word ª«¥óµ{¦¡®w¤¤ªºª«¥ó¡A¦pªG±z¦w¸Ë¤F VBAWRD8.hlp ÀɮסA±z¬Æ¦Ü¥i¥H¬d¸ßÃö©ó¯S©wÄݩʩάO¤èªkªº¬ÛÃö»¡©ú©Î¬O¸ê°T¡C¡]¨£¹Ï16-1¡^¡C
¡@
¹Ï16-1 ®Ö¨ú Microsoft Word 8.0 Object library ªº¡u¤Þ¥Î¶µ¥Ø¹ï¸Ü¤è¶ô¡v¥H¤ÎÅã¥Üª«¥óµ{¦¡®w¤º®eªºÂsÄýª«¥ó¹ï¸Ü¤è¶ô¡C |
±z¬Æ¦Ü¥i¥H¤£¥Î¥[¤J¤Þ¥Î¶µ¥Ø¦Üª«¥óµ{¦¡®w¤¤´N¥i¥HÅý±zªº±M®×¦p Automation «È¤áºÝ¤@¼Ë¦a¤u§@¡A¦¹®É¡A«Ø¥ßª«¥ó¥²¶·§Q¥Î CerateObject ¨ç¼Æ¥N´À New ÃöÁä¦r¡C¨Ã¥B±z¥²¶·±Nª«¥ó¤Þ¥Î¡]Object Reference¡^Àx¦s¦b¤@¯ëªº As Object ª«¥óÅܼƤW¦Ó¤£nÀx¦s¦b¯S©wªºª«¥óÅܼƤW¡A³oªí¥Ü±z¥u¯à¨Ï¥Î¸û¨S¦³®Ä²vªº±ß´Á³sµ²¡]late binding¡^¥N´À¦´Á³sµ²¡]early binding¡^¡C©Ò¦³§Q¥Î Visual Basic 3 ©Î¬O VBScript ¼gªº«È¤áºÝµ{¦¡¥u¯à³z¹L¦¹¤èªk¦s¨ú Automation ¦øªA¾¹ ¡C
·í±z¤w¸g¥[¤J¤@Ó¤Þ¥Î¦Ü Word ª«¥óµ{¦¡®w¤¤¡A³oÓª«¥ó´N¦p¦P¦b±M®×¤¤¡A±z«K¥i¥H¶i¦æ±zªºÀ³¥Îµ{¦¡¶}µo¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H«Å§i¤@Óª«¥óÅܼƨåB¦b±z¥Dnªºªí³æ¸ü¤J®É«Ø¥ß¤@Ó·sªº Word.Application ª«¥óªº°õ¦æÓÅé¡R
Dim MSWord As Word.Application Private Sub form_Load() 'Create the instance of Word that will be used later. Set MSWord=New Word.Application End Sub
·í¤@Ó Word ª«¥óµ{¦¡®wªºª«¥ó«Ø¥ß®É¡AWord À³¥Îµ{¦¡¥»¨¬O¤£¥i¨£ªº¡C³o¼ËÅý±zªº¨Ï¥ÎªÌ¦b¨Ï¥Îª«¥ó®É¬Æ¦Ü¤£·|¹îı¨ì±z¬O¨Ï¥Î¥~¦bªºª«¥óµ{¦¡®w¡CµM¦Ó¡A¦pªG±z·Qnªº¸Ü¡A¤´¥i¥HÅý Word ¬O¥i¨£ªº¡G
MSWord.Visible=True
µM¦Ó¡A¦bµ§ªÌ·Ç³Æ¦nªº½d¨Òµ{¦¡¤¤¡A¨Ï¥Î¤F Microsoft Word¡A¤£¹L¦b¨Ï¥ÎªÌ«eÁôÂð_¨Ó¡C
¹Ï 16-2 Åã¥Ü¤F¨Ï¥ÎªÌ¹ê»Ú¬Ý¨ìªºµe±¡C¥Dnªºµ{§Ç´N¬O¹ê»Ú¤W§¹¦¨«÷¦rÀˬdªº¨º¤@¬q¡A¦pªGÀˬd¥X¦³¦r·J¤£¥¿½T¡A±Nn¸m´«ªº«Øij¦r·J²M³æ¦C¦b ListBox ±±¨î¶µ¤¤¡CPrivate Sub cmdCheck_Click() Dim text As String Dim suggestion As Word.SpellingSuggestion Dim colSuggestions As Word.SpellingSuggestions ' Add a document if there aren't any (needed to get suggestions). If MSWord.Documents.Count = 0 Then MSWord.Documents.Add text = Trim$(txtWord.text) lstSuggestions.Clear If MSWord.CheckSpelling(text) Then ' The word is correct. lstSuggestions.AddItem "(correct)" Else ' The word is incorrect. Get the list of suggested words. Set colSuggestions = MSWord.GetSpellingSuggestions(text) If colSuggestions.Count = 0 Then lstSuggestions.AddItem "(no suggestions)" Else For Each suggestion In colSuggestions lstSuggestions.AddItem suggestion.Name Next End If End If End Sub
¹Ï16-2 ¤@ӨϥΠMicrosoft Word §@«÷¦rÀˬdªº½d¨Ò |
¦b cmdCheck_Click µ{§Ç¤¤ªºÃöÁä¤èªk¬O CheckSpelling¡A¦pªG¶Ç»¼ªº¤Þ¼Æ¬O¥¿½Tªº¡A«h¶Ç¦^ True¡A§_«h¶Ç¦^ False¡C¦b«á±ªº¨Ò¤l¤¤¡Aµ{¦¡©I¥s GetSpellingSuggestions ¤èªk¡A¨Ã¶Ç¦^¤@Ó¥]§t 0 ©Î¬O§ó¦h SpellingSuggestion ª«¥óªº¶°¦X¡C¦pªG¦³¥ô¦óªº«Øij¡Aµ{¦¡·|§Q¥Î For Each °j°é¦CÁ|¥X¨Ó¨Ã¥B©ñ¤J ListBox ±±¨î¶µ¤¤¡C
¤§«eªºµ{§Ç¨Ï¥Î New ÃöÁä¦r«Ø¥ß¤F¤@Ó Word.Application Ãþ§O°õ¦æÓÅé¡A¦p¦P¦b²{¦bªº±M®×¤¤¤@¯ë¡C¦ý¬O·í±z»P COM ª«¥ó¤@°_¤u§@®É¡A±z¤]¥i¥H¨Ï¥Î CreateObject ¨ç¼Æ¡A¦¹¨ç¼Æ¥i¥H±µ¨üÃþ§Oªº¦WºÙ¡G
' An alternative way to create a Word.Application object Set MSWord = CreateObject( "Word.Application")
CreateObject ¨ç¼Æ¤ñ New ÃöÁä¦r¦³§ó¦h¯à¤O¡A¦]¬°±z¥i¥H¦b°õ¦æ´Á¶¡§Q¥ÎÃþ§O¦WºÙ¦r¦ê«Ø¥ßª«¥ó¡A¥N´Àª½±µ¼g¦b«È¤áºÝªºì©l½X¤¤¡C¨âºØ«Ø¥ß COM ª«¥óªº¤èªk¤¤¡A¨ä¥L¥L·L§®ªº®t²§³£¥]§t¦b¦¹³¹¸`¤¤¡C
¨Ï¥Î¥~¦bªº Automation ª«¥ó¬O«Ü®e©öªº¤@¥ó¨Æ¡A«e±ªº¨Ò¤lÅý±z¤F¸Ñ¦p¦ó§Q¥Î¤¸¥óªº¤èªk¡BÄÝ©Ê¥H¤Î¨Æ¥ó¡C¦¹¥~¡A³oÓ²³æªº½d¨ÒÃÒ©ú¤F COM ªº»y¨¥¤¤¥ß¡]language-neutral¡^¥»½è¡C±zªº Visual Basic µ{¦¡¥i¥H¨Ï¥Î COM ¨Ó¦s¨ú¨ä¥L¨ä¥L»y¨¥©Ò¼gªº¤¸¥ó¡A¤Ï¹L¨Ó¤]¤@¼Ë¡R±z¥i¥H§Q¥Î Visual Basic ¨Óµo®i¤¸¥ó¡AµM«á¦b¨ä¥Lªºµo®iÀô¹Ò¤¤¨Ï¥Î¥¦Ì¡C
ª`·N
·í«Å§i¥H¤Î«Ø¥ß¤@ÓÄÝ©ó¥~³¡ª«¥óµ{¦¡®wªºª«¥ó®É¡A±z¥i¥H¨Ï¥Î ¦øªA¾¹¦WºÙ.Ãþ§O¦WºÙªº¥þ¦W»yªk¥N´À³æ¤@ªºÃþ§O¦WºÙ¡C³o©Î³\¬O¥²nªº¡A¥H¸Ñ¨M¤@¨Ç§t½kªº°ÝÃD¡CÁ|¨Ò¨Ó»¡¡A¹³¬OÀ³¥Îµ{¦¡¤Þ¥Î¦hÓ¥~³¡¤¸¥ó¡A¦Ó¨âÓ¥H¤Wªºª«¥ó¨Ï¥Î¬Û¦Pªº¦WºÙ¡C³oºØ±¡§Î¤ñ±z¹w´ÁªºÁÙn±`µo¥Í¡C¦pªG¤£¹w¨¾¡A±z¥i¯à·|¹J¨ì¤@¨Ç¤£©ö¹îıªº¿ù»~¡CÁ|¨Ò¨Ó»¡¡AExcel ª«¥óµ{¦¡®w¥H¤Î Word ª«¥óµ{¦¡®w©Ò´£¨ÑªºÀ³¥Îµ{¦¡ª«¥ó¡C²{¦b¡A«ä¦Ò¤@¤U·í Visual Basic °õ¦æ¤U¦Cµ{¦¡½X®É·|¦p¦ó¡R
Dim x As New Application x.Visible=True
¦óºØµøµ¡·|¥X²{¡AExcel ©Î¬O Word¡Hµª®×¬O¡Rµ²ªG¬O¨Ì¾Ú¦b¤Þ¥Î¶µ¥Ø¹ï¸Ü¤è¶ô²M³æ¤¤¦ì©ó«e±ªºª«¥óµ{¦¡¸ê®Æ®w¡C¦]¦¹¤Þ¥Î¶µ¥Ø¹ï¸Ü¤è¶ô¤¤¥]§t¨âÓÀu¥ýÅvªº«ö¶s¡AÅý±z§ó§ï¸Ó¶µ¥Ø¦b²M³æ¤¤ªº¦ì¸m¡CµM¦Ó¡Aª`·N¨ì¦¹ºØ¼u©Êªº°µªk·|³y¦¨¤@¨Ç¤£©ö¹îıªº¿ù»~¡CÁ|¨Ò¨Ó»¡¡A¦pªG±z±Nµ{¦¡½X½Æ»s¨ì¥t¤@Ó¾Ö¦³¤£¦P¶¶§Çªº²M³æªº±M®×¤¤¡A«hµ{¦¡¤£·|«ö·Ó¦p¹w´Á¯ëªº¤u§@¡C¦]¦¹¡Aµ§ªÌ«Øij±zÀ³¸Ó¸Ô²Ó«ü©ú¥~³¡ª«¥óªº¥þ¦W¡A°£«D±z¦Ê¤À¤§¦Ê½T©w±zªºÀ³¥Îµ{¦¡¤£·|¨Ï¥Î¨ä¥L¥L·|´£¨Ñ¬Û¦P¦WºÙªºª«¥óµ{¦¡®w¡C
«Ø¥ß¤@ÓActiveX EXE¦øªA¾¹
¡@
¦pªG±z¤w¸g¾Ö¦³¤F¤@Ó¥HÃþ§O©Ò«Øºcªºµ{¦¡¡A¥u»Ýn«ö·Æ¹«¼Æ¤U´N¥i¥H±N¨äÂà´«¦¨ ActiveX ¦øªA¾¹¡Cµy«á±z±N·|¨£¨ì¡A±z¬Æ¦Ü¤£»Ýn±NÀ³¥Îµ{¦¡½sĶ¦¨¹ê»Úªº EXE ÀɮרӴú¸Õ¨ä¤¸¥ó¡A¦Ó¥i¥H¦b Visual Basic ªº¾ã¦Xµo®iÀô¹Ò¤¤§Q¥ÎÀô¹Ò©Òµ¹±zªº©Ò¦³¤u¨ã¨Ó°£¿ù¡C
·íµM¡A±z¤]¥i¥H±q¥\¯àªíªº ÀÉ®× ¿ï¨ú «Ø¥ß·s±M®× ¡AµM«á¿ï¨ú ActiveX EXE ¶µ¥Ø¨Ó±Ò°Ê¤@Ó ActiveX ¤¸¥ó¡C¦b³oºØ±¡ªp¤U¡AVisual Basic «Ø¥ß¤@Ó¥]§t Public Ãþ§O¼Ò«¬ªº±M®×¥N´À¥]§tªí³æªº±M®×¡C
°ò¥»¨BÆJ
¡@
·í®i¥Ü¦p¦ó¹ê§@¤@Ó·sªº§Þ³N®É¡A²ßºD¤W¥Ñ¤@Ó²³æªº¨Ò¤l¶}©l¡CµM¦Ó¡A¦b³oӮרҤW¡A§ÚÌ¥i¥H¦A§Q¥Î§Ú̦b
²Ä¤C³¹ ©Òµo®iªº¤@Ó¥HÃþ§O¬°°ò¦ªº¨Ò¤l¡ACFileOp À³¥Îµ{¦¡¡C
³]©w±M®×ÄÝ©Ê
¡@
²Ä¤@¥ón°µªº¨Æ´N¬O¨ø¸ü©Ò¦³¤£¥²nªº¼Ò²Õ¡C·í±z±N CFileOp À³¥Îµ{¦¡Âà´«¬° ActiveX ¦øªA¾¹®É¡A±z¤£¦A»Ýn Form1 ªí³æ¡A¦]¦¹±z¥i¥H±Nªí³æ¸ü¥X¡CµM¦Ó¡A¤£n±Nªí³æ±qºÏºÐ¤W§R°£¡A¦]¬°±z°¨¤W±N»Ýn¨Ï¥Î¨ì¥¦¡C
¤U¤@¨B´N¬O±N¦¹±M®×Åܦ¨ ActiveX À³¥Îµ{¦¡¡A±z¥i¥H¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤ªº ¤@¯ë ¶ÅÒ°µ³]©w¡C¡]¨£¹Ï16-3¡^±z¤]À³¸Óµ¹¤©±M®×¤@Ó¦³·N¸qªº¦WºÙ¡AÁ|¨Ò¨Ó»¡¡AFileOpSvr¡C³oÓ¦WºÙ¦¨¬°µ{¦¡®wªº¦WºÙ¡A¦¹µ{¦¡®w¬O«È¤áºÝ»Ýn¤Þ¥Î¥H¨Ï¥Î¦¹À³¥Îµ{¦¡©Ò´£¨Ñªºª«¥ó¡C¦b ±Ò°Êª«¥ó Äæ¦ì¤¤¿ï¾Ü¡]µL¡^¡A¨Ã¥B¥[¤J¹ï¦¹±M®×ªº´yz¡A¦b³oӮרҤ¤¡A§â´yz³]©w¬° A component for file operations ¡C³o¬q´yz·|¥X²{¦b«È¤áºÝµ{¦¡ªº ¤Þ¥Î ¹ï¸Ü¤è¶ô¤¤¡C
³Ì«á¡A¨ì¹ï¸Ü¤è¶ôªº ¤¸¥ó ¶ÅҨåB½T©w±N±Ò°Ê¼Ò¦¡³]©w¬° ActiveX ¤¸¥ó ¡C¦¹³]©w§i¶D Visual Basic Àô¹Ò±zn¦p¦P¥Ñ¨ä¥LªºÀ³¥Îµ{¦¡¤Þµo¤@Ó¤¸¥ó¤@¯ë¦a´ú¸Õ¥Ø«eªº±M®×¡C¤£n§Ñ°O ActiveX À³¥Îµ{¦¡¤]¥i¥H¦p¦P¤@¯ëªº Windows À³¥Îµ{¦¡¤@¯ë¦a°õ¦æ¡Qn´ú¸Õ ActiveX ¤¸¥ó¦b¬YÀ³¥Îµ{¦¡ªº¦æ¬°¡A±N±Ò°Ê¼Ò¦¡³]¬° ¿W¥ßªºÀ³¥Îµ{¦¡ ¡C
¡@
¹Ï16-3 ³]©w FileOpSvr ¦øªA¾¹À³¥Îµ{¦¡ªº¡u±M®×ÄÝ©Ê¡v¹ï¸Ü¤è¶ôªº©Ò¦³ÄÝ©Ê¡C |
³]©wÃþ§OÄÝ©Ê
¡@
FileOpSvr ±M®×´X¥G¤w¥i¥H°õ¦æ¤F¡A¦ý¬O Visual Basic ¹ê»Ú¤W©Úµ´°õ¦æ¡Aª½¨ì±M®×¤º¥]§t¦Ü¤Ö¤@ӫإߦnªº Public Ãþ§O¡C¦]¬°±zÂà´«¤@Ӽзǰõ¦æÀɱM®×¡ACFileOp Ãþ§O¼Ò²Õªº Instancing ÄݩʬO³]©w¬° 1-Private¡A¦Ó private Ãþ§O¦b¥~¬O¬Ý¤£¨ìªº¡C¬°¤F²Å¦X Visual Basic ªº»Ý¨D¡A±z¥²¶·±NÄݩʧó§ï¬° 5-MultiUse¡A·N¸q¬°¦¹Ãþ§O¬° Public¡A¨Ã¥B¨ä°õ¦æÓÅé¥i¥H³Q«È¤áºÝªºÀ³¥Îµ{¦¡©Ò«Ø¥ß¡C¡]±z»Ýn¤F¸Ñ§ó¦h¦³Ãö©ó°õ¦æÓÅéÄÝ©Ê¡A±z±N¦b¤U¤@³¹¾Ç²ß¨ì¡^
°õ¦æ¦øªA¾¹±M®×
¡@
¨ì¦¹¡A±z¤w·Ç³Æ¦nn°õ¦æ¦øªA¾¹À³¥Îµ{¦¡¡C¦pªG±z«ö¤U F5¡A·|¥X²{¤@Ó¹ï¸Ü¤è¶ô¡A³o¬O ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ôªº°»¿ù¶¡C½T©w®Ö¨ú µ¥«Ý¤¸¥ó«Ø¥ß§¹ ¦¨¿ï¶µ¡AµM«áÂI¨ú OK ¶}©l°õ¦æ¦øªA¾¹¡C¦pªG©Ò¦³ªº³]©w³£¬O¥¿½Tªº¡A±z±N·|¬Ý¨ìµ{¦¡¦b°õ¦æ¡A¦ý¬O¨S¦³¥ô¦ó¨Æ±¡µo¥Í¡C³o¬O¥¿±`ªºªº±¡§Î¡RVisual Basic ¥¿¦bµ¥«Ý«È¤áºÝªºÀ³¥Îµ{¦¡¹ï¦¹¤¸¥ó½Ð¨D¬Y¤@ª«¥ó¡C
¤p¯µ³Z
·í°õ¦æ ActiveX EXE ©Î¬O DLL ±M®×®É¡A±zÀ³¸Ó¨ú®ø¦b¿ï¶µ¹ï¸Ü¤è¶ô¤¤ªº¤@¯ë¶ÅÒ¤Wªº¥HI´º¤è¦¡½sĶ¿ï¶µ¡C¦p¦¹³]©w¥i¥H½T©w·íµ{¦¡´£¨Ñ¥»¨ªºª«¥óµ¹«È¤áºÝªºÀ³¥Îµ{¦¡®É¡A¤£·|¦³½sĶ©Î¬O»yªkªº¿ù»~µo¥Í¡C¦b¦h¼Æªº±¡ªp¤¤¡A¿ù»~·|³y¦¨±z¥²¶·°±¤î¦øªA¾¹©M«È¤áºÝªºÀ³¥Îµ{¦¡¡A×¥¿¿ù»~¡AµM«á«·s¶}©l¡C¦pªG±z¤£·Qn§ó§ï¾ã¦Xµo®iÀô¹Òªº³]©w¡A±z¥i¥H¥Î«ö¤UCtrl+F5ªº½sĶ¤è¦¡¥N´À F5 ªº½sĶ¤è¦¡©Î¬O¿ï¨ú¥\¯àªí¤¤°õ¦æ¤¤ªº¥þ³¡½sĶ«á¶}©l¡C
«Ø¥ß«È¤áºÝÀ³¥Îµ{¦¡
¡@
²{¦b¬O¦^¦¬±z¦b ActiveX EXE ±M®×¤¤©Ò±Ë±óªº Form1 ªí³æªº®ÉÔ¤F¡C°õ¦æ¥t¤@Ó Visual Basic Àô¹Òªº°õ¦æÓÅé¡A¿ï¾Ü ¼Ð·Ç°õ¦æÀɱM®× ¡A¦pªG¥²nªº¸Ü¡A²¾°£ Visual Basic ¦Û°Ê«Ø¥ßªº Form1 ¼Ò²Õ¡C±z¥²¶·³o¼Ë°µ¥H¨¾¤î¦WºÙªº½Ä¬ð¡C
¦¹®É¡A±z¥i¥H¿ï¨ú ±M®× ¥\¯àªí¤¤ªº ·s¼WÀÉ®×... ©R¥O¡A±N CFileOp.Frm ÀÉ®×¥[¤J¨ì±M®×¤¤¡C¡]±z¥i¥H¨Ï¥Î Ctrl+D §Ö³tÁä¡C¡^±z»Ýn±N¦¹ªí³æ³]¬°¦¹±M®×ªº±Ò°Êª«¥ó¡A¥i¥H¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ôªº ¤@¯ë ¶ÅÒ¤¤°µ¦¹³]©w¡C¦pªG±z²{¦b°õ¦æ«È¤áºÝªº±M®×¡A±z±N·|±o¨ì¤@Ó½sĶ¿ù»~ªº°T®§¡]¨Ï¥ÎªÌ¦Ûq«¬ºA©|¥¼©w¸q¡^¡A³o¬O¥Ñ¤U¦C¦b Form1 ¼Ò²Õªº«Å§iµ{¦¡¬q¤¤ªºµ{¦¡©Ò¤Þ°_ªº¡G
Dim WithEvents Fop As CFileOp
ì¦]¬O«Ü©úÅ㪺¡GCFileOp ª«¥ó¹ï©ó¥Ø«eªºÀ³¥Îµ{¦¡¦Ó¨¥¬O¥~³¡ªºª«¥ó¡An¨Ï Visual Basic ¯à°÷§ä¨ì¦¹ª«¥ó¡A±z¥²¶·¦bÀ³¥Îµ{¦¡ªº ¤Þ¥Î ¹ï¸Ü¤è¶ô¥[¤J¹ï¦¹ª«¥óªº¤Þ¥Î¡C¿ï¨ú FileOpSvr ±M®×«Ü²³æ¡A¦]¬°¨ä´yz¬°¡uA component for file operations¡v¡A¥X²{¦bµù¥U¨t²Î¤W¥H¦r¥À±Æ¦Cªº©Ò¦³¤¸¥óªº«e¤è¡CµM¦Ó¡A¦pªG±zÃhºÃ¡A¥unÀˬd¹ï¸Ü¤è¶ô¤¤¾aªñ¤U±ªº ¦ì¸m Äæ¦ì¡C¦¹¦r¦êÀ³¸Ó«ü¦V VBP ±M®×ÀɮסA©Î¬O¦pªG±z©|¥¼Àx¦s¦¹±M®×¡A«h«ü¦V¤@Ó¦ì©ó WINDOWS TEMP ¥Ø¿ý¤¤ªº¼È¦sÀÉ¡C¦b¦hÓ¦³¬Û¦Pªº±Ôzªº¤¸¥ó¤¤§ä´M©Ò»Ýªº¤¸¥ó®É¡A±zÀ³¸ÓÀˬd¦¹Äæ¦ì¡A¦¹±¡ªp±`µo¥Í¦b¤£¦Pª©¥»ªº¬Û¦P¤¸¥ó¤W¡C
´ú¸Õ«È¤áºÝ
¡@
¥[¤J¤@ӤޥΨì FileOpSvr ±M®×¤¤¤§«á¡A´N¥i¥H°õ¦æ¦¹«È¤áºÝªºÀ³¥Îµ{¦¡¡A¨Ã¥B¥i¨£¨ìÀ³¥Îµ{¦¡¦p¦Pì¨Óªº¥HÃþ§O¬°°ò¦ªºÀ³¥Îµ{¦¡¤@¯ë¦a°õ¦æ¡CµM¦Ó¡A©Ò¬Ý¤£¨ìªº®t²§¦b©ó©Ò¦³ªºª«¥ó¹ï©óÀ³¥Îµ{¦¡¨Ó»¡³£¬O¥~³¡ªº¡A¨Ã¥B§Q¥Î COM »PÀ³¥Îµ{¦¡Ápô¡C§ó¥O¤H¿³¾Äªº¬O±z¥i¥H¦p¦P¤@ӼзǪº Visual Basic ±M®×¯ë¦a¹ï¥H COM ¬°°ò¦ªºÀ³¥Îµ{¦¡¶i¦æ°»¿ù¡C¨Æ¹ê¤W¡A±z¥i¥H¨Ï¥Î F8 ¥\¯àÁä¨Ó°lÂÜ¥ô¦ó¸óÀ³¥Îµ{¦¡ªº©I¥s¡A±z±N¥Ñ«È¤áºÝ±M®×ªºì©lµ{¦¡½X¶Ç°e¨ì¦øªA¾¹ªºµ{¦¡½X¨Ã¦A¶Ç¦^¡C
ÅãµM¦a¡A³oÓ¤p¤pªº¯S¦â¹ê»Ú¤W«o¬O¤@ӫܤjªº±ÏÃøªÌ¡A·í±z´ú¸Õ ActiveX «È¤áºÝ©M¦øªA¾¹ªºµ{¦¡¥i¥H¸`¬Ù±z³\¦h®É¶¡¡C
·í±z¤w§¹¦¨´ú¸Õ¶¥¬q¡A´NÀ³¸ÓÃö³¬«È¤áºÝÀ³¥Îµ{¦¡ªí³æ¡A¨Ã¥B«ö¤U¤u¨ã¦C¤Wªº °±¤î «ö¶s¥H°±¤î¦øªA¾¹ªºµ{¦¡¡C¡]³o¬O¤Ö¼Æ·í±z«ö¤U¡u°±¤î¡v«ö¶s´N¥i¥H¦¨¥\°±¤î¤@Ó°õ¦æªºÀ³¥Îµ{¦¡ªº±¡ªp¤§¤@¡C¡^¦pªG±z¹Á¸Õ¥H¬Û¤Ïªºµ{§Ç§¹¦¨³o¨Ç°Ê§@¡A¨º»ò·í±z·Qn°±¤î¦øªA¾¹®ÉÔ·|¥X²{¤@Óĵ§i¡A¦p¹Ï16-4¡C¦pªG±z«ö¤U Yes «ö¶s¡A½T©w²×¤î¦øªA¾¹ªºÀ³¥Îµ{¦¡¡A¨º»ò·í«È¤áºÝªºµ{¦¡¹Á¸Õ¨Ï¥Î Fop ÅܼƩÒÀx¦sªºª«¥ó«ü¼Ð®É¡AÀ³¥Îµ{¦¡·|¥X²{¿ù»~¡C
¡@
¹Ï16-4 ¦pªG«È¤áºÝ¥¿¦b¨Ï¥Î¦øªA¾¹ªºª«¥ó®É¡A±z¤£À³¸Ó°±¤î¦øªA¾¹ªºÀ³¥Îµ{¦¡¡C |
InstancingÄÝ©Ê
¡@
¤@ÓÃþ§O¼Ò²Õªº Instancing ÄݩʨM©w«È¤áºÝªºÀ³¥Îµ{¦¡¦p¦óÂÇ¥Ñ COM «Ø¥ß¥H¤Î¤Þ¥Î¦¹Ãþ§Oª«¥ó¡C¦¹ÄÝ©Ê¥i¥H¤À°t¤»Ó¤£¦PªºÈ¡A§Y¨Ï¤£¬O©Ò¦³ªºÈ³£¾A¥Î©ó¥|ºØ±M®×§Î¦¡¡A¸Ô¦C©óªí 16-1¡A±z¥i¥H¦b Visual Basic ¤¤«Ø¥ß¡R
¼Ð·Ç EXE | ActiveX EXE | ActiveX DLL | Active X ±±¨î¶µ | |
---|---|---|---|---|
1-Private | ۷ƒÀ | ۷ | ۷ƒÀ | ۷ |
2-PublicNotCreatable | ۷ | ۷ | ۷ | |
3-SingleUse | ۷ | |||
4-Global SingleUse | ۷ | |||
5-MultiUse | ۷ | ۷ | ||
6-Global MultiUse | ƒÀ | ۷ | ۷ |
ªí16-1 ¤£¦P±M®×Ãþ«¬¤¤©Ò¾A¥Îªº Instancing ÄÝ©Ê |
¿ï¾Ü³Ì¾A·íªº³]©w
¡@
±z»Ýn¤F¸Ñ¦UºØ¥i¯àªº Instancing Äݩʪº³]©w¤§¶¡ªº®t²§¡C¦b°õ¦æ®É¡A±z¤£¯à¾\Ū©M§ó§ï¦C©ó ÄÝ©Ê µøµ¡¤¤Ãþ§OªºÄÝ©ÊÈ¡C¤£¦P©ó±±¨î¶µªºÄÝ©Ê¡AÃþ§OªºÄݩʬO¥u¾A¥Î©ó³]p¶¥¬qªºÄÝ©Ê¡CInstancing ÄÝ©Ê¥i¯àªº³]©w¦C©ó¤U¤@¶¤¤¡C
Private ¡RPrivate Ãþ§O¼Ò²Õ¦b¥Ø«eªº±M®×¥H¥~¬O¬Ý¤£¨ìªº¡C´«¥y¸Ü»¡¡A¤£¥u¬O«È¤áºÝªºÀ³¥Îµ{¦¡¤£¯à«Ø¥ß¦¹ºØÃþ«¬ªºÃþ§O¡A¬Æ¦Ü¤£¥i¥H¤Þ¥Î³o¨ÇÃþ§O¡C¨Æ¹ê¤W¡A¦øªA¾¹ªºÀ³¥Îµ{¦¡¤£¤¹³\¶Ç°e¤@Ó Private Ãþ§Oªº°õ¦æÓÅé¨ì«È¤áºÝ¡C¡]Á|¨Ò¨Ó»¡¡A¦p¦P¤@Ó Function ªº¶Ç¦^ȩάO¤@Ó Procedure ªº°Ñ¼Æ¡^¡C¦b¼Ð·Çªº EXE ±M®×¤¤©Ò¦³ªºÃþ§O¼Ò«¬³£¬O Private¡A¦]¦¹¡A¦b³o¨Ç±M®×¤¤°õ¦æ Instancing ÄݩʬO¤£¾A¥Îªº¡C
PublicNotCreatable¡R ³o¨ÇÃþ§O¬O¥~¦bªº±M®×¥i¥H¬Ý¨ìªº¡A¦ý¬O«È¤áºÝªºÀ³¥Îµ{¦¡¤£¯àª½±µ«Ø¥ßÃþ§Oªº°õ¦æÓÅé¡C³o¥y¸Üªº·N«ä¬O¡A«È¤áºÝ¥i¥H«Å§i³o¨ÇÃþ§O«¬ºAÅܼƥH¤Î§Q¥Î Set ©R¥O«ü¬£ª«¥ó¤Þ¥Î¡A¦ý¬O¤£¥i¥H¨Ï¥Î New ¹Bºâ¤l©Î¬O CreatObject ¨ç¼Æ¨Ó«Ø¥ß³o¨ÇÃþ§Oªº°õ¦æÓÅé¡C«È¤áºÝn±o¨ì PublicNotCreatable Ãþ§O¦Xªkªº¤Þ¥Î°ß¤@ªº¤èªk´N¬O½Ð¨D¦øªA¾¹¶Ç¦^¤Þ¥Î¡AÁ|¨Ò¨Ó»¡¡A³z¹L¨ä¥LÃþ§Oªº¤èªk¡C¦]¦¹¡AVisual Basic ´£¨Ñ©Ò¦³ªº ActiveX ±M®×¥]§t¦Ü¤Ö¤@Ó¥i«Ø¥ßªºÃþ§O¡C
SingleUse¡R SingleUse ª«¥ó¬O¤½¶}¨Ã¥B¬O¥i«Ø¥ßªº¡A©Ò¥H«È¤áºÝ¥i¥H«Å§iÃþ§OÅܼƨåB¨Ï¥Î New ¹Bºâ¤l©Î¬O CreatObject ¨ç¼Æ«Ø¥ß°õ¦æÓÅé¡C·í¤@Ó·sªºª«¥ó³Q«È¤áºÝ«Ø¥ß¡ACOM ¸ü¤J¤@Ó·sªº¦øªA¾¹°õ¦æÓÅé¡A¨C¦¸¦ì©ó¤£¦Pªº¦ì§}ªÅ¶¡¡CÁ|¨Ò¨Ó»¡¡A·í¤@ӫȤáºÝÀ³¥Îµ{¦¡«Ø¥ß¤QÓ SingleUseª«¥ó¡ACOM °õ¦æ¤QÓ¤£¦Pªº³B²z§Ç¡A¨CÓ³B²z§Ç´£¨Ñ¤@Óª«¥óªº°õ¦æÓÅé¡C
MultiUse¡R MultiUse ª«¥ó¬O¤½¶}¨Ã¥B¬O¥i«Ø¥ßªº¡A¦ý¬O¤£¦P©ó SingleUseª«¥ó¡A³æ¤@¤¸¥óªº°õ¦æÓÅé´£¨Ñ«È¤áºÝÀ³¥Îµ{¦¡©Ò½Ð¨Dªº©Ò¦³ª«¥ó¡C³o¬O¦b ActiveX EXE ©Î¬O ActiveX DLL ¤¤¥[¤Jªºª«¥ó¼Ò²Õªº¹w³]È¡A¤]¬O¦b¤j¦h¼Æªº±¡ªp¤¤³Ì¾A¥Îªº³]©w¡C
GlobalSingleUse¥H¤ÎGlobalMultiUse¡R ³o¤À§O¬O SingleUse ¥H¤ÎMultiUse ªºÅܼƪº³]©w¡C¤@¯ë¥þ°ì¡]Global¡^ª«¥ó¦b«á±ªº³¹¸`¤¤´yz¡C
Private¥H¤ÎPublicª«¥ó
¡@
¤@ÓÃþ§O³Ì«nªº¯S©Ê´N¬O¨ä½d³ò¡]Scope¡^¡C¦pªG°õ¦æÓÅé¡]Instancing¡^ÄݩʬO 1-Private¡A¦b¦øªA¾¹¥H¥~¨S¦³¥ô¦óÃþ§O°õ¦æÓÅé¥i¥H¬Ýªº¨ì¡C¦b¨ä¥LªºÄݩʤ¤¡A³o¨Çª«¥ó¥i¥H³Q«È¤áºÝÀ³¥Îµ{¦¡¾Þ§@¨Ã¥B¥i¥H¦Û¥Ñ¦a¥Ñ¦øªA¾¹¶Ç»¼¦Ü«È¤áºÝ¡A¤Ï¤§¥çµM¡ÐÁ|¨Ò¨Ó»¡¡A¦p°Ñ¼Æ¶Ç¦Ü¤èªk©Î¬OÄÝ©Ê¥H¤Î¨ç¼Æªº¶Ç¦^È¡C
¦pªG¤@ӫȤáºÝªºÀ³¥Îµ{¦¡¥i¯à±o¨ì¤@Ó¦øªA¾¹ Private ª«¥óªºª«¥ó¤Þ¥Î¡A¤@³s¦êÄY«Ãø¥H³B²zªº¨Æ±¡¥i¯à·|µo¥Í¡A¥]§tP©Rªº¿ù»~©Î¬O¬Æ¦Ü¬O GPE ¿ù»~¡C«Ü©¯¹B¦a¡A±z¤£·|°õ¦æ¥ô¦óÄY«ªº¦MÀIµ{¦¡¡A¦]¬° Visual Basic ½sĶ¾¹·|ªý¤î±q¦øªA¾¹¶Ç¦^ Private ª«¥ó¦Ü«È¤áºÝ¡CÁ|¨Ò¨Ó»¡¡A¦pªG±zªº¦øªA¾¹¤¸¥ó©w¸q¤F¤@Ó Private Ãþ§O¡A¨Ã¥B±z«Ø¥ß¤@Ó¾Ö¦³·|¶Ç¦^ Private Ãþ§Oªº°õ¦æÓÅ骺 Public ¤èªkªº Public Ãþ§O¡A
Visual Basic ·|²£¥Í¤@Ó¦p¹Ï16-5ªº¿ù»~°T®§¡C·í±z¹Á¸Õ¶Ç»¼«È¤áºÝ¤@Ó¤¸¥óªº BAS ¼Ò²Õ¤¤ªº¨Ï¥ÎªÌ¦Ûq«¬ºA¡]UDT¡^®É¡A¤]·|µo¥Í¬Û¦Pªº¿ù»~°T®§¡C³o¬O¦]¬°¦b BAS ¼Ò²Õ¤¤ªº©Ò¦³©w¸q³£µø¬° Private¡AÁa¨Ï¨Ï¥Î Public ÃöÁä¦r°µ«Å§i¤]¬O¦p¦¹¡C
¡@
¹Ï16-5 ¹ï¦øªA¾¹¦Ó¨¥¡A¶Ç»¼ Private ª«¥ó¥H¤Î¸ê®Æµ²ºcµ¹¤©«È¤áºÝ³£¬O¤£¦Xªkªº¡C |
MultiUse ¥H¤Î SingleUse ª«¥ó
¡@
n¤F¸Ñ SingleUse ¥H¤Î MultiUse ª«¥ó¤§¶¡ªº®t²§¡A±z¥²¶·n°O¦íªº¬O°£«D±z©ú¥Õ¦a½Ð¨D¨ä«Ø¥ß¦h°õ¦æºüªº¤¸¥ó¡]¦h°õ¦æºü¥]§t¦b«á±ªº¡q¦h°õ¦æºü ActiveX ¤¸¥ó¡rªº³¹¸`¤¤¡^¡A¤£µM Visual Basic «Ø¥ß³æ¤@°õ¦æºüªº¤¸¥ó¡C
¤@Ó³æ¤@°õ¦æºü MultiUse ¤¸¥ó¥u¥i¥H¦b¦P¤@®É¶¡ªA°È¤@ӫȤáºÝ¡Q´«¥y¸Ü»¡¡A§Y¨Ï¤¸¥ó´£¨Ñ³\¦hª«¥óµ¹¨ä«È¤áºÝ¡A¦b¯S©wªº®É¶¡¤º¥u¦³¤@Óª«¥ó¥i¥H°õ¦æµ{¦¡¡C©Ò¥H¦pªG¤À§O¦³¨âӫȤáºÝ¦P¤@®É¶¡¹ï¤¸¥ó¤¤ªºª«¥ó´£¥X½Ð¨D¡A±N¥u¦³¤@ӫȤáºÝ·|³Qª½±µ¦aªA°È¡A¥t¤@ӫȤáºÝ¥²¶·µ¥¨ì²Ä¤@Óª«¥ó¤¤ªº¤èªk§¹¦¨°õ¦æ«á¤~·|°õ¦æ¡CµM¦Ó¡A¨S¦³¥ô¦ó½Ð¨D·|¿ò¥¢¡A¦]¬° COM ¦Û°Ê¦a±Æ¦C¦n©Ò¦³«È¤áºÝªº½Ð¨D¡Q½Ð¨D·|³Q©µ½w¨Ã©ñ¸m¦b¦î¦C¤¤¡C¨CӽШD±N·|¯d¦b¦î¦C¤¤ª½¨ì¦b¨CӽШDªº¦î¦C¤§«eªº¤u§@³£§¹¦¨¥H«á¡C
³oÓ ¦P®É¤@¶µ¤u§@ ¡]one-thing-at-a-time¡^ªº¨î¤w¸g³Q¦h°õ¦æºü MultiUse ¤¸¥ó¥´¯}¤F¡AMultiUse ¤¸¥ó¥i¥H«Ø¥ß°õ¦æªº¦h°õ¦æºü¡A¨CÓ°õ¦æºü´£¨Ñ¤@Ó¤£¦Pªºª«¥ó¡C¦]¦¹¦h°õ¦æºü¤¸¥ó¥i¥HªA°È¦hӫȤáºÝ¡A¤£·|¦]¬°¤@ӫȤáºÝªýê¦Ó¼vÅT¨ì¨ä¥L¨ä¥Lªº«È¤áºÝ¡C
¬Û¤Ï¦a¡A¨CÓ SingleUse ª«¥ó¬O¥Ñ¤£¦Pªº³B²z§Ç¡]process¡^©Ò´£¨Ñªº¡CSingleUse ª«¥ó¥DnªºÀuÂI¦b©ó¥¦Ì¥i¥H¦h¤u¡]Multitask¡^¡C´«¥y¸Ü»¡¡A¨CÓ³æ¿Wªº SingleUse Ãþ§O°õ¦æÓÅé¦b¤£¦Pªº³B²z§Ç¤¤°õ¦æ¡ASingleUse ª«¥ó¤ñ MultiUse ª«¥ó»Ýn¸û¦hªº°O¾ÐÅé¥H¤Î¨t²Î¸ê·½¡CÁ`Åé¨Ó»¡¡A±z¥i¥H°²³]¨C¼W¥[¤@Ó SingleUse ª«¥ó»Ýn¤j¬ù 800KB ªº°O¾ÐÅé¡A¦]¦¹«Ü©úÅã¦a¡A·í±z·Q¹³«Ø¥ß¤W¤d¤W¦ÊÓª«¥ó®É±z¤£¥i¥H¨Ï¥Î SingleUse ª«¥ó¡C¹ê»Ú¤W¡A¦b°ª¶¥¨t²Î¤W±z¤£¯à°õ¦æ¶W¹L¼Æ¤QÓªº SingleUse ª«¥ó¡C³o¬O¦]¬°·í¤Ó¦hªº³B²z§Ç¦b°õ¦æ®É¡A±zªº CPU ªá¶O¦b³B²z§ÇÂà´«¤Wªº®É¶¡¤ñ¹ê»Ú¤W°õ¦æ³B²z§Çµ{¦¡½Xªº®É¶¡ÁÙn¦h¡C
¥t¥~¤@Ó SingleUse ¤¸¥óªº°ÝÃD´N¬O±z¤£¯à¦b Visual Basic ªºÀô¹Ò¤¤°µ§¹¾ãªº´ú¸Õ¡CIDE ¥u¯à´£¨Ñ¤@Ó SingleUse ª«¥ó¡A·í«È¤áºÝ½Ð¨D²Ä¤GÓ SingleUse ª«¥ó®É¡A´£¨Ñ SingleUse ª«¥óªº Visual Basic °õ¦æÓÅé·|Åã¥Ü¤@Ó¿ù»~°T®§¡C¥X²{¿ù»~°T®§ªº´X¬í¤¤¤§«á¡A«È¤áºÝªºÀ³¥Îµ{¦¡¦¬¨ì¤@Ó¥N¸¹ 429 ªº¿ù»~°T®§¡u¤¸¥óµLªk«Ø¥ßª«¥ó©Î¶Ç¦^¤Þ¥Î¨ì¦¹ª«¥ó¡v¡Cn§¹¾ãªº´ú¸Õ¤@Ó SingleUse ¤¸¥ó¡A±z¥²¶·±N SingleUse ¤¸¥ó½sĶ¦¨ ActiveX EXE ÀɮרåB¥H±zªº«È¤áºÝ¤Þ¥Î³oÓ EXE ÀɮרӥN´À Visual Basic Àô¹Ò©Ò´£¨Ñªº¤¸¥ó¡C
©Ò¦³ªº¨Æ±¡¦Ò¼{«á¡A±zªº³Ì¨Î¿ï¾Ü³q±`´N¬O«Ø¥ß³æ¤@°õ¦æºü©Î¬O¦h°õ¦æºüªº MultiUse ª«¥ó¡C³o¤]¬O¸û®e©ö¹F¦¨ªº¤èªk¡A·Pı¤W±z¥i¥H´£¨Ñ 10¡B100 ©Î¬Æ¦Ü 10000 Óª«¥ó¦Ó¤£·|®ø¯Ó±¼±zªº¨t²Î©Ò¦³ªº°O¾ÐÅé¥H¤Î CPU ®É¶¡¡C·í±z§Q¥Î¦P³B²z§Ç¡]in-process¡^ActiveX ®É¡A±z¨S¦³§Oªº¿ï¾Ü¡C¦]¬°¤@Ó ActiveX DLL »P«È¤áºÝ¦b¦P¤@¦ì§}ªÅ¶¡°õ¦æ¡A¤£¥i¯à¦b¤£¦Pªº¦ì§}ªÅ¶¡«Ø¥ß¦P¤@¤¸¥óªº¦hÓ°õ¦æÓÅé¡C¦]¦¹¡AActiveX DLL ±M®×¤£¤ä´© SingleUse ÄÝ©Ê¡C
¤£½×±zªº¨M©w¬O¤°»ò¡A³Ì«nªº¤@ÂI¬O¦b¬Û¦Pªº ActiveX EXE ¦øªA¾¹¤º±zµ´¤£À³¸Ó²V¦X MultiUse ¥H¤Î SingleUse ª«¥ó¡]©Î¬O¥¦Ìªº Global Åܼơ^¡C¦pªG±z¦p¦¹°µ¡A±z¨S¦³¹ï MultiUse ª«¥ó©Ò´£¨Ñ¤¸¥óªº¯S§O°õ¦æÓÅ骺±±¨î¡A¨Ã¥B¤@Ó¯S©wªº«È¤áºÝ¥i¯à©Ò¾Ö¦³ªºª«¥ó¬O¤£¦P°õ¦æÓÅé©Ò´£¨Ñªº¡A³o¨Ç¨Æ±¡³£¬O±zÀ³¸ÓÁקKªº¡C
¹ê»Ú¤W¡A¦pªG¤@Ó SingleUse ¤¸¥ó¬O¤@Óª«¥óªº¶¥¼h¡A±zn¨Ï¶¥¼hªº®Úª«¥ó¦¨¬°°ß¤@¤@Ó¥i«Ø¥ßªºª«¥ó¨Ã¥B¨Ï¶¥¼h¤¤©Ò¦³¨ä¥Lªº Public ª«¥ó¬° PublicNotCreatable.¡C±z¤]n´£¨Ñ±zªº«È¤áºÝ¤@©w¼Æ¶qªº«Øºc¦¡¡]Constructor method¡^¥H¾Ö¦³«Ø¥ß¨CÓ¦p¦¹¬ÛÃöª«¥óªº°õ¦æÓÅ骺ªA°È¡C»Ýn§ó¦hªºª«¥ó¶¥¼h¥H¤Î«Øºc¦¡ªº°T®§¡A¨£ ²Ä¤C³¹ ¡C
¤º³¡ªº°õ¦æÓÅé¡]Internal instancing¡^
¡@
¤@Ó ActiveX ¦øªA¾¹¥i¥HÅý©w¸q¦b¦Û¤v Visual Basic ±M®×¤ºªºª«¥ó¦¨¬°°õ¦æÓÅé¡C¦b¦¹±¡§Î¤U¡Aª«¥ó¨ü¨ìª«¥ó¦p¦ó³Q«Ø¥ß¥H¤Î¨Ï¥Îªº¼vÅT¡A¨¤¦â¦³¨Ç·L¤£¦P¡G
±q©Ò¦³ COM ªº¦¨¥»¨Ó¬Ý¡A¹ï©ó©w¸q¦b¦P¤@Ó±M®×¤¤ªº Public ª«¥ó¨Ï¥Î CreateObject «Ø¥ß°õ¦æÓÅén¤ñ¨Ï¥Î New ¹Bºâ¤lºC¤W¥|¡B¤¿¤]¤£À³¸Ó·P¨ìÅå³Y¡C¦]¦¹¡A¤@¯ë¨Ó»¡¡AÀ³¸ÓÁקK CreateObject¡C¡]¨£µy«á¦¹³¹¤¤ªº¡q¦h°õ¦æºü Visual Basic À³¥Îµ{¦¡¡r¹ï©ó¦¹¨¤¦âªº¨Ò¥~¡^
¥þ°ì¡]global¡^ª«¥ó
¡@
¥þ°ì©M«D¥þ°ì SingleUse ¥H¤Î MultiUse ª«¥ó°ß¤@ªº®t§O¦b©ó·í¤Þ¥Î¨ì¥þ°ìª«¥óªº¤èªk¥H¤ÎÄݩʮɡA±z¥i¥H©¿²¤±¼¥þ°ìª«¥óªº«Å§i¡CÅý§Ú̥Τ@Ó¨Ò¤l¨Ó¸ÑÄÀ¡R
°²³]±z¾Ö¦³¤@Ó¥]§t¼Æ¾Çpºâ¤èªkªºª«¥ó¡A¨Ò¦p¡R
' In the Math class of the VBLibrary project Function Max(x As Double, y As Double) As Double If x > y Then Max = x Else Max = y End Function
¦pªG±z¨Ï³oÓª«¥ó¬° GlobalMultiUse ©Î¬O GlobalSingleUse¡A±z¦b Visual Basic «È¤áºÝÀ³¥Îµ{¦¡¤¤¥i¥H¤£¥Î©ú½T¦a«Ø¥ß¤@Ó«ü¨ì¦¹ª«¥ó°õ¦æÓÅ骺ª«¥óÅܼƴN¯à¤Þ¥Î¨ì Max ¤èªk¡C³o«D±`ªº«K§Q¡A¦]¬°³o¬O¤@ºØ Visual Basic »y¨¥µ{¦¡®wªº©µ¦ù¡C
'In the client application Print Max(10, 20) 'This works!
´«¥y¸Ü»¡¡A±z¥i¥H«Ø¥ß¤@Ó¥i¥HÅã¥Ü sub ¥H¤Î function ¤èªkªºÃþ§O¡A±z¥i¥H¦p¦P©R¥O¥H¤Î¨ç¼Æ¯ë¦a¦b±zªº«È¤áºÝÓ§O¦aÅã¥Ü³o¨Ç¤èªk¡C±z¤£·|³Q¤èªk©Ò¨î¦]¬°±zªºÃþ§O¥i¥HÅã¥ÜÄÝ©Ê¡A¨Ã¥B¨ä«È¤áºÝ¨£¨ì³o¨ÇÄݩʦp¦P³o¨ÇÄݩʬOÅܼƤ@¯ë¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H¦b Visual Basic ¤¤¥[¤J±`¼Æ¡R
'A read-only property in the VB2TheMax.Library class Property Get Pi() As Double Pi = 3.14159265358979 End Property ' In the client program Circumference = Diameter * Pi
µM¦Ó¡A±zÀ³¸Óª`·N¤U¦C´XÓnÂI¡C§Y¨Ï±z©¿²¤«Å§i¤@Ó«ü¨ì¤@ÓÃþ§O°õ¦æÓÅ骺ÅܼơA¨Ã¥B¤´µM¦s¨ú¨äÄÝ©Ê¥H¤Î¤èªk¡A©Ò©¿²¤ªº¨BÆJ¥u¬O Visual Basic ´£¨Ñ±z¦b»yªk¤Wªº«K§Q¡C¨Æ¹ê¤W¡A¦b¦¹I«á¡A»y¨¥«Ø¥ß¤F¤@ÓÁôÂ꺾A·í«¬ºAªºª«¥óÅܼơA¨Ã¥B·í¨C¦¸¨ú¥Î¤@ÓÃþ§Oªº¦¨û®É¨Ï¥Î¦¹ÅܼơC¦¹°Ê§@ªí¥Ü±z¨Ï¥Î¤@Ó¥þ°ìª«¥ó¨Ã¤£¯à¥[§Ö±zµ{¦¡ªº³t«×¡C¬Û¤Ïªº¡AÁôÂ꺤ޥάO¥Ñ auto-instancing ÅܼƩҹê§@¥X¨Óªº¡A©Ò¥H·í±z¦s¨ú¥þ°ìª«¥óªº¤èªk¥H¤ÎÄÝ©Ê®Én¥I¥X¤@ÂIÂIªº¦¨¥»¡A¦]¬° Visual Basic n¨M©w¬O§_n«Ø¥ß¤@Ó·sªº°õ¦æÓÅé¡C
¶i¤@¨B¦a¡A¦]¬°±z¹ï³oÓÁôÂêºÅܼƨS¦³±±¨îÅv¡A©Ò¥H±z¤£¯à±N¥¦³]©w¬° Nothing¡A©Ò¥H³oÓª«¥ó¥u¦³¦bÀ³¥Îµ{¦¡µ²§ô®É¤~·|®ø·À¡C³o¤@ÂI³q±`¨S¦³Ãö«Y¡A¦ý¬O·íª«¥ó¨ú¥Î«Ü¦h°O¾ÐÅé¥H¤Î¸ê·½®É¥i¥HÅܱo¦³·N¸q¨Ç¡C
¥O¤HÃö¤ßªº¬O±z¥i¯à¨Ï¥Î¥þ°ìÅܼƦh¦~¦ý¤£ª¾¹D¥¦ªº·N¸q¡C¨Æ¹ê¤W¡AVBA µ{¦¡®w¥u¤£¹L¬O¥þ°ìª«¥óªº¶°¦X¡Q±z¥i¥H§Q¥Îª«¥óÂsÄý¾¹ÂsÄý VBA ¨ç¦¡¡A±z·|¬Ý¨ì¤@¨Ç¦WºÙ¬° Math¡BStrings µ¥¼Ò²Õ¦WºÙ¡C¨CÓ¼Ò²Õ´£¨Ñ¤@¨Ç¤èªk¡C¦]¬°¨CӼҲռаO¬°¡u¥þ°ì¡v¡A©Ò¥H±z¥i¥H¦b Visual Basic À³¥Îµ{¦¡¤¤Åã¥Ü³o¨Ç¤èªk¦p¦P¬Oì¥Í¨ç¼Æ¤@¯ë¡C¬Û¦P¦a¡AVisual Baisc µ{¦¡®w¡]¦bª«¥óÂsÄý¾¹¤¤¦WºÙ¬° VB¡^¥]§t¤@Ó¥þ°ì¼Ò²Õ¡A´£¨Ñ©Ò¦³»y¨¥©Ò¤ä´©ªº¼Ò²Õ¡A¨Ò¦p App¡BPrinter ¥H¤Î Clipboard¡C»Ýn§ó¦hªº¸ê°T¡A¨£²Ä¤C³¹ ¡qSubclassing the VBA Language¡r ¡C
¦]¬°¥þ°ìª«¥ó¨å«¬¤W¥Î©ó«Ø¥ßµ{¦¡®w¡A©¹©¹³Q¹ê§@¬°¦P³B²z§Ç¡]in-process¡^ActiveX ¤¸¥ó¡C¦bÀH®Ñ¥úºÐ¤¤¡A±z¥i¥H§ä¨ìÃö©ó³oÓÆ[©À¤è±¤@Ó¸û½ÆÂøªº¨Ò¤l¤@VB2TheMax ¤¸¥ó¡A¥]§t¤F Visual Basic »y¨¥¤¤³\¦h math¡Bdate¡Btime¡Bstring ¥H¤Î file ªº¨ç¼Æ¥H¤Î©R¥O©Ò©µ¦ù¥Xªº¤Q¤CÓÃþ§O¥H¤Î¤@¦Ê¤C¤QÓ¥H¤Wªº¤èªk¡C
³o¸Ì¦³¨âÓ±z»Ýnª¾¹D¦³Ãö©ó¥þ°ìª«¥ó§ó«nªº»¡©ú¡C
²Ä¤@¡A ³o¼Ëªºª«¥ó¥u¦³¦b±M®×¤§¥~¤~¬O¥þ°ìªº¡C¦b¤¸¥óªº±M®×¤¤¡A¥¦Ì¬O¤@¯ëªºª«¥ó¡A¥²¶·¦p¤@¯ëªºª«¥ó¤@¼Ë¡A«Å§i¥H¤Î«Ø¥ß°õ¦æÓÅé¡C
²Ä¤G¡A ¦p¦P¦¹®É©Ò¼gªº¡AVisual Basic ¥u¬O¤@ӫإߤ䴩¥þ°ìª«¥óªº«È¤áºÝªºµo®iÀô¹Ò¡A±z¥i¥H¦b COM ¬Û®eªºµ{¦¡»y¨¥¤¤¨Ï¥Î±zªº¥þ°ìª«¥óµ{¦¡®w¡A¦ý¦b³o¨Çµ{¦¡»y¨¥¤¤¡A±zªº¥þ°ìª«¥ó³Qµø¬°¤@¯ëªº SingleUse ©Î¬O MultiUse ª«¥ó¡C
¦bÀ³¥Îµ{¦¡¶¡¶Ç»¼¸ê®Æ
¡@
COM ¦n¥Îªº¦a¤è¦b©ó¤¸¥ó©M¨ä«È¤áºÝ¥i¥H§â¸ê®Æ¶Ç¦^¡B¶Ç¥X¡A¨Ã¥B¤£»Ýn±z¾á¤ß³q°T¤W©Ò¦³°ò¥»ªº®Ö¤ß²Ó¸`¡CµM¦Ó¡A¦pªG±z¯àµy·L¤F¸Ñ COM ¦bI«á©Ò°µ±o°µªº¨Æ¡A±z¤@©w¥i¥H¼g¥X§ó¦nªºµ{¦¡¡C
¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^
¡@
¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^¬O COM ¨C¦¸°õ¦æ®É¡A¸ê®Æ»Ýn±q«È¤áºÝ¶Ç°e¨ì¸ó³B²z§Ç¦øªA¾¹¨Ã¶Ç¦^ªº¤@ºØ§@·~¡C¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^¬O¤@Ó½ÆÂøªºµ{§Ç¡G¦]¬° ActiveX EXE ¦øªA¾¹©M¨ä«È¤áºÝ¦ì©ó¤£¦Pªº¦ì§}ªÅ¶¡¡A¤¸¥ó¨Ã¤£¯àª½±µ¬Ý¨ìÀx¦s¦b«È¤áºÝ¦ì§}ªÅ¶¡ªºÅܼơA¤Ï¤§¥çµM¡C¦Ò¼{·í«È¤áºÝ°õ¦æ¤U¦Cµ{¦¡½X·|µo¥Í¦ó¨Æ¡G
Dim x As New MyServer.MyClass, value As Long value = 1234 x.MyMethod value
·í±z§Q¥Î¶Ç§}¶Ç»¼¤@ÓÅܼơA©I¥sªºµ{§Ç·|±µ¦¬¨ìÅܼƪº¦ì§}¡CµM«á³oÓ¦ì§}±µ¦¬©Î¬O¥i¯àקï³oÓÅܼơCµM¦Ó¡A·í©I¥s°_·½©ó¥t¤@Ó³B²z§Ç¡A©I¥sªºµ{§Ç±N¥i¯àµLªk¦s¨úÅܼƪºÈ¡A¦]¬°ÅܼƦì©ó¥t¤@Ó¦ì§}ªÅ¶¡¨Ã¥B©Ò¦¬¨ìªº¦ì§}¹ï©óµ{§Ç¨Ó»¡¨S¦³¤°»ò·N¸q¡C¦ý¬O±zª¾¹D¶Ç»¼¤@ÓÅܼƨì¤@Ó¸ó³B²z§Ç¦øªA¾¹¡A¹ê»Ú¤W¥i¥H¥¿±`¤u§@¡A©Ò¥H¦p¦¹n·PÁ COM marshaling¡Cn¸Ô²Óªº¸ÑÄÀ marshaling ¦p¦ó¤u§@¶W¥X¤F¥»®Ñªº½d³ò¡A¦ý¬O¤U¦Cªº¸ÑÄÀ¨¬¥Hº¡¨¬§Ú̪º¥Øªº¡C(¨£¹Ï16-6¡C)
¡@
¹Ï16-6 COM marshaling ¦p¦ó¤u§@ |
·í±z»P ActiveX EXE ¤¸¥ó¤@°_¤u§@®É¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^¤~¬O¥²nªº¡C¦]¬°¦P³B²z§Ç¤¸¥ó¬O¦b«È¤áºÝªº¦ì§}ªÅ¶¡°õ¦æ¡A¥¦Ì¥i¥Hª½±µªº¦s¨ú¥H¤Îקï©Ò¦³«È¤áºÝªºÅܼơC³o»¡©ú¤F¬°¦ó ActiveX DLL ¤¸¥ó¸û¸ó³B²z§Ç¤¸¥ó§Ö¤W³\¦h¡C
¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^ªº§Þ³N¬O«Ü½ÆÂøªº¡CÁ|¨Ò¨Ó»¡¡A¦pªG¤@ӰѼÆÈ¥H¶Ç§}¶Ç»¼¡Astub ¦b¦øªA¾¹ªº¦ì§}ªÅ¶¡«Ø¥ß¤@ӼȦsªº°Ñ¼ÆȨåB¶Ç»¼³oÓÅܼƪº¦ì§}µ¹¤©¤èªk¡C¦p¦¹¤èªk¤¤ªºµ{¦¡½X¥i¥H¦s¨ú¥H¤Î§ó§ï¦¹ÅܼÆÈ¡C·í¤èªk¶Ç¦^®É¡]returns¡^¡Astub Ū¨ú·sªºÅܼÆÈ¡A¥]¸Ë°_¨Ó¡A¨Ã¥B¶Ç¦^¥N²z¦øªA¾¹¼Ò²Õ¡A¥N²z¦øªA¾¹¼Ò²Õ±Nì¨Ó°O¾ÐÅé¦ì¸m¤¤ªºÅܼÆȥηsªºÈ´À´«¡C
°£¤F¤¹³\¸ê®Æ¥æ´«¤§¥~¡A¥~³¡°Ñ¼Æ¶Ç»¼¡]Marshaling¡^§Þ³N«P¨Ï¤F¡ulocation transparency¡vªº·§©À¡A¡ulocation transparency¡v¬O¤¸¥óªº¥»½è¡C«È¤áºÝªºµ{¦¡½X¤£»Ýnª¾¹D¦øªA¾¹ªº¦ì§}¡A¦P®É¦øªA¾¹¤]¤£»Ýnª¾¹D¦ó³B¥¿¦b©I¥s¡C¨Æ¹ê¤W¡A¤¸¥ó¤¤¦P¼Ëªº¤èªk¥i¥H³Q¥~³¡©Î¬O¤¸¥ó¤º³¡¥»¨©I¥s¡A¨Ã¥B³o¨âºØ¤è¦¡³£±N¥H¬Û¦Pªº¤è¦¡¤u§@¡C
¡ulocation transparency¡vªº·§©À¬O«Ü«nªº¡A¦]¬°¡ulocation transparency¡v«OÃÒ·íª«¥ó³Æ³¡¸p¦bºô¸ô¤W»·ºÝªº¹q¸£¤W¡Aª«¥ó¥i¥HÄ~Äò¤u§@¡C¦b³oºØ±¡ªp¤U¡A¥N²z¦øªA¾¹©M stub ¼Ò²Õ¶¡ªº³q°T§ó¥[½ÆÂø¦]¬°»Ýn¨Ì¿à RPC¡]Remote Procdure Call¡^¥H«K¦b¦U¹q¸£¶¡¤u§@¡C¦ý¬O COM ³B²z¤F©Ò¦³ªº°ÝÃD¡C±z«È¤áºÝ¥H¤Î¦øªA¾¹ªºÀ³¥Îµ{¦¡±N¦p¥H«e¤@¯ëªº¤u§@¡C
²³æªº¸ê®Æ«¬ºA
¡@
n¥¿½Tªº¨Ï¸ê®Æ¶Ç¥X¥H¤Î¶Ç¤J¡ACOM ¦³¸q°Èª¾¹D¸ê®ÆÀx¦sªº®æ¦¡¡C¥H Visual Basic Strings ¨ÓÁ|¨Ò¡R·í«È¤áºÝ¶Ç»¼¤@Ó string µ¹¤@¤èªk¡A¹ê»Ú¤W¬O¶Ç°e¤@Ó«ü¨ì¹ê»Ú¸ê®Æªº 32bit «ü¼Ð¡C¥N²z¦øªA¾¹¤¤ªº¤èªkª¾¹D±µ¦¬¨ì¤@Ó string ¦]¦¹¥i¥H¿h¨£¨ì«È¤áºÝªº¦ì§}ªÅ¶¡¥H±µ¦¬¹ê»Úªº¦r¤¸¸ê®Æ¡C
©Ò¦³ Visual Basic ²³æ¸ê®Æ«¬ºA³£»P COM ©Ò¯à³B²zªº¸ê®Æ¬Û®e¡C³oªí¥Ü¤@Ó¦øªA¾¹¥i¥H¶Ç¦^«È¤áºÝ¥ô¦óªº numeric¡Bstring ©Î¬O Variant value¡C±q Visual Basic 6 ¶}©l¡A¤@Ó¦øªA¾¹¥i¥H¶Ç¦^¥ô¦ó«¬ºAªº°}¦C¡C¡]¥H Visual Basic ¤§«eªºª©¥»©Ò¼gªº¦øªA¾¹¥u¯à¶Ç¦^¦s¦b Variants ªº°}¦C¡C¡^
¥H Visual Basic 4 ©Î¬O 5 ©Ò½sĶªº¤¸¥ó¤£¯à¶Ç¦^¨Ï¥ÎªÌ¦Ûq«¬ºA¡]UDT¡^¨ì«È¤áºÝ¡CVisual Basic 6 ¤¹³\¤¸¥ó¶Ç°e¤@Ó¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v¡A¦¹¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v¬On©w¸q¦b Public Ãþ§O¤¤¨Ã¥B±z»Ýn¦w¸Ë DCOM98 ©Î¬O¦b Windows NT 4 ¤¤¦w¸Ë Service Pack 4¡C¦w¸Ë Windows 98 ·|¦Û°Ê¦w¸Ë DCOM98¡C§Y¨Ï¦b¼g§@ªº¦P®É Windows 2000 ÁÙ¨S¦³µo¦æ¡A´Á±æ Windows 2000 ¤£»Ý¦w¸Ë¥ô¦ó Service Pack ´N¤ä´©¦¹¶µ¯S¦âÀ³¬O¦X²zªº¡C¤£n§Ñ°O DCOM98 ©Î¬O Service Pack 4 ¤]¥²¶·¦w¸Ë¦b±zÅU«Èªº¹q¸£¤W¡C¦pªG¨S¦³¦w¸Ë¡AVisual Basic ·|²£¥Í¤@Ó°õ¦æ¿ù»~ 458¡A¡u Variable uses an Automation Type not supported in Visual Basic.¡v¡C±zÀ³¸Ó§ì¦í¦¹¿ù»~°T®§¨Ã¥BÅã¥Ü¤@ӧ󦳷N¸qªº°T®§µ¹±zªº¨Ï¥ÎªÌ¡A¨Ò¦p«Øij¥LÌÀ³¸Ó¤É¯Å¥L̪º§@·~¨t²Î¥H¤ä´©¦¹¶µ¯S¦â¡C
¦]¬°¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v¥²¶·©w¸q¦b¤@Ó Pubic Ãþ§O¤¤¡A©Ò¥H±z¤£¯à¶Ç»¼©w¸q¦b«È¤áºÝªº¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v¨ì¦øªA¾¹¡A°£«D«È¤áºÝ¬O¤@Ó ActiveX EXE µ{¦¡¥»¨¡C³Ì«á¡Aª`·N¨ì DCOM98 ©Î¬O Service Pack 4 ¥u¦³¦b±zªº¤¸¥ó¶Ç»¼¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v°Ñ¼Æµ¹¸ó³B²z§Ç¦øªA¾¹®É¤~»Ýn¡C·í±z»P ActiveX DLL ¤@°_¤u§@®É¡A¤£·|¦³¥~³¡°Ñ¼Æ¶Ç»¼¡]marshaling¡^µo¥Í¨Ã¥B¤£½×¦b Windows 95 ©Î¬O Windows NT 4 ¨t²Î¤W¡u¨Ï¥ÎªÌ¦Ûq«¬ºA¡v³£¥i¥H¶Ç¦^«È¤áºÝ¡C
Private ¥H¤Î Publicª«¥ó
¡@
¤@Ó¦øªA¾¹¥H¤Î¤@ӫȤáºÝ¥i¥H¬Û¤¬¶Ç»¼ Public ª«¥ó¡C¨ä¤¤¥]§t©w¸q¦b¦øªA¾¹ªºª«¥ó¥H¤Î¥~³¡µ{¦¡®w©Ò´£¨Ñªºª«¥ó¡A¨Ò¦p Microsoft Word ©Î¬O Microsoft Excel ª«¥óµ{¦¡®w¡C
µ§ªÌ±N·|µy·L²`¤J´yzÃö©óª«¥ó¥~³¡°Ñ¼Æ¶Ç»¼¡]marshaling¡^ªº²Ó¸`¡C°£¤F¦b±M®×¤¤ªºÃþ§O¼Ò²Õ¤¤©Ò©w¸qªºª«¥ó¤§¥~¡A¤@Ó Visual Basic À³¥Îµ{¦¡³B²z¤TÓµ{¦¡®w©Ò´£¨Ñªºª«¥ó¡GVisual Basic¡BVBA ¥H¤Î VBRUN µ{¦¡®w¡C³o¤TºØµ{¦¡®w¦bª«¥óªºÅã¥Ü¤W¬Ý°_¨Ó¦ü¥G¤@¼Ë¡]¦ý¬O¥¦Ì¬O¤£¦Pªº¡^¡C
©Ò¦³¥Ñ Visual Basic ©Ò´£¨Ñªºª«¥ó¹ï©ó´£¨Ñªºµ{¦¡®w³£¬O private¡A©Ò¥H¤£¯à¶Ç»¼µ¹¨ä¥L¨ä¥LªºÀ³¥Îµ{¦¡¡]Á|¨Ò¨Ó»¡¡Aªí³æª«¥ó¡BApp ª«¥ó¡A¥H¤Î©Ò¦³¤º«Ø±±¨î¶µ¡C¡^¡AÁa¨Ï¨ä¥LªºÀ³¥Îµ{¦¡¬O¥Ñ Visual Basic ©Ò¼gªº¡CÁ|¨Ò¨Ó»¡¡A°²¦p¦b±zªº¦øªA¾¹¤¤¦³¤@ Public Ãþ§O¥]§t¤U¦Cµ{¦¡½X¡G
¡¥This function can't appear in a Public class module. Function CurrentForm() As Form Set CurrentForm = Form1 End Function
½sĶ¾¹·|©Úµ´°õ¦æ³oÓÀ³¥Îµ{¦¡¡C¬Û¤Ï¦a¡A¥Ñ VBA ¥H¤Î VBRUN µ{¦¡®w©Ò´£¨Ñªºª«¥ó¬O Public ªº¡A©Ò¥H¥i¥H¦b¤£¦Pªº³B²z§Ç¤§¶¡¶Ç°e¡C³o¸Ì¥]§t¤F ErrObject ¥H¤Î Collection ª«¥ó¡]¦bVBAµ{¦¡®w¤¤¡^¡C
³\¦hµ{¦¡³]p¤Hûµo²{¤@ÓÄY«ªº¨î¡A¨º´N¬O¦b¦øªA¾¹©M«È¤áºÝ¤§¶¡¤£¯à¶Ç»¼¤@¯ëªºª«¥ó¡A¨Ò¦pªí³æ¥H¤Î±±¨î¶µ¡A¨Ã¥B§ä´M§ó§ïªº¤è¦¡¡C
§ó§ïªº¤è¦¡¹ê»Ú¤W¬O¦³ªº¡Q¥un¨Ï¥Î As Object ©Î¬O As Variant «Å§i¤èªkªº°Ñ¼Æ¥H¤Î¶Ç¦^È¥N´À©ú½Tªº«Å§iÃþ«¬¡G
¡¥In the MyClass public module of the MyServer ActiveX EXE project ¡¥Assumes that the project contains a Form1 form and a Text1 text box on it Function CurrentField() As Object Set CurrentField = Form1.Text1 End Function ' In the client project Dim x As New MyServer.MyClass Dim txt As Object Set txt = x.CurrentField txt.Text = "This string comes from the client"
«È¤áºÝªºÀ³¥Îµ{¦¡«Å§i¤@Ó¤@¯ëªº As Object ÅܼƱµ¦¬CurrentField ¤èªk©Ò¶Ç¦^ªºµ²ªG¡A·N«ä¬O±zn°µ±ß´Á³sµ²¡C¦p¦P±z©Òª¾¹Dªº¡A±ß´Á³sµ²¯Ê¥F®Ä²v¨Ã¥BµLªkÅý±z¨Ï¥Î WithEvents ÃöÁä¦r¡C
¨Ï«È¤áºÝÀ³¥Îµ{¦¡¨Ï¥Î¯S©wªºª«¥óÅܼƫŧiª«¥ó¹ï©ó¦P³B²z§Ç ActiveX ¦øªA¾¹¨Ó»¡¬O¤ñ¸û¦nªº¨Æ¡C¦ý¬O±zÀ³¸Óª`·N¨ì¥Î¦¹¤èªk«Ø¥ßªº DLLs ¦b¬Y¨Ç±¡ªp¤U¥i¯àµLªk¥¿±`ªº¤u§@¡A©Ò¥H°í«ù¨Ï¥Î As Object ÅܼƳq±`¬O¦X²zªº¡A§Y¨Ï¬O»P¦P³B²z§Ç¤¸¥ó¤@°_¤u§@¡C¦P®É½Ð¤£n§Ñ°O¥u¦³¦b«È¤áºÝªºÀ³¥Îµ{¦¡¬O¥H Visual Basic ¼¶¼g®É¤~¯à¨Ï¥Î³oºØ¤èªk¡C
²{¦bµ§ªÌ¤w¸g§i¶D±z§ó§ïªº¤è¦¡¡Aªþ¥[¤@ÂI¡A´N¬O Microsoft ©ú½T¦a¤£¤¹³\³oÓ§Þ¥©¡A¨Ã¥Bĵ§i¦b¤§«áªº Visual Basic ª©¥»¤¤¥i¯à¤£¯à°õ¦æ¡C©Ò¥H¨Ï¥Î³oÓ¤èªkn¦Û¦æt³d¡C
³oÓ°ÝÃD¤]²£¥Í¤@Ó¦³½ìªº°ÝÃD¡R«È¤áºÝªºÀ³¥Îµ{¦¡¦p¦ó¦s¨ú¦ì©ó¦øªA¾¹À³¥Îµ{¦¡ªºªí³æ¥H¤Î±±¨î¶µ?µª®×¬O«È¤áºÝÀ³¸Ó±q¨Ó¤£·|ª½±µ¦s¨ú¦øªA¾¹ªº Private ª«¥ó¡A¦]¬°³o¼Ë·|¯}Ãa¤¸¥óªº«Ê¸Ë©Ê¡C¦pªG«È¤áºÝ»Ý¼Ë¨Ï¥Î¦øªA¾¹ªº private ª«¥ó¡A¦øªA¾¹À³¸Ó¹ê§@¥X¤@¨Ç¥Î¨Ó´£¨Ñ½Ð¨Dªº¤èªk¥H¤ÎÄÝ©Ê¡AÁ|¨Ò¨Ó»¡¡R
Property Get CurrentFieldText() As String CurrentFieldText = Form1.Text1.Text End Function Property Let CurrentFieldText(newValue As String) Form1.Text1.Text = newValue End Property
ª`·NFriend ¤èªk¥H¤ÎÄݩʤ£·|¥X²{¦b¤¸¥óªº Public ¤¶±¤¤¡A©Ò¥H¤£¯à³Q¥~¦bªº±M®×©Ò©I¥s¡C¦]¦¹¡A¥¦Ì¤£»Ýn¥~³¡°Ñ¼Æ¶Ç»¼¡]marshaling¡^¡A¨Ã¥B±z¥i¥H¶Ç»¼¤@Ó Private ª«¥ó©Î¬O¤@ӨϥΪ̦Ûq«¬ºA·í§@¬O Friend ¦¨ûªº°Ñ¼Æ©Î¬O¦^¶ÇÈ¡C
»¡©ú
¤£n§Ñ°O·í±z¦b¥~³¡°Ñ¼Æ¶Ç»¼¡]marshal¡^¤@Óª«¥ó¡A¹ê»Ú¤W¥¿¶Ç»¼¤@ӤޥΡA¦Ó¤£¬Oª«¥ó¥»¨¡C·í«È¤áºÝ¨Ï¥Î³oÓª«¥óªº¤èªk¥H¤ÎÄݩʪº®ÉÔ¡A³o¨Ç¤èªk¥H¤ÎÄݩʪº¹ê»Úµ{¦¡¬O¦b¤¸¥ó¤¤°õ¦æ¡C³oÓ¯S©Ê¬O«Ü«nªº¡A¦]¬°¨C¤@¦¸«È¤áºÝ¨Ï¥Îª«¥óÅܼƮɡA´N·|µo¥Í¤@Ө컷ºÝª«¥óªº¨Ó¦^®Èµ{¡C
Ãþ«¬µ{¦¡®w
¡@
±z¥i¯à·|¯Ç´e COM ¬O¦p¦ó«Ø¥ß¥N²z¦øªA¾¹¥H¤Î Stub ¨ÓÅý«È¤áºÝ©M¦øªA¾¹Ápô¡Cµª®×´N¦bÃþ«¬µ{¦¡®w¤¤¡AÃþ«¬µ{¦¡®w¶°¦X¤F¤¸¥ó´£¨Ñªº Public Ãþ§Oªº©Ò¦³¦³Ãö¸ê°T¡A¥]§t¤FÓ§O¤èªkªº»yªk¡BÄÝ©Ê¥H¤Î¨Æ¥ó¡CÃþ«¬µ{¦¡®w³q±`Àx¦s¬°°ÆÀɦW¬° TLB ©Î¬O OLB ªºÀɮסA¦ý¬O¥¦¤]¥i¥H´O¦b¤¸¥ó¥»¨ªº EXE¡BDLL ©Î¬O OCX Àɮפ¤¡CÁ|¨Ò¨Ó»¡¡AVisual Basic ½s¼gªº¤¸¥óªºÃþ«¬¨ç¼Æ®wÀx¦s¦b¤¸¥óªº EXE ©Î¬O DLL Àɮפ¤¡C
¦pªG¤@Ó¤¸¥ó¾Ö¦³Ãþ«¬µ{¦¡®w¡A±z´N¥i¥H¦b¤Þ¥Î¹ï¸Ü¤è¶ô¤¤¿ï¨ú¨Ã¥B¨Ï¥Îª«¥óÂsÄý¾¹¬d¸ß¡C¤Þ¥Î¹ï¸Ü¤è¶ô¦C¥X©Ò¦³ªº¤w¸gµù¥U¦bµn¿ý¸ê®Æ®w¤¤ªºÃþ«¬¨ç¼Æ®w¡C¦pªG±z¦³¤@ÓÃþ«¬¨ç¼Æ®w©|¥¼µù¥U¡A±z¥i¥H«ö¤U ÂsÄý ±Nª«¥ó¥[¤Jµn¿ý¸ê®Æ®w¤¤¡C
¤@¯ë¦Ó¨¥¡A±z¤£¥Î±Nª«¥ó¥[¤J¤Þ¥Î¹ï¸Ü¤è¶ô´N¥i¥H¨Ï¥Îª«¥ó¡A¦ý¬O±z¥²¶·¨Ï¥Î CreateObject ¨ç¼Æ«Ø¥ßª«¥ó¨Ã¥B¥u¯à³z¹L¤@¯ëªº As Object ÅܼƤޥΡC¨Æ¹ê¤W¡A¨S¦³Ãþ«¬¨ç¼Æ®w¡AVisual Basic «K¨S¦³¨¬°÷ªº¸ê°TÅý±z«Å§i¤@Ó¯S©wªºª«¥óÅܼơA©Ò¥H±z³Q¨î¦b¨Ï¥Î±ß´Á³sµ²¡Cn¨Ï¥Î¯S©wªºÅܼơ]¦´Á³sµ²¡^¡BNewÃöÁä¦r¥H¤Î IntelliSense¡A±z¥²¶·§â¦øªA¾¹ªºÃþ«¬¨ç¼Æ®w¥[¨ì¤Þ¥Î¦Cªí¤¤¡C
¤p¯µ³Z
Visual Basic ¥i¥H«Ø¥ß³æ¤@ªºÃþ«¬¨ç¼Æ®w¡A¦ý¬O±z»Ýn¥ø·~ª©ªº Visual Basic¡Cn»â¬O²³æªº¡A¦b±M®×Äݩʹï¸Ü¤è¶ô¡vªº¤¸¥ó¶ÅÒ¤¤¡A®Ö¨ú»·ºÝ¦øªA¾¹ÀɮסAµM«á«·s½sĶ±M®×¡CVisual Basic ²£¥Í¤@Ó»P±M®×¦WºÙ¬Û¦Pªº TLB ÀɮסC
®Ä¯à«Øij
¡@
²{¦b±zª¾¹D¨ì¸ê®Æ¦p¦ó¦b«È¤áºÝ¥H¤Î¦øªA¾¹¤§¶¡§@¥~³¡°Ñ¼Æ¶Ç»¼¡A±z¥i¥H¤F¸Ñ¤@¨Ç¥©§®ªº§Þ¥©¥H¼W¶i±z ActiveX EXE ¤¸¥óªº®Ä¯à¡C
¤@Ó«D±`¦³®Äªº«Øij´N¬O±zÀ³¸Ó¦b«Å§i¤èªkªº°Ñ¼Æ®É¦h¨Ï¥Î ByVal ¥N´À ByRef ¡]°£«Dµ{§Ç¹ê»Ú¤Wn§ó§ï°Ñ¼ÆÈ¥H¤În¶Ç¦^«È¤áºÝ¡^¡C¶ÇȰѼƤ£·|¥H¥~³¡°Ñ¼Æ¶Ç»¼ªº¤è¦¡¶Ç¦^«È¤áºÝ¦]¬° COM ª¾¹D¦b©I¥s´Á¶¡ÅܼÆȤ£¯à§ó§ï¡C
²z·Qªºª¬ªp¬O·í±z©I¥s¤@Ó Sub µ{§Ç®É¡A±N©Ò¦³ªº°Ñ¼Æ«Å§i¬° ByVal¡A ¦]¬°¦b³oºØ±¡ªp¤U¨S¦³¸ê®Æ·|¶Ç¦^«È¤áºÝ¡A·í¶Ç°eªø¦r¦ê®É±z¥i¯à·|¦³³Ì¨ÎÅé»{¡CÁ|¨Ò¨Ó»¡¡Aµ§ªÌµoı§Q¥Î ByVal «Å§iªº¦r¦ê¶Ç»¼³t«×¤ñ§Q¥Î ByRef.«Å§i§Ö¤W¬ù¦Ê¤À¤§¤G¤Q¡C
¸ó process ªº©I¥s¥»½è¤W´NºC¡C©I¥s¤@Ó¥|ӰѼƪº¤èªk´X¥Gn¤ñ³]©w¥|ÓÄݩʺC¥|¿¡C¦]¦¹¡A±zªº¦øªA¾¹À³¸Ó´£¨ÑÅý«È¤áºÝ§Ö³t³]©w¥H¤Î¦s¨úÄݩʪº¤èªk¡CÁ|¨Ò¨Ó»¡¡A±zªº¦øªA¾¹´£¨Ñ Name¡BAddress¡BCity ¥H¤Î State ÄÝ©Ê¡C°£¤F´£¨Ñ¤@¯ëªºÄݩʳ]©wµ{§Ç¥H¥~¡A±z¥i¥H¼W¥[¤U¦C GetProperties ¥H¤ÎSetProperties ¤èªk¡G
' In the MyClass module of the MyServer project Public Name As String, Address As String Public City As String, State As String Sub SetProperties(Optional Name As String, Optional Address As String, _ Optional City As String, Optional State As String) If Not IsMissing(Name) Then Me.Name = Name If Not IsMissing(Address) Then Me.Address = Address If Not IsMissing(City) Then Me.City = City If Not IsMissing(State) Then Me.State = State End Sub Sub GetProperties(Optional Name As String, Optional Address As String, _ Optional City As String, Optional State As String) If Not IsMissing(Name) Then Name = Me.Name If Not IsMissing(Address) Then Address = Me.Address If Not IsMissing(City) Then City = Me.City If Not IsMissing(State) Then State = Me.State End Sub
¦]¦¹«È¤áºÝªºÀ³¥Îµ{¦¡¥i¥H¨Ï¥Î¤@¦æµ{¦¡´N³]©w¥H¤Î¦s¨ú©Ò¦³ªºÄÝ©Ê¡]©Î¬O¨ä¤¤ªº¤@³¡¥÷¶°¦X¡^¡C
'Set all properties in one statement. Dim x As New MyServer.MyClass x.SetProperties "John Smith", "1234 East Road", "Los Angeles", "CA" ' Read just the City and State properties. Dim city As String, state As String x.GetProperties city:=city, state:=state
±z¥i¥H¨Ï¥Î«ü©w¦WºÙÅܼƤj¤j¼W¥[µ{¦¡ªº¥iŪ©Ê¡A¦p¦P«e±ªºµ{¦¡¤ùÂ_¤@¯ë¡C
¨ä¥L¥L¸Ñ¨M¸ó process ªº©I¥sªº¤èªk¬O§Q¥Î°}¦C¶Ç»¼©Ò¦³ªº°Ñ¼Æ¡C±z¥i¥H¨Ï¥Î Variants °}¦C¡A¦]¬°¥¦Ì¥i¥H¶Ç»¼¤£¦PÃþ«¬ªº°Ñ¼ÆÈ¡C·íµM¡A«È¤áºÝ©M¦øªA¾¹³£¥²¶·¦P·N¶Ç»¼°}¦C¤¤ªº¸ê®Æ·N¸q¡C
·í±z¤£ª¾¹D±zn¶Ç»¼¦h¤Ö¸ê®Æ¶µ¥Øµ¹¦øªA¾¹®É¡A³o¬O³Ì¦³®Ä²vªº³B²z¤è¦¡¡CÁ|¨Ò¨Ó»¡¡A°²³]¦øªA¾¹´£¨Ñ¤@Ó Public ¶°¦XÃþ§O¡A¾Ö¦³¤@¯ëªº Add¡BRemove¡BCount ¥H¤Î Item ¤èªk¡C±z¥i¥H¦Ò¼{´£°ª³oÓÀ³¥Îµ{¦¡ªº®Ä²v¡A¦pªG±z´£¨Ñ¤@Ó AddMulti ¤èªk¡A¦¹¤èªk¨C©I¥s¤@¦¸¥i¥H¥[¤J¤@Ó¥H¤Wªº¶µ¥Ø¡G
' In the MyCollection modules of the MyServer project Private m_myCollection As New Collection Sub AddMulti(values As Variant) Dim v As Variant For Each v In values m_myCollection.Add v Next End Sub
ª`·N¨ì values °Ñ¼Æ«Å§i¬° Variant ¥N´À«Å§i¦¨ Variants ªº°}¦C¡A¦p¦P±z©Ò¹w´Áªº¡Aµ{§Ç§Q¥Î¤@Ó For Each...Next °j°é«½Æ¦a¿é¤J¦¨û¡C³oµ¹¤©¦¹¤èªkµL¤ñªº¼u©Ê¡A¦]¬°±z´X¥G¥i¥H¶Ç»¼¥ô¦óªF¦è¡GStrings ªº°}¦C¡BVariants ªº°}¦C¡Bª«¥óªº°}¦C¥H¤Î¥]§t Strings °}¦Cªº Variant¡BVariants¡Bª«¥ó¬Æ¦Ü¬O¤@Ó¶°¦X¡G
' In the client application Dim x As New MyServer.MyCollection ' Pass an array of Variants built on the fly. x.AddMulti Array("First", "Second"," Third")
¬Û¦P¦a¡A¦pªG«È¤áºÝªºÀ³¥Îµ{¦¡»Ýn¦s¨úÀx¦s¦b MyCollection ¼Ò²Õ¤¤©Ò¦³ªºÅܼÆÈ¡A±z¥i¥H¹ê§@¤@Ó§Q¥Î Variants °}¦C¶Ç¦^©Ò¦³¶°¦X¤¤ªº¶µ¥Øªº¤èªk¨Ó´£°ª®Ä²v¡G
Function Items() As Variant() Dim i As Long ReDim result(1 To m_myCollection.Count) As Variant For i = 1 To m_myCollection.Count ' Object values require the Set command. If IsObject(m_myCollection(i)) Then Set result(i) = m_myCollection(i) Else result(i) = m_myCollection(i) End If Next Items = result End Function
±z¥i¥H°Ñ¦Ò Dictionary ª«¥ó¨ÓÅý¦øªA¾¹ªº¤¶±§ó¦³®Ä²v¥B´£¨Ñ§ó¦nªº®Ä¯à¡C¡]¨£²Ä¥|³¹
¡qDictionary Objects¡r ¡^³Ì«á¡A±z¥i¥H§Q¥Î¦b¤¸¥ó¤¤«Å§i¬° Public ªº¨Ï¥ÎªÌ¦Ûq«¬ºA¦b«È¤áºÝ¥H¤Î¦øªA¾¹¤§¶¡¶Ç»¼¸ê®Æ¡C
¿ù»~³B²z
¡@
¦b COM µ{¦¡³]p¤¤±z¥²¶·n°µªº«Ü«nªº³¡¤À´N¬O¿ù»~³B²z¡C·íµM¡A¿ù»~³B²z¤@ª½³£¬O«nªº¡A¦ý¬O·í±z¼¶¼g ActiveX ¤¸¥ó®É¡A±z¥²¶·¥¿½T¦a¦Ò¼{¨ì©Ò¦³¤£¥i¹w´Áªº¿ù»~¡C
¦øªA¾¹¤¸¥ó¤¤ªº¿ù»~³B²z
¡@
¤¸¥ó¤¤²£¥Íªº¿ù»~¦p¦P¦b¤@¯ëªºµ{¦¡¤¤µo¥Íªº¿ù»~¤@¼Ë¡F¦pªG¥Ø«eªºµ{§Ç¨S¦³¥D°Êªº¿ù»~³B²z¾÷¨î«OÅ@¡A«hµ{§Ç·|ª½±µÂ÷¶}¨Ã¥B±N±±¨îÅv¶Ç¦^µ¹©I¥sªÌ¡C¦pªG©I¥sªÌ¤]¨S¦³¿ù»~³B²z¾÷¨î¡A±±¨îÅv·|¦A¶Çµ¹¥Ø«eµ{§Çªº©I¥sªÌ¡A±±¨îÅv¤@ª½¶Ç¤U¥h¡Aª½¨ìÀ³¥Îµ{¦¡¹J¨ì¾Ö¦³¿ù»~³B²z¾÷¨îªº©I¥sµ{§Ç¡A©Î¬O¤@ª½¨ì¨S¦³©I¥sªºµ{§Ç¬°¤î¡C¡]´N¬O¨ì¹F³Ì³»ºÝªºµ{§Ç¨Ã¥B¿ù»~¨S¦³³Q±µ¦¬¡C¡^¦b³Ì«áªº¨Ò¤l¤¤¡A¿ù»~¬O«D±`ÄY«ªº¡A¨Ã¥BÀ³¥Îµ{¦¡·|²×¤î¡C
¦b¤¸¥ó¤¤ªºÄÝ©Ê¥H¤Î¤èªk¤@ª½·|¦³¤@Ó©I¥sªÌ´N¬O«È¤áºÝÀ³¥Îµ{¦¡¡A©Ò¥H´N¬Y¤è±¨Ó»¡µ{§Ç¤¤ªºµ{¦¡½X¨ü¨ì«OÅ@¦Ó¤£¦Ü©ó²£¥Í¡uP©R©Ê¿ù»~¡v¡A¦]¬°©Ò¦³ªº¿ù»~³£·|¶Ç¦^«È¤áºÝ¡C¨Æ¥óµ{§Ç¬O³oÓ³W«h¤¤ªº¨Ò¥~¡A¦]¬°¥¦¨S¦³ª½±µªº©I¥sªÌ¡A©Ò¥H±zÀ³¸Ó½T©w¦b Class_Initialize ¥H¤Î Class_Terminate ¨Æ¥óµ{§Ç¤¤¤£·|µo¥Í¿ù»~¡C
Áa¨Ï¤èªk¥H¤Îµ{§Ç¤¤ªº¿ù»~·|¶Ç¦^«È¤áºÝ¡A¤@Ó¦nªºµ{¦¡³]p¤Hûn¯à°÷¥ý±±¨î³o¨Ç¿ù»~¡C°ò¥»¤W¡A±z¥i¥H±Ä¥Î¤U¦C¤TºØµ¦²¤¤§¤@¡G
·í¶Ç¦^¤@Ó¦Ûq¿ù»~µ¹«È¤áºÝ®É¡A±z¥i¥H¦b¿í´` COM ªº«ü¾É¤â¥U¨Ó³B²z¥¦¡C®Ú¾Ú³o¼Ëªº»¡©ú¤å¥ó¡A©Ò¦³ªº¦Ûq¿ù»~½Xªº½d³òÀ³¸Ó¦b 512 ¨ì 65535¡A¦p¦¹¤~¤£·|»P COM ¥»¨ªº¿ù»~½X²V²c¡A¨Ã¥BÀ³¸Ó¥[¤W¤Q¤»¶i¦ìªºÈ &H80040000¡]©Î¬O -2,147,221,504¡^¡CVisual Basic ¹ï©ó³oÓÈq©w¤F¤@ӲŸ¹±`¼Æ¡AvbObjectError¡A©Ò¥H¦b ActiveX ¦øªA¾¹¤º¤@Ó°ò¥»ªº Visual Basic ¿ù»~³B²z¾÷¨î¥i¯àÃþ¦ü¤U±ªºµ{¦¡½X¡G
Function Evaluate() As Double On Error GoTo ErrorHandler ' Open an initialization file (omitted). ' ... ' Evaluate the result. (This is just a sample expression.) Evaluate = a * b(i) / c Exit Function ErrorHandler: Select Case Err Case 6, 11 ' Overflow or division-by-zero error Err.Raise Err.Number ' can be returned to clients as is. Case 53 Err.Raise 1001 + vbObjectError, , _ "Unable to load initialization data" Case Else 'It's always good to provide a generic error code. Err.Raise 1002 + vbObjectError, , "Internal Error" End Select End Function
¤£½×±z¨M©w±Ä¨ú¦óºØµ¦²¤¡A¦³¤@¥ó¨Æ¬O±zµ´¹ï¤£À³¸Ó°µªº¡A¨º´N¬OÅã¥Ü¤@Ó¹ï¸Ü¤è¶ô¡C¤@¯ë¨Ó»¡¡A¤¸¥óÀ³¸Ó©e°U¿ù»~µ¹«È¤áºÝ¨Ã¥BÅý«È¤áºÝ¨M©w¬O§_nÅý¨Ï¥ÎªÌ¤F¸Ñµo¥Íªº¿ù»~¡C±q¤¸¥ó¤ºÅã¥Ü¤@Ó¹ï¸Ü¤è¶ô¬O¤£¦nªºµ{¦¡³]p¡A¦]¬°³o¼Ë·|¨ÏÀ³¥Îµ{¦¡µLªk°õ¦æ»·ºÝªºª«¥ó¡C
¦b«È¤áºÝÀ³¥Îµ{¦¡ªº¿ù»~³B²z
¡@
¦b«È¤áºÝÀ³¥Îµ{¦¡¤¤ªº¤@Ó¥¿½Tªº¿ù»~³B²z¤ñ¦b¦øªA¾¹¤¤¨Óªº«n¡A¦]¬°¤j¦h¼Æªº¨Ò¤l¤¤«È¤áºÝ¨Ã¨S¦³©I¥sªÌ¥i¥H¨Ñ¨ä©e°U¿ù»~¡A©Ò¥H©Ò¦³ªº¿ù»~³£¥²¶·n¦b¦¹³B²z¡C§Y¨Ï±z¦³µ´¹ïªº§â´¤¦øªA¾¹¤£·|²£¥Í¿ù»~¡]Á|¨Ò¨Ó»¡¡A·í±z¥u¬O²³æ¦a¦s¨ú¤@ÓÄÝ©Ê¡C¡^¡Aµ§ªÌ±j¯P«Øij±zµL½×¦p¦óÁÙ¬On´£¨Ñ¿ù»~³B²z¾÷¨î¡Cì¦]¬O·í±z©M ActiveX ¤¸¥ó¤@°_¤u§@®É¡A±z¤]·|¥Ñ COM ¥»¨¾ÉP¿ù»~ªº²£¥Í¡C¤U±¦C¥X´X¶µ¥Ñ COM ²£¥Íªº¿ù»~¡C
³o¸Ì©Ò¦C¥Xªº¨Ã¤£¬O«Ü¸ÔºÉ¡A±zÀ³¸Ó¦b±zªº¿ù»~³B²z¾÷¨î¤¤°O¿ý¨ä¥L¥L¿ù»~¡CÁ`µ²¨Ó»¡¡A¦b«È¤áºÝÀ³¥Îµ{¦¡¤¤¨å«¬ªº¿ù»~³B²z¾÷¨îÀ³¸Ó°O¿ý¤TºØ¤£¦P¿ù»~µo¥Íªº¨Ó·½¡G¦øªA¾¹¡BCOM ¥H¤Î«È¤áºÝ¥»¨¡C©³¤U«K¬O¤@Ó¥i¯àªº Visual Basic «È¤áºÝªº¿ù»~³B²z¾÷¨î¡G
Private Sub cmdEvaluate() Dim x As New MyServer.MyClass' res As Double On Error GoTo ErrorHandler res = x.Evaluate() Exit Function ErrorHandler: Select Case Err Case 429 ' ActiveX can't create the component. MsgBox "Please reinstall the application", vbCritical End Case 430 ' Automation error MsgBox "Unable to complete the operation at this time." _ & "Please try again later.", vbCritical Case 462 ' The remote server machine is unavailable. MsgBox "Please ensure that the server machine " _ & " is connected and functioning", vbCritical Case 1001 + vbObjectError MsgBox "Please copy the file VALUES.DAT in the " _ & "application directory.", vbCritical Case 1002 + vbObjectError MsgBox "Unknown error. Please contact the manufacturer." _ ,VbCritical Case Else ' This might be a standard Visual Basic error or COM error. ' Do whatever is more appropriate for your application. End Select End Sub
¡u¤¸¥ó¦£¸L¡v¥H¤Î¡uÀÁ¸m¤¸¥óªº½Ð¨D¡v
¡@
¦p¦Pµ§ªÌ¤§«e©Ò´£¨ìªº¡ACOM ±N¨Ó¦Û«È¤áºÝªº©Ò¦³½Ð¨D´`§Ç¤Æ¡A©Ò¥H¦øªA¾¹¥i¥H¥Î¡u¥ý¶i¥ýªA°È¡vªº¤è¦¡³B²z©Ò¦³ªº½Ð¨D¡C¦ý¬O¦b¬Y¨Ç±¡ªp¤U¡ACOM ¤£¯à±µ¨ü«È¤áºÝªº½Ð¨D¡Q³o´NºÙ§@¤¸¥ó¦£¸L¡]component busy¡^¡CÁ|¨Ò¨Ó»¡¡A·í±zªºµ{¦¡§Q¥Î Microsoft Excel ·í§@¦øªA¾¹¡A¦Ó Excel ¥¿¦b®i¥Ü¤@Ó±j¨î¦^À³¡]modal¡^ªº¹ï¸Ü¤è¶ô®É¡A·|µo¥Í³o¼Ëªº±¡§Î¡C
Visual Basic °²³]³o¬O¤@ӼȮɩʪº°ÝÃD¦Ó¦Û°Ê¶¡¹j¦a«¸Õ¡C¦pªG°ÝÃD«ùÄò¥X²{¡AVisual Basic ·|Åã¥Ü¤@Ó ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô¡A¦p¹Ï16-7 ©Ò¥Ü¡C ¤Á´«¦Ü... «ö¶s±Ò°Ê¨ä¥L¨ä¥LªºÀ³¥Îµ{¦¡¨Ã¥B±N±Ò°Êªºµøµ¡±a¨ì©Ò¦³µøµ¡ªº³Ì¤W¼h¡A¦p¦¹±z¥i¥H§ï¥¿³oÓ°ÝÃD¡C¡]³oӿﶵ¹ï©ó¨S¦³¨Ï¥ÎªÌ¤¶±ªº ActiveX ¦øªA¾¹¨S¦³§@¥Î¡C¡^ «¸Õ «ö¶sÅý±z«¸Õ³oÓ¾Þ§@¤Q¬íÄÁ¡C³Ì«á¡A¦pªG±zÂI¨ú ¨ú®ø ªº«ö¶s¡A±zºM¾P¤F³o¶µ½Ð¨D¨Ã¤Þµo¤@Ó¿ù»~ &H80010001 (¤Q¶i¦ì -2,147,418,111)¶Ç¦^«È¤áºÝ¡C³o¬O¥t¤@Ó±z¥²¶·°O¿ý¦b¿ù»~³B²z¾÷¨îªº¿ù»~¡C
¡@
¹Ï16-7 ¡u¤¸¥ó¦£¸L¤¤¡v¹ï¸Ü¤è¶ô |
¥t¤@Ó¤£¦Pªº°ÝÃDµo¥Í¦b COM ±µ¨ü¤F«È¤áºÝªº½Ð¨D¡A¦ý¬O COM ±µ¨üªº½Ð¨D¤Ó¦h¥H¦Ü©ó³o¶µ½Ð¨DµLªk§¹¦¨¡CÁ|¨Ò¨Ó»¡¡A³o·|µo¥Í¦b·í¤¸¥óµ¥Ô¤@¶µ¬d¸ß§¹¦¨®É¡A©Î¬OÅã¥Ü¤@Ó°T®§¤è¶ô¨Ãµ¥Ô¨Ï¥ÎªÌÃö³¬¹ï¸Ü¤è¶ô¡C³o¨Ç°ÝÃD³y¦¨ÀÁ¸m¤¸¥ó½Ð¨D¡]component request pending¡^¡A¦øªA¾¹±`±`¦]¬°·N®Æ¤§¥~ªº¿ù»~°±¤î¡A¦Ó¦b°»¿ù¶¥¬q³oºØ¿ù»~¬O¬Û·í±`¨£¨ìªº¡C
¦]¬° COM ¤w¸g±µ¨ü¤F½Ð¨D¡AVisual Basic ¤£·|«·s»¼°e¤@¦¸¡C¦ý¬Oª½¨ì¤èªk¶Ç¦^µ²ªG¡A«È¤áºÝªºÀ³¥Îµ{¦¡¤w¸g¥¢®Ä¨Ã¥B¤£¯à±µ¨ü¨Ï¥ÎªÌªº¿é¤J¡C¤¬í¥H«á¡A¦pªG¨Ï¥ÎªÌ¸ÕµÛ»P«È¤áºÝÀ³¥Îµ{¦¡¥æ½Í¡A¤@Ó¦p¹Ï 16-8 ªº¹ï¸Ü¤è¶ô´N·|¥X²{¡C³oÓ¹ï¸Ü¤è¶ô»P ¤¸¥ó¦£¸L ¤¤¹ï¸Ü¤è¶ôÃþ¦ü¡A¦ý¬O ¨ú®ø ªº«ö¶s¤£¯à¨Ï¥Î¡A¦]¬°½Ð¨D¬O¤£¯à³QºM¾Pªº¡C
¡@
¹Ï16-8 ½Ð¨D³QÀÁ¸m®Éªº¡u¼È°±³B²z¤¸¥óªº½Ð¨D¡v¹ï¸Ü¤è¶ô |
¤@¨Ç Application ª«¥óªºÄݩʼvÅT¨ì³o¨Ç¹ï¸Ü¤è¶ôªº¦æ¬°¥H¤Îªí²{¡CApp.OLEServerBusyTimeout Äݩʬ°¦b¦h¤Ö²@¬í¤§«á·|¥X²{ ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô¡C¡]¹w³]Ȭ° 10000 ²@¬í¡^¡CApp.OLEServerBusyMsgText ¥H¤Î App.OLEServerBusyMsgTitle ÄÝ©ÊÅý±z³]©w¹ï¸Ü¤è¶ôªº¤º®e¥H¤Î¼ÐÃD¡C¦pªG±z³]©w«DªÅ¦r¦êµ¹¤©³o¨âÓÄÝ©Ê¡A¼Ð·Çªº ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô·|³Q¸m´«¦¨¤@Ó¥]§t ½T©w ¥H¤Î ¨ú®ø «ö¶sªº¤@¯ë°T®§¤è¶ô¡C±z¥i¥H±N App.OleServerBusyRaiseError Äݩʳ]©w¬° True ¨Ón¨D Visual Basic ¤£nÅã¥Ü ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô¡C¦b³oºØª¬ªp¤U¡A¤£·|Åã¥Ü¥ô¦ó°T®§¡A¦Ó¥B¿ù»~ &H80010001 ·|ª½±µ¶Ç¦^«È¤áºÝ¡C¡]³o¸ò¨Ï¥ÎªÌ«ö¤U ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô¤¤ªº ¨ú®ø «ö¶s©Ò²£¥Íªº¿ù»~¤@¼Ë¡^¡C
¦³¤@²Õ¬Û¦üªºÄÝ©Ê¥i¥HÅý±z¦Ûq ÀÁ¸m¤¸¥óªº½Ð¨D ¹ï¸Ü¤è¶ô¡GApp.OleRequestPendingTimeout¡]¹w³]ȬO 5,000 -¤]´N¬O¤¬í¡^¡AApp.OleRequestPendingMsgText ¥H¤Î App.OleRequestPendingMsgTitle¡C
·í±zªºÀ³¥Îµ{¦¡¬O»P»·ºÝ¤¸¥ó©¹¨Ó®É¡A¦Ûq ¤¸¥ó¦£¸L¤¤ ¹ï¸Ü¤è¶ô¥H¤Î ¼È°±³B²z¤¸¥óªº½Ð¨D ¹ï¸Ü¤è¶ô´N¯S§Oªº«n¡C¹w³]ªº¼È°±®É¶¡³q±`³£¤£°÷¡A©Ò¥H¹ï¸Ü¤è¶ô«Ü¥i¯à·|¥X²{¡C·í»P»·ºÝ¤¸¥ó¤u§@®É¡A ¤Á´«¦Ü... ªº«ö¶s¨S¦³§@¥Î¡A©Ò¥H±zÀ³¸Ó´£¨Ñ¤@Ó°T®§¦V¨Ï¥ÎªÌ¸ÑÄÀµo¥Í¤F¤°»ò¨Æ¡C
¥]§t¨Ï¥ÎªÌ¤¶±ªº¤¸¥ó
¡@
ActiveX EXE ¤@Ó¥DnªºÀuÂI´N¬O¨Ï¥ÎªÌ¥i¥H¦p¦P°õ¦æ¼Ð·Çªº Windows À³¥Îµ{¦¡¤@¯ëªº±Ò°Ê¤¸¥ó¡A³o¼Ë¼W¥[¤F³\¦h¼u©Ê¦ý¬O¤]»s³y¤F¤@¨Ç¤p¤pªº°ÝÃD¡C
¨M©w±Ò°Ê¼Ò¦¡
¡@
Á|¨Ò¨Ó»¡¡AÀ³¥Îµ{¦¡¥²¶·¨M©w¬O¨Ï¥ÎªÌ°õ¦æªº©Î¬O COM ¤l¨t²Î°õ¦æªº¡C¦b«eªÌªº¨Ò¤l¤¤¡AÀ³¸ÓÅã¥Ü¤@ӨϥΪ̤¶±¡A¸Ó¤¶±¥Ñ¸ü¤JÀ³¥Îµ{¦¡ªº¥Dªí³æ¨Ó¹F¦¨¡C¤@Ó ActiveX EXE¤¸ ¥ó¥i¥H¤À§O³o¨âºØª¬ªp¡A¥i¥H¦b Sub Main µ{§Ç¤¤ÂǥѬd¸ß App ª«¥óªº StartMode ÄݩʨӹF¦¨¡C
Sub Main If App.StartMode = vbSModeStandalone Then ' Being launched as a stand-alone program frmMain.Show Else ' StartMode = vbSModeAutomation 'Being launched as a COM component End If End Sub
¬°¤F¨Ï¤§«eªºµ{¦¡½X¥i¥H¤u§@¡A±zÀ³¸Ó¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤ªº ¤@¯ë ¶ÅÒ¤¤³]©w Sub Main ¬°±Ò°Êª«¥ó¡C¤@Ó©¾§i¡G·í¦øªA¾¹¥Ñ COM ±Ò°Ê¡AVisual Basic °õ¦æ Sub Main µ{§Ç¥H¤Î«Ø¥ßª«¥óªº°õ¦æÓÅé¡AµM«á COM §âª«¥ó¶Ç¦^µ¹«È¤áºÝ¡C¦pªG¦b Sub Main µ{§Ç©Î¬O¦b Class_Initialize ¨Æ¥óµ{§Ç¤¤ªá¤Ó¦h®É¶¡«h¦¹©I¥s·|¦]¬°¼È°±¦Ó¥¢±Ñ¡C¦]¦¹¡A±zµ´¤£À³¸Ó¦b³o¨Çµ{§Ç¤¤°õ¦æªá¶O³\¦h®É¶¡ªº«ü¥O¡A¨Ò¦p¸ê®Æ®wªº¬d¸ß¡C
Åã¥Üªí³æ
¡@
¤@Ó ActiveX EXE ¤¸¥ó¥i¥H¦p¦P¤@¯ëÀ³¥Îµ{¦¡Åã¥Ü¤@Ó¥H¤Wªºªí³æ¡CÁ|¨Ò¨Ó»¡¡A¤¸¥ó¥i¯à¬O¤@Ó¸ê®Æ®wªºÂsÄý¾¹¡A¥i¥H¦p³æ¿Wªºµ{¦¡¤@¼Ë¤u§@©Î¬O¦p¤¸¥ó¤@¼Ë¥Ñ§OªºÀ³¥Îµ{¦¡©Ò¤Þµo¡C
µM¦Ó¡A·íµ{¦¡¦pCOM¤¸¥ó¤@¯ëªº¤u§@®É¡]App.StartMode =vbSModeAutomation¡^¡A«È¤áºÝ¬O¦ì©ó«e´ºªºÀ³¥Îµ{¦¡¡A¥Bµøµ¡¥i¯à¥]§t¤F¦øªA¾¹ªºªí³æ¡C³o·|³y¦¨¤@Ó°ÝÃD¡A¦Ó«Ü¤£©¯¦a¡AVisual Basic ¨S¦³¤èªk¥i¥H«OÃÒªí³æ·|¦bµøµ¡ªº³Ì¤W¤è¡CÁ|¨Ò¨Ó»¡¡Aªí³æª«¥óªº ZOrder ¤èªk§âªí³æ±a¨ì¦P¤@À³¥Îµ{¦¡©Ò¦³ªí³æªº¤W¤è¡A¦ý¬O¨Ã¤£¥²µM¦b©Ò¦³À³¥Îµ{¦¡µøµ¡ªº³Ì¤W¤è¡C³oÓ°ÝÃDªº¸Ñ¨M¤è¦¡¬O©I¥s SetForegroundWindow API ¨ç¦¡¡G
' In the server application Private Declare Function SetForegroundWindow Lib "user32" _ (ByVal hwnd As Long) As Long ' A method that displays a modal window Sub DisplayDialog() frmDialog.Show SetForegroundWindow frmDialog.hWnd End Sub
¤£©¯¦a¡A¦b Windows 98 ¤U Microsoft §ïÅܤF¨ç¦¡¤u§@ªº¤è¦¡¡A©Ò¥H±q«eªº¤èªk¦b²{¦bªº§@·~¨t²Î¤W¥i¯à¤£¯à¤u§@¡C¸Ñ¨M¦¹°ÝÃDªº¤è¦¡¤§¤@¬O¡G¥Ñ Karl E. Peterson©Òµo©ú¡A¥X²{¦b 1999 ¦~¤G¤ëµo¦æªº Visual Basic Programmer's Journal¤¤ ªº¡uAsk the VB Pro¡v±MÄæ¡C
Visual Basic 6 ¹ï©ó MsgBox ©R¥O´£¨Ñ·sªº vbMsgBoxSetForeground ºX¼Ð¡A½T©w°T®§¤è¶ô¥X²{¦b©Ò¦³À³¥Îµ{¦¡µøµ¡ªº³Ì¤W¤è¡C
¥t¤@Ó¦³Ãö©ó ActiveX EXE ¤¸¥ó¤¤ªí³æªº°ÝÃD¡C±z±`±`¨Ïªí³æªº¦æ¬°Ãþ¦ü¤@Ó±j¨î¦^À³ªºªí³æ¡A¦ý¬O±j¨î¦^À³¤£·|¬ï¶V³B²z§Çªº½d³ò¡A¨Ï¥ÎªÌÁ`¬On¨Ï¥Î·Æ¹«ÂI¨ú¤~¯à±Ò°Êµøµ¡¡C´«¥y¸Ü»¡¡A¦pªG¦øªA¾¹¥¿¦bÅã¥Ü¤@Ó±j¨î¦^À³ªºµøµ¡¡A¥Ñ«È¤áºÝ¤Þµoªº¤èªk©|¥¼¶Ç¦^¡A¦]¦¹«È¤áºÝ¤£¯à¹ï¦Û¤vªºµøµ¡§@¥X¤ÏÀ³¡Cµ²ªG¤¬íÄÁªº¼È°±®É¶¡¨ì¤F¤§«á¡A¤@Ó ÀÁ¸m¤¸¥óªº½Ð¨D ¹ï¸Ü¤è¶ô¥X²{¡A¸ÑÄÀ¦]¬°¤¸¥ó¨S¦³¦^À³¡A¾Þ§@¤£¯à§¹¦¨¡C¡]³o¦³ÂI¥O¤H»~¸Ñ¡A¦]¬°¬O«È¤áºÝ¨S¦³¦^À³¡A¤£¬O¦øªA¾¹¡C¡^
¸Ñ¨M³oÓ°ÝÃDªºÂ²³æªº¤èªk´N¬O¦b©I¥s¤¸¥óÅã¥Ü±j¨î¦^À³ªº¹ï¸Ü¤è¶ôªº¤èªk¤§«e¡A¨ú®ø©Ò¦³«È¤áºÝªºªí³æ¡C³o«Ü®e©ö«Ü§Öªº°µ¨ì¡A·PÁÂForms ¶°¦X¡G
Private Sub cmdShowDialogFromComponent_Click() SetFormsState False x.DisplayDialog SetFormsState True End Sub ' The same routine can disable and reenable all forms. Sub SetFormsState(state As Boolean) Dim frm As Form For Each frm In Forms frm.Enabled = state Next End Sub
¨î¨Ï¥ÎªÌªº¦æ¬°
¡@
¤@ÓActiveX EXE¤¸¥óªº°õ¦æÓÅé¥i¥H¦P®ÉªA°È¥æ½Í¦¡ªº¨Ï¥ÎªÌ¥H¤Î«È¤áºÝªºÀ³¥Îµ{¦¡¡CÁ|¨Ò¨Ó»¡¡A·í¨Ï¥ÎªÌ±Ò°Ê¤@Óµ{¦¡¡A¨Ã¥B«È¤áºÝ½Ð¨D¤@ӥѤ¸¥ó©Ò´£¨Ñªºª«¥ó®É¡A¤¸¥ó¬O¥Ñ¥¿¦b°õ¦æªº¦øªA¾¹©Ò´£¨Ñ¡C¤Ï¹L¨Ó¤£¤@©w¬°¯u¡A¦pªG«È¤áºÝ¤w¸g«Ø¥ß¤@Óª«¥ó¦Ó¨Ï¥ÎªÌ±Ò°Ê¤@Óµ{¦¡¡A¤@Ó·sªº¡A¤£¦Pªº¦øªA¾¹°õ¦æÓÅé·|¸ü¤J¨ì°O¾ÐÅ餤¡C
·í¦øªA¾¹Åã¥Ü¤@Óªí³æ¡A¹³¬O«È¤áºÝÀ³¥Îµ{¦¡½Ð¨Dªºµ²ªG¡A¦øªA¾¹À³¸Ó¨¾¤î¨Ï¥ÎªÌÃö³¬¦¹µøµ¡¡C±zn¨¾¤î³oºØ±¡ªpµo¥Í¡A¥i¥H¦bªí³æ¤¤³]©w¤@ÓPublicÄÝ©Ê¡A§iª¾¬°¦ó·|Åã¥Üªí³æ¡A¨Ã¥B¦b QueryUnload ¨Æ¥óµ{§Ç¤¤¥[¤J¤@¨Çµ{¦¡½X¡G
' In the frmDialog form module Public OwnedByClient As Boolean Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) If UnloadMode = vbFormControlMenu Then ' The form is being closed by the user. If OwnedByClient Then MsgBox "This form can't be closed by the end user" Cancel = True End If End If End Sub
·íµM¡A±z¥²¶·¦bÅã¥Üªí³æ¤§«e¥¿½T¦a³]©w OwnedByClient ÄÝ©Ê¡A¦p¤U¦Cªºµ{¦¡½X¡G
' If the form is being displayed because a client requested it frmDialog.OwnedByClient = True frmDialog.Show vbModal
¦b§ó½ÆÂøªº®×¨Ò¤¤¡A¬Û¦Pªºªí³æ¥i¯à³Q¨Ï¥ÎªÌ¥H¤Î¤@Ó¥H¤Wªº«È¤áºÝ©Ò¨Ï¥Î¡C¦b³o¨Ç±¡ªp¤¤¡A±zÀ³¸Ó´£¨Ñ¤@Óªí³æªºÄݩʧ@¬°¤@Óp¼Æ¾¹¡A¨Ã¥B§P©w¦ó®É¥i¥H¦w¥þªº¸ü¥Xªí³æ¡C
³Ì«án»¡ªº¬OÃö©ó¾Ö¦³¨Ï¥ÎªÌ¤¶±ªº¤¸¥ó¡C³o¼Ëªº¤¸¥ó¬O¤@Ó¥»¾÷¤º«Øªº¤¸¥ó¡A¥¿¦]¬°¦p¦¹¡A¥¦¤£¯à¦b»·ºÝªº¹q¸£°õ¦æ¡C³oªí¥Ü±z¥¿¦b«Ø¥ß¤@Ó¬Û®e©Ê¤£°ªªº¸Ñ¨M¤è®×¡C·í±z¨M©w±z¬O§_n±N¨Ï¥ÎªÌ¤¶±¥[¤J¤¸¥óªº®ÉÔ¡A½Ð±N¦¹²Ó¸`¥[¥H¦Ò¼{¡C³oºØ±¡ªp¦³¤@Ó¨Ò¥~´N¬O·í¤¸¥ó¬°¤FºÞ²zÅã¥Ü¤@Ó¥H¤Wªºªí³æ¡A¥H¤Î±Mªù¬°¤F°»¿ùªº¥Øªº¡A¨Ã¥B·íªí³æ¬°«D±j¨î¦^À³ªí³æ¦Ó¤£·|°±¤î¤@¯ë±q«È¤áºÝ¨Óªº°õ¦æ¬yµ{ªº®ÉÔ¡C
¬Û®e©Êªº°ÝÃD
¡@
µ{¦¡³]p¤Hû´N¥H¥i§PŪªº¦Wµü°µ«äºûªº±À²z¡G¨CÓÃþ§O¦³¤@Ó§¹¾ãªº¦WºÙ¡A¥H servername.classname ªº®æ¦¡¡A³oÓ§¹¾ãªº¥þ¦WºÙ°µ ProgID¡C·íµM¡A¨S¦³µ{¦¡³]p¤Hû·|¬G·N«Ø¥ß¨âÓ¦³¬Û¦PProgID«o¤£¬Û¦PªºÃþ§O¡A©Ò¥H¬Ý°_¨Ó¦WºÙªº½Ä¬ð¥Ã»·¤£·|µo¥Í¡C¦ý¬OCOMnºÞ²z©Ò¦³¤£¦Pªºµ{¦¡³]p¤Hû©Ò¼gªºÃþ§O¡A©Ò¥H°²³]¦³¨âÓ¤£¦Pªºµ{¦¡³]p¤Hû©Ò«Ø¥ß¬Û¦PProgIDªºª«¥ó¤£·|¦³¦WºÙ¤Wªº½Ä¬ð¦ü¥G¤Ó¹L©ó¼ÖÆ[¡C¦]¦¹¡ACOM¨Ï¥Î¯S®íªºÃѧO½X¨Ó¼Ð°O¨CÓÃþ§O¥H¤Î¥¦Ì©Ò´£¨Ñªº¤¶±¡C
³oºØÃѧO½XºÙ¬°GUIDs¡]¥þ²y°ß¤@ÃѧO½X¡^¡A¨Ã¥B²£¥ÍÃѧO½Xªººtºâªk½T©w¤£·|¦³¨âÓ§¹¥þ¬Û¦PGUIDs·|³Q¥@¬É¤W¨â¥x¤£¦Pªº¹q¸£²£¥Í¥X¨Ó¡CGUIDs¬O128¦ì¤¸¼Æ¦r¨Ã¥B³q±`¬O¥H¤@¸s¥Ñ¬A¸¹©Ò¥]³òªº¤Q¤»¶i¦ì¼Æ¦r©Òªí¥Ü¡CÁ|¨Ò¨Ó»¡¡AExcel.Applicationª«¥ó¡]Excel 97ª©¥»¡^ªº GUID¬°¡G
{00024500-0000-0000-C000-000000000046}
·íVisual Basic½sĶ¤@ÓActiveX¦øªA¾¹®É¡A¹ï©ó¨C¤@ÓÃþ§O¥H¤Î¥¦Ì©Ò´£¨Ñªº¤¶±·|²£¥Í¤@Ó¤£¦PªºÃѧO½X¡C¤@ÓÃþ§OªºÃѧO½XºÙ¬°CLSID¡A¦ÓÃþ§O©Ò´£¨Ñªº¤¶±ªºÃѧO½XºÙ¬°IID¡A¦ý¬O¨CÓÃþ§O¥H¤Î©Ò´£¨Ñªº¤¶±¥u¦³¤@Ó ¤@¯ëªºGUID¡C©Ò¦³ªºGUIDsÀx¦s¦bVisual Basic¬°¤¸¥ó©Ò«Ø¥ßªº«¬ºAµ{¦¡®w¤¤¡A¨Ã¥Bµù¥U¦bµn¿ý¸ê®Æ®wùØ¡C«¬ºAµ{¦¡®w¥»¨µn°O¦¨¥t¤@Ó³æ¤@ªºÃѧO½X¡C
µn¿ý¸ê®Æ®wªº¨¤¦â
¡@
¤@Ó¦nªºµ{¦¡³]p¤Hû¦Ü¤ÖÀ³¸Ó¹ïCOM¦p¦óµù¥U¦bµn¿ý¸ê®Æ®w¤¤¦³¤@¯ëªº¤F¸Ñ¡C¨Ã¥Bª¾¹D·í«È¤áºÝ«Ø¥ß¤@ÓCOMªº°õ¦æÓÅé®É·|µo¥Í¤°»ò¨Æ¡C
n°õ¦æ¤@Ó¤¸¥ó¡AVisual Basic¥²¶·n§â¤¸¥óªºÃþ§OªºProgIDÂà´«¬°¹ê»ÚªºCLSID¡Cn°µ¨ì³o¼Ë¡AVisual Basic©I¥sCOM°õ¦æ®É´Áµ{¦¡®w¤¤ªº¨ç¼Æ¨Ó¦bµn¿ý¸ê®Æ®wHKEY_CLASS_ROOT¤l¥Ø¿ý¤¤·j´MProgID¡C¦pªG·j´M¦¨¥\¡A·j´M¨ìªº¶µ¥ØCLSID¤l¾÷½X¥]§tÃþ§OªºÃѧO½X¡C¡]¨£¹Ï16-9¡^¡C·íµ{¦¡§Q¥Î CreateObject ¨ç¼Æ«Ø¥ßÃþ§O°õ¦æÓÅ骺®ÉÔ¡A¬O¦b°õ¦æ®É´Á·j´M¡F·íµ{¦¡§Q¥ÎNew¹Bºâ¤¸«Ø¥ßÃþ§O°õ¦æÓÅ骺®ÉÔ¡A¬O¦b½sĶ®É´Á°µ·j´M¡Cªþ±a¦a¡A³o¸ÑÄÀ¤F¨Ï¥ÎNew¹Bºâ¤¸«Ø¥ßÃþ§O°õ¦æÓÅé¤ñ¨Ï¥Î CreateObject ¨ç¼Æ§Ö³t¡C·í¨Ï¥ÎNew¹Bºâ¤¸®É¡A°õ¦æ®É¤w¸g¥]§t¤FÃþ§OªºCLSID¡A¸`¬Ù¤F¦bµn¿ý¸ê®Æ®w¤¤©Ò®ø¯Óªº®É¶¡¡C¡]±z¨Ï¥Î¯S©wªºÅܼƥN´À¤@¯ëªºÅܼƥi¥H±o¨ì¸û¦nªº®Ä¯à¡^¡C
¡@
¹Ï16-9 µn¿ý¸ê®Æ®w½s¿è¾¹Åã¥ÜCOM¦bþ¸Ì¥i¥H§ä¨ìMyServer.MyClass¤¸¥óªºCLSID¡C |
¥H¦¹Æ[ÂI¨Ó¬Ý¡ACOM¥i¥H·j´M¨ìµn¿ý¸ê®Æ®w¤¤HKEY_CLASS_ROOT\CLSID¤l¥Ø¿ý¤¤¤¸¥óªºCLSID¡C¦pªG¤¸¥ó¥¿½T¦aµù¥U¤F¡ACOM¥i¥H§Q¥Î³oÓ¾÷½X§ä¨ì©Ò¦³©Ò»Ýnªº¸ê°T¡C¡]¨£¹Ï16-10¡^(See Figure 16-10.)¡C¯S§O¦a¡ALocalServer32 ÁäȪºÈ¬O¤¸¥ó¹ê»ÚEXEÀɮתº©Ò¦bªº¥Ø¿ý¡C¨ä¥L«nªº¸ê°TÀx¦s¦b TypeLib ÁäȤ¤¡A¨ä¤¤¥]§t¤FÃþ«¬µ{¦¡®wªºGUID¡CCOM§Q¥Î³oÓGUID·j´Mµn¿ý¸ê®Æ®w¡A§ä´M«¬ºAµ{¦¡®wªº©Ò¦b¦ì¸m¡C¡]¦b¯S§Oªº¨Ò¤l¤¤¡A«¬ºAµ{¦¡®w¦b´£¨Ñ¤¸¥ó¦P¼ËªºEXEÀɮפ¤¡A¦ý¬O¤@¯ë¬OÀx¦s¦b¥H.tlb¬°°ÆÀɦWªº¤£¦PªºÀɮפ¤¡^
¡@
¹Ï16-10 COM¨Ï¥ÎCLSIDÂ^¨ú°õ¦æÀɮתº¸ô®|¡C |
¤¸¥óªº¬Û®e©Ê
¡@
²z½×¤W¡A¤p¤ß¥J²Óµû¦ô±zªº»Ý¨D¥i¥H¨Ï±z«Ø¥ß¤@Ó¥]§t©Ò¦³Ãþ§O¥H¤Î¤èªkªºCOM¤¸¥ó¡A¥H±¹ï¯u¹ê¥@¬ÉªºÄYV¦ÒÅç¡C¦b³o²z·Qªº¼ÒÀÀ±¡¹Ò¤¤¡A±z¤£¥Î¦b¤¸¥ó¤¤¼W¥[¥ô¦óªºÃþ§O¥H¤Î¤èªk©Î¬O§ó§ï¥ô¦óªºPublic¤¶±¡C³o¨Ç¤¸¥óµ´¹ï¤£·|²£¥Í¥ô¦ó¬Û®e©Êªº°ÝÃD¡C·íVisual Basicªº½sĶ¾¹±N¤@¤èªkªº¦WºÙÂà´«¬°VTable¤¤ªº¦ì²¾¡A³oӦ첾¥Ã»·¬O¦Xªkªº¨Ã¥B«ü¨ì¤¸¥ó¤¤¦P¼Ëªºµ{§Ç¡C
§A¥i¯à·|ÃhºÃ¡A³o¼Ëªº¼ÒÀÀ±¡¹Ò¤Ó§¹¬ü¥H¦Ü©ó¤£¥i¯à¬°¯u¡C¨Æ¹ê¤W¬O±z±`±`§ó§ï±zªº¤¸¥ó¡B×¥¿¿ù»~¥H¤Î¼W¥[·sªº¥\¯à¡C³o¨Ç§ïÅÜ·|¹ï¤w¦s¦bªº«È¤áºÝ³y¦¨°ÝÃD¡C§óºë½Tªº»¡¡A¦pªG±z·sª©¥»ªº¤¸¥ó§ó§ï¤F±Æ¦C¦bVTable¤¤¤èªkªº¶¶§Ç¡A·í¤w¦s¦bªº«È¤áºÝ¸Õ¹Ï¦s¨ú¦ì©ó¿ù»~¦ì²¾ªº¤èªk®É¡A·|¦³ÄY«ªº¨Æ±¡µo¥Í¡CÃþ¦üªº°ÝÃD·|µo¥Í¦b¬Û¦Pªºµ{§Ç«o¦³¤£¦Pªº¤Þ¼Æ¼Æ¥Ø©Î¬O¤Þ¼Æ«¬ºA¤W¡C
Visual Basic©w¸q¤F¤TºØµ¥¯Åªº¬Û®e©Ê¡G
ª©¥»¬Û¦P¡G ·sªºª«¥ó¾Ö¦³¬Û¦Pªº±M®×¦WºÙ¥H¤Î»P«e¤@ª©¥»¾Ö¦³¬Û¦Pªº¤¶±¡CÁ|¨Ò¨Ó»¡¡A³oµo¥Í¦b¦pªG±z§ó§ï¤F¤èªk¥H¤ÎÄݩʪº³]p¤è¦¡¦ý¬O¨S¦³§ó§ï¥¦Ìªº¦WºÙ¡B°Ñ¼Æ¥H¤Î¶Ç¦^Ȫº«¬ºA¡C¡]±z¬Æ¦Ü¤£¥i¥H¼W¥[¿ï¾Ü©Ê°Ñ¼Æ¨ì¤w¦s¦bªº¤èªk¤¤¡A¦]¬°³o¼Ë·í¤èªk³Q¤Þµo®É¡A·|§ïÅÜ°ïÅ|¤¤°Ñ¼ÆȪº¼Æ¥Ø¡^¡C¦b³oºØ±¡ªp¤U¡AVisual Basic¨Ï¥Î«e¤@ª©¥»¤¤©Ò¨Ï¥ÎªºCLSIDs¥H¤ÎIIDs¨Ó½sĶ·sªº¤¸¥ó¡A¤w¦s¦bªº«È¤áºÝ¬Æ¦Ü¤£·|µoı¤¸¥ó¹ê»Ú¤W¤w³Q§ó§ï¹L¡C
ª©¥»¬Û®e¡G ¦pªG±z¼W¥[·sªº¤èªk¥H¤ÎÄݩʦý¬O¨S¦³§ó§ï¤w¦s¦b¦¨ûªº¤¶±®É¡AVisual Basic¥i¥H«Ø¥ß¤@Ó»P«e¤@ª©¥»¬Û®eªº·sªº¤¸¥ó¡A¦b¬Y¨Ç·N¸q¤W¨Ó»¡¡A©Ò¦³ªº¤èªk¥H¤ÎÄݩʤ´µM«O¯dVtable¤¤ªº¦ì¸m¡C¦]¦¹¡A¤w¦s¦bªº«È¤áºÝ¥i¥H¦w¥þ¦a©I¥s¦³ªº¦¨û¡CVTable©µ¦ù°O¿ý·sªº¦¨û¡A·sªº¦¨û¥u·|³Q¹ï©ó·sª©¥»¤¸¥ó«·s½sĶªº«È¤áºÝ©Ò¨Ï¥Î¡C¤¸¥óªºEXE©Î¬ODLLªºÀɮצWºÙ¥i¥H»P«e¤@ª©¥»ªº¦WºÙ¬Û¦P¡A·í±z¦bÅU«Èªº¹q¸£¤¤¦w¸Ë·sª©¥»ªº¤¸¥ó¡A±N·|§âª©¥»ªº¤¸¥óÂл\±¼¡C
ª©¥»¤£¬Û®e¡G ·í±z§ó§ï¤w¦s¦b¤èªk¥H¤ÎÄݩʪº¤¶±¡ÐÁ|¨Ò¨Ó»¡¡A¼W¥[©Î¬O²¾°£¤Þ¼Æ¡]¥]§t¿ï¾Ü©Êªº¤Þ¼Æ¡^©Î¬O§ó§ï¤Þ¼Æªº«¬ºA©Î¬O¦^¶ÇȡЦ¹¤¸¥ó¤£¦A¸ò«eª©ªº¤¸¥ó¬Û®e¡CVisual Basic 6¦³®É·|»s³y¤£¬Û®eªº¤¸¥ó¬Æ¦Ü±z¥u¬O§ó§ï¤Fµ{§ÇÄݩʹï¸Ü¤è¶ô¡C¦b³oºØ±¡ªp¤U¡A±z¥²¶·§ó§ï¤¸¥ó©Ò¦bªºEXE©Î¬ODLLÀɮתº¦WºÙ¡A³o¼Ë¤¸¥ó¤~¯à¦AÅU«Èªº¹q¸£¤¤»P«e¤@ª©¥»ªº¤¸¥ó¦@¦s¡Cªº«È¤áºÝÀ³¥Îµ{¦¡¨Ï¥Î«e¤@ª©¥»ªº¤¸¥ó¡A·sªº«È¤áºÝÀ³¥Îµ{¦¡¨Ï¥Î·sª©¥»ªº¤¸¥ó¡C
¦pªG«È¤áºÝ¨Ï¥ÎNew¹Bºâ¤¸«Ø¥ß¨Ó¦Û¤¸¥óªºª«¥ó¡A«È¤áºÝ³z¹LCLSID¤Þ¥Î³o¨Çª«¥ó¡A¨Ï¥Î³oºØ¤è¦¡¡A·í¦³¨âÓ¤£¦P¡]¤£¬Û®e¡^«o¾Ö¦³¬Û¦PªºProgIDªº¤¸¥ó¦w¸Ë¦b¦P¤@¥x¹q¸£®É¡A¤£·|¦³½Ä¬ð²£¥Í¡C¦ý¬O¸û¦nªº¤è¦¡¬O¤£¦Pª©¥»ªº¤¸¥ón¦³¤£¦PªºProgID¡A±z¥i¥HÂǥѧó§ï·s¤¸¥óªº±M®×¦WºÙ¨Ó¹F¦¨¦¹¥Øªº¡C
Åý§Ų́ӦҼ{·í±z«Ø¥ß¤@Óª©¥»¬Û®eªº¤¸¥ó®É¡A¹ê»Ú¤W·|µo¥Í¤°»ò¨Æ¡C±z¥i¯à·|¬Û«HVisual Basic¥u¬O²³æªº¥HÄ~©Ó«e¤@ª©¥»¤¸¥óªºCLSID¥H¤ÎIIDªº¤è¦¡«Ø¥ß¤@Ó·sªº¤¸¥ó¡A¦ý¬O¨Ã¤£¬O¦p¦¹¡C¬Û¤Ï¦a¡AVisual Basic¬°©Ò¦³ªº¤¸¥ó¤¤ªºÃþ§O¥H¤Î¤¶±¡A²£¥Í·sªºÃѧO½X¡C³o¼Ë¦X¥GCOMªº«ü¾Éì«h¡A¨ä¤¤´£¨ì¤@¥¹±zµo¦æ¤@Ó¤¶±¤§«á«K¤£À³¸Ó¦A¥h§ó§ï¥¦¡CµM¦Ó¡A·sªº¤¸¥ó¤]¥]§t¤F«e¤@ª©¥»¤¸¥óªºCLSID¥H¤ÎIIDªº©Ò¦³¬ÛÃö¸ê°T¡A¦p¦¹¥Hª©¥»¤¸¥ó©Ò«Ø¥ßªº«È¤áºÝ¥i¥HÄ~Äò¦p¥H«e¤@¯ëªº¤u§@¡C·íªº«È¤áºÝ±q·sªº¤¸¥ó½Ð¨D¤@Óª«¥ó®É¡ACOM·j´Mµn¿ý¸ê®Æ®w¤¤ÂªºCLSID¡AªºCLSID¤´µM¤Þ¥Î¦P¤@ÓEXEÀɮסC±z»Ýn¤F¸Ñ¹q¸£¬O¦p¦ó¹B§@ªº¡A¦]¬°³o¸Ì¸ÑÄÀ¤F¬°¦ó¤@Óª©¥»¬Û®eªº¤¸¥ó¦b°õ¦æÀɤ¤²Ö¿n¦h«ªºCLSID¥H¤ÎIID¶°¦X¡A¨Ã¥B¤]·|¾ÉP¹L¦h¶µ¥Ø¶ñº¡µn¿ý¸ê®Æ®w¡C¡]¥]§t±zÅU«È¥H¤Î±z¦Û¤vªº¡^¡C
¦bVisual BasicÀô¹Ò¤¤ªºª©¥»¬Û®e
¡@
±z¤w¸g¨¬°÷ªº¤F¸Ñ¦p¦ó«Ø¥ß¤@Ó¬Û®eªº¤¸¥ó¨Ã¥B¦ó®ÉÀ³¸Ó«Ø¥ß¤¸¥ó¡CVisual Basic¨Ã¤£¤¹³\¹³¨ä¥Lµ{¦¡»y¨¥¤@¯ë¦a¿ï¾ÜÃþ§OªºCSID¡F©Ò¦³ªºÃþ§O¥H¤Î¤¶±³£¬O¦Û°Ê²£¥Í¡C¦ý¬O±z¥i¥H¨M©w¤@Ó·sª©¥»ªº¤¸¥ó¬O§_n«O¯d«e¤@ª©¥»¤¸¥ó©Ò²£¥ÍªºCSIDs¡CVisual Basic´£¨Ñªº¤TºØ³]©w·|¼vÅT¨ìÃѧO½X¦p¦ó²£¥Í¡A¦p¹Ï16-11¡G
¡@
¹Ï16-11 Visual Basic ¾ã¦Xµo®iÀô¹Ò¤¤ªºª©¥»¬Û®e³]©w¡C |
¤£¬Û®e¡G ·í±z¨C¦¸¦b¦¹Àô¹Ò¤¤°õ¦æ±M®×®É¡]©Î¬O½sĶ¦ÜºÏºÐ¤¤¡^¡AVisual Basic·|Âл\©Ò¦³¤w¦s¦bªºÃѧO½X¨Ã¥B«·s²£¥Í¥¦¡C³o¥]§t¤F©Ò¦³ªºÃþ§O¡B¤¶±¥H¤Î¤¸¥óªº«¬ºAµ{¦¡®w¡C³oªí¥Ü»P«e¤@ª©¥»¥¿±`¤u§@ªº«È¤áºÝ±N¤£¯à»P·sª©¥»ªº¤¸¥ó¤u§@¡C
»P±M®×¬Û®e¡G ·í±z¿ï¾Ü¦¹¼Ò¦¡¡A±z¥²¶·¤]¿ï¾Ü¤@Ó¥²¶·«O¦s¬Û®e©ÊªºVBP¡BEXE©Î¬ODLLÀɮסC¦b³oºØ±¡ªp¤U¡AVisual Basic©ß±ó©Ò¦³Ãþ§O¥H¤Î¨ä¤¶±ªºÃѧO½X¡A¦ý¬O«O¯d¤¸¥óÃþ«¬µ{¦¡®wªºGUID¡C³o¼Ëªº³]©w¦bµo®i¹Lµ{¤¤¬O«Ü¦³¥Îªº¡A¦]¬°¥Ñ¨ä¥LVisual Basic°õ¦æÓÅé©Ò¸ü¤Jªº«È¤áºÝÀ³¥Îµ{¦¡±N¤£·|¥¢¥h¤Þ¥Î¹ï¸Ü¤è¶ô¤¤¦øªA¾¹«¬ºAµ{¦¡®wªº¤Þ¥Î¡C·íVisual Basicµo®iÀô¹Ò¥¢¥h«¬ºAµ{¦¡®wªº¤Þ¥Î®É¡A¦b¤Þ¥Î¹ï¸Ü¤è¶ô¤¤¤Þ¥Î¶µ¥Ø¬Û¹ïÀ³ªº¦ì¸m¤§«e·|¼Ð°O¤WMISSING: ªº¼Ð°O¡C·í³oºØ±¡§Îµo¥Í®É¡A±z¥²¶·±N¨ä§R°£¡AÃö³¬¹ï¸Ü¤è¶ô¡A«·s¶}±Ò¹ï¸Ü¤è¶ô¡A¨Ã¥B¿ï¨ú¤w³Q¥[¤J¬Û¦P¦WºÙªº·sªº¤Þ¥Î¡C
·íµM¡A¦pªGn¨Ï±o¤w¦s¦bªº«È¤áºÝ¯à°÷Ä~Äò¨Ï¥Î·sª©¥»ªº¤¸¥ó¤u§@¡A¥u¬O«O¯d«¬ºAµ{¦¡®wªºGUID¬O¤£°÷ªº¡A¦ý¬O³o¬O¤@ÓÃøÃD¡A¦]¬°¦b´ú¸Õ´Á¶¡±z¨S¦³µo¦æ¥ô¦ó¤w½sĶ¦nªº«È¤áºÝ¡C·í±z«Ø¥ß¤@ÓActiveX EXE©Î¬ODLL±M®×¡AVisual Basicªº¹w³]Ȭ°±M®×¬Û®e¼Ò¦¡¡C
»P¾÷¾¹½X¬Û®e¡G ·í±z¹ï¤@Ó¤w¦s¦bªº¤¸¥ó³]©w»P¾÷¾¹½X¬Û®e¡AVisual Basic¸Õ¹Ï«O¯d©Ò¦³¤¸¥óªº«¬ºAµ{¦¡®w¡BÃþ§O¥H¤Î¤¶±ªºÃѧO½X¡C±zÀ³¸Ó¦bµo¦æ¦¹¤¸¥ó¡]¥H¤Î¥¦ªº«È¤áºÝÀ³¥Îµ{¦¡¡^µ¹±zªºÅU«È®É±j¨î¨Ï¥Î¦¹¼Ò¦¡¡A¦]¬°³o¼Ë¥i¥H«OÃÒ¤£¥Î«·s½sĶ©Ò¦³¤w¦s¦bªº«È¤áºÝ´N¯à´À´«¤¸¥ó¡C±z»Ýn´£¨Ñ¥]§t«e¤@ª©¥»¤¸¥óªº°õ¦æÀɪº¸ô®|¡A³o¼ËVisual Basic±N§Q¥Î¦¹¸ô®|§ä¨ì©Ò¦³©Ò»ÝnªºÃѧO½X¡C
ª`·N
¤@Ó±`¨£ªº¿ù»~´N¬O¬°¾÷¾¹½X¬Û®e¿ï¨ú°Ñ¦ÒÀɮ׮ɡA¿ï¾Ü»P½sĶ¹Lµ{ªº¥Ø¼Ð¬Û¦P¡C¦pªG±z¥Ç¤F³oÓ¿ù»~¡A·í±z¨C¤@¦¸½sĶ±z·sª©¥»ªºÀɮ׮ɡA¤@Ó·sªºGUID¶°¦X·|¥[¤J±zªºEXEÀɮפ¤¡C³o¨ÇÃѧO½X³£¬O¨S¦³¥Îªº¡A¦]¬°¥¦Ì¨Ó¦Ûµo®i¶¥¬qªº½sĶª«¡A¨Ã¥B¥¦Ì¤£Â_ªº¼W¥[°õ¦æÀɪº¤j¤p¨Ã¥B¦b±zªºµn¿ý¸ê®Æ®w¤¤¥[¤J¤@¨Ç¤£·|¥Î¨ìªº¾÷½X¡C¦¹¥~¡A¦b¬Y¨ÇÀô¹Ò¤¤¡A·í½sĶªº¥Ø¼Ð¥H¤Î¾÷¾¹½X¬Û®e©Ò¨Ï¥Îªº°Ñ¦ÒÀɦP®Éµo¥Í®É¡A·|³y¦¨½sĶ®Éªº¿ù»~¡C
´À¥Nªº¤è®×¬O¡A±zÀ³¸Ó¬°±zªº¤¸¥ó·Ç³Æ¤@Óªì©lªºª©¥»¡A¥]§t©Ò¦³¾A·íªºÃþ§O¥H¤Î¤èªk¡]§Y¨Ï¬OªÅªº¡^¡AµM«á«Ø¥ß¤@Ó°õ¦æÀɨåB§@¬°©Ò¦³«á¨Ó½sĶªº°Ñ¦Ò¡C¥Î³oºØ¤è¦¡¡A±z¥i¥H¿ï¾Ü¾÷¾¹½X¬Û®e¨Ã¥B¥i¥HÁקKGUIDªºÂX®i¡C·íµM¡A¤@¸g±zµo¦æ±z¦øªA¾¹²Ä¤@Ó¤½¶}ªºª©¥»¡A¥¦±NÅܦ¨¤@Ó·sªº¾÷¾¹½X¬Û®eªº°Ñ¦Ò¡C°O±o±N³o¼ËªºEXE¥H¤ÎDLLÀÉ®×Àx¦s¦b¤£¦Pªº¥Ø¿ý¡A¦p¦¹·í±z½sĶ±M®×¦ÜºÏºÐªº®ÉÔ´N¤£·|·N¥~¦aÂл\±¼¥¦Ì¡C
·í±z¥¿¦b¾÷¾¹½X¬Û®e¼Ò¦¡¤U¡AVisual Basic¶È¶È±N½sĶ¤¸¥ó·í§@°Ñ¦Ò¨Ó¹Á¸ÕºûÅ@¬Û®e©Ê¡C¨Æ¹ê¤W¡A¦bµo®i¤@Ó·sª©¥»¤¸¥óªº¬Y¨Ç®ÉÔ¡A±z¥i¯à¬G·N¦a©Î¬O·N¥~¦a¯}Ãa¬Û®e©Ê¡ÐÁ|¨Ò¨Ó»¡¡A§ó§ï±M®×ªº¦WºÙ¡B§ó§ïÃþ§O©Î¬O¤èªkªº¦WºÙ¡A©Î¬O¤èªkªº¤Þ¼Æªº«¬ºA©Î¬O¼Æ¶q¡C¡]¨£
¡qª©¥»¬Û®e¡r ³¹¸`¡A¦b¦¹³¹¤§«e¡^¡C·í±zµy«á°õ¦æ©Î¬O½sĶ¦¹±M®×¡AVisual Basic·|Åã¥Ü¤@Ó¦p¹Ï16-12ªº¹ï¸Ü¤è¶ô¨Ã¥B´£¨Ñ±z¤Tӿﶵ¡G
¡@
¹Ï16-12 »¡©ú¦b¾÷¾¹½X¬Û®e¼Ò¦¡¤U¦p¦ó³B²z¤@Ó¤£¬Û®eªº¤¸¥ó |
¦¹®É¡A±z¥i¯à¦³¥Øªº¦an¯}Ãa«e¤@ª©¥»¤¸¥óªº¾÷¾¹½X¬Û®e©Ê¡C³o¬O¤@Ó¦³®Äªº¤âªk¡AÁ|¨Ò¨Ó»¡¡A·í±z¥¿n³¡¸p«È¤áºÝªºÀ³¥Îµ{¦¡¥H¤Î©Ò¦³©Ò»Ýnªº¤¸¥ó®É¨Ã¥B±z½T©w¦bÅU«Èªº¾÷¾¹¤W¨S¦³Âª©¥»ªº¤¸¥ó¡C±z¥i¥HÂǥѤâ°Ê«·s³]©w¬Û®e©Ê¬° ¤£¬Û®e ¨Ó¯}Ãa¬Û®e©Ê¨Ã¥B«·s½sĶÀ³¥Îµ{¦¡¡C³o®É±z©Ò±o¨ìªº¤¸¥ó¤£¥]§t©Ò¦³«e¤@ª©¤¸¥óªºGUID¦]¦¹¤¸¥óªºÅé¿n¸û¤p¨Ã¥B¦bµn¿ý¸ê®Æ®w¤¤¤£·|¦³¤@¨Ç±q¨Ó¤£·|¥Î¨ìªº¾÷½X¡C
³]p´£¥Ü
¡@
n³]p¤@Ó¤£¥¤Zªº¤¸¥ó´X¥G¬O¤£¥i¯àªº¡A©Ò¥H·í»Ý¨D§ïÅܮɡA±z¤£»Ýn¯}Ãa»P«e¤@ª©¥»¤¸¥óªº¬Û®e©Ê¡C³o¸Ì¦³´XÓ´£¥ÜÀ°§U±z«O¯d¤¸¥óªº¬Û®e©Ê¡C
²Ä¤@¡A ·V¿ï¨C¤@Ó¤èªk¥H¤ÎÄݩʪº¸ê®Æ«¬ºA¡C¹çÄ@¨Ï¥ÎLongs¦Ó¤£n¨Ï¥ÎIntegers¦]¬°«eªÌ´£¨Ñ¸û¤jªºÅܼÆȽd³ò¥B¤£·|¯}Ãa®Ä¯à¡A¨Ï¥ÎDouble¥N´ÀSingle§@¬°¤Þ¼Æ¡C¨Ï¥ÎVariant¤Þ¼Æ¤]¥i¥HÀ°§U±z¦b»Ý¨D§ïÅܮɴ£¨Ñ¬Û®e©Ê¡C
²Ä¤G¡A ¹Á¸Õ¥h¹w´Á±zªº¤èªkªº¦¨ªø©Ê¡C§Y¨Ï±z¤£§Æ±æ¼g¥X¨ã¦³³o¨Çªþ¥[¯à¤Oªºµ{¦¡½X¡A´£¨Ñ©Ò¦³¥²nªº¤èªk¥H¤Î¤Þ¼Æ¦b¤§«áÅܦ¨¬O¥²nªº¡C±z¥i¥H¨Ï¥Î Optional ¥H¤Î ParamArray ÃöÁä¦r¨Ó¨Ï±zªºµ{¦¡¨ã¦³¼u©Ê¦Ó¤£·|¼vÅT¤w¦s¦b«È¤áºÝªºÂ²³æ©Ê¡C
Åý±z¥i¥H»P«e¤@ª©¥»ªº¤¸¥ó«O«ù¬Û®e©Êªº¨ä¥Lªº¤âªk´N¬O¥]§t¤@Ó¥i¥H°µ¥ô¦ó¨Æ±¡ªº¤èªk¡A¦¹¤èªk¨Ì·Ó±z©Ò¶Ç¤Jªº¤Þ¼Æ¨M©w§¹¦¨ªº¤u§@¡C¹ê§@ªº¤è¦¡¦p¤U¡G
Function Execute(Action As String, Optional Args As Variant) As Variant ' No code is here in the initial version of the component. End Function
¥ô¦ó®ÉÔ±z·Qn¼W¥[Ãþ§Oªº´¼¼z¥\¯à¦ý¬O±z¤£·Q¯}Ãa¤¸¥ó»P¤w¦s¦b«È¤áºÝªº¬Û®e©Ê®É¡A±z¥un¥[¤J¤@¨Çµ{¦¡½X¦b Execute ¤èªk¤¤¡AµM«á¥H¡u¯}Ãa¾÷¾¹½X¬Û®e¡vªº¤è¦¡«·s½sĶ¡CÁ|¨Ò¨Ó»¡¡A±z¥i¯à¼W¥[±qÀÉ®×Àx¦s¥H¤Î¸ü¤Jªì©l¸ê®Æªº¥\¯à¡G
Function Execute(Action As String, Optional Args As Variant) As Variant Select Case Action Case "LoadData" 'LoadData and SaveData are private procedures LoadData args 'defined elsewhere in the project. Case "SaveData" SaveData args End Select End Function
Args ÅܼƬO¤@ÓVariant¡A©Ò¥H±z¥i¥H¨Ï¥Î°}¦C¶Ç»¼¦h«ªº°Ñ¼Æµ¹¥¦¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H¹ê§@¤@Ó¦b¤@¬q´Á¶¡¤º¾P°â¼Æ¶qªº¨ç¼Æ¡G
' Inside the Evaluate method Case "EvalSales" ' Check that two arguments have been passed. If IsArray(Args) Then If UBound(Args) = 1 Then ' The arguments are the start and end date. Evaluate = EvalSales(Args(0), Args(1)) Exit Function End If End If Err.Raise 1003, , " A two-element array is expected"
µM«á±z¥i¥H©I¥s Evaluate ¤èªk¡G
'Load initialization data. obj.Evaluate "LoadData", "c:\MyApp\Settings.Dat" 'Build a 2-element array on the fly, and pass it to the Evaluate method. SoldPieces = obj.Evaluate("DevalSales", Array(#1/1/98#, Now))
µù¥U¤¸¥ó
¡@
¦p¦Pµ§ªÌ¦b¤§«e©Ò´yzªº¡AÃö©ó¤¸¥ó³\¦h«nªº¸ê®Æ³£Àx¦s¦bµn¿ý¸ê®Æ®w¤¤¡C·í¤¸¥ó¸g¹L¤Fµù¥U¡]registration¡^ªº¹Lµ{¡A¸ê°T´N§¹¥þ¦a°O¿ý¦bµn¿ý¸ê®Æ®w¤¤¡C·í±z¦bIDEªºÀô¹Ò¤¤°õ¦æ¤@ÓActiveX±M®×¡AVisual Basic«K§¹¦¨¤@Ó¤¸¥ó¼È¦sªºµù¥U¡A·í«È¤áºÝ¹³ª½Ä¶ªº¤¸¥ó½Ð¨D¤@Óª«¥ó®É¡ACOM±N©I¥sVisual Basic¥»¨¡C·í±z°±¤î°õ¦æ³oÓ±M®×¡AVisual Basicª½±µ¨ú®ø¤¸¥óªºµù¥U¡C
µM¦Ó¡A·í±z¦w¸Ë¤@Ó¤¸¥ó¦bÅU«Èªº¹q¸£¤¤®É¡A±z»Ýn§¹¦¨¤@ӥä[ªºµù¥U¡C³o¸Ì¦³¤TºØ¥Ã¤[µù¥UActiveX¦øªA¾¹ªº¤èªk¡G
regsvr32 <filename>
¦³®É¡A±z¥i¯àn¨ú®ø¤¸¥óªºµù¥U¡CÁ|¨Ò¨Ó»¡¡A¦b±z±N¤¸¥ó±þ±¼¤§«e¨ú®øµù¥U¬O¤@Ó¦nªºÂI¤l¡A¦]¬°±z±N¥i¥H²¾¥h©Ò¦³¤¸¥ó¦bµn¿ý¸ê®Æ®w¤¤ªº¶µ¥Ø¡C¦pªG±z«O«ùµn¿ý¸ê®Æ®wªº¼ä²b¡A±z¥i¥H¦³¤@Ó¸û¦³®Ä²vªº¨t²Î¥H¤Î´î¤Ö¤@¨Ç¤£¹w´Á³y¦¨µ{¦¡³]p¤Hû¯«¸gºò±iªº"ActiveX can't create the component" ªº¿ù»~¡C±z¥i¥H¥Î¤U¦C¨âºØ¤è¦¡¨ú®ø¤¸¥óªºµù¥U¡G
regsvr32 /U <filename>
¤p¯µ³Z
±z¥i¥H§Q¥Î¤U¦Cªº¤è¦¡¨Ó´î¤Öµù¥U¤@ÓDLL¦øªA¾¹ªº®É¶¡¡C¥´¶}Windows Explorer¨Ã¥BÂsÄý¨ìC:\Windows\SendTo¥Ø¿ý¡]°²³]±zªº§@·~¨t²Î¦w¸Ë¦b C:\Windows¥Ø¿ý¡^¡CµM«á«Ø¥ß¤@Ó±¶®|¨ìRegsvr32.exe ÀɮרåB¼Ð°O¬° Register-ActiveX DLL¡A©Î¬O±z³ßÅwªº¦WºÙ¡C·í±z°µ¦n¦¹¨BÆJ¡A±z¥i¥HÂǥѦb¤¸¥ó¤W«ö¤U·Æ¹«ªº¥kÁä¡AµM«á¶Ç°e¨ìµù¥U©R¥O¨Ó»´©öªºµù¥U¤¸¥ó¡Cn»´©ö¦a¨ú®ø¤¸¥óªºµù¥U¡A±z¥i¥H«Ø¥ß¤U¦C¨â¦æ§å¦¸ÀÉ¡G
C:\VisStudio\Common\Tools\Vb\Regutils\regsvr32 /U %1 Exit
µM«á«Ø¥ß±¶®|¨ìSendToªí³æ¡C¡]·íµM,°O±o¸ô®|n²Å¦X±zªº¨t²Î¡^¡C
°±¤î¦øªA¾¹
¡@
·í±z¨Ï¥Î¤@Óª«¥ó¤§«á¡A·í±z¤£¦b»Ýn³oÓ¤¸¥ó«á±z¥²¶·¸ü¥X¦¹¤¸¥ó¡C¦pªG±z©¿²¤¦¹¨BÆJ¡A¤¸¥ó·|Ä~Äò°±¯d¦b±zªº¨t²Î¤§¤¤¡A®ø¯Ó°O¾ÐÅé¡B¸ê·½¥H¤ÎCPU®É¶¡¡C¤@Ó¸ó³B²z§ÇActiveX¤¸¥ó²Å¦X¤U¦C±ø¥ó®É¡A¬O¥¿½Tªº¸ü¥X¡C
¤£n§Ñ°O¥u¦³¦b«È¤áºÝÀ³¥Îµ{¦¡¤¤ªºª«¥óÅܼƫO«ù¤¸¥óªº¬¡¤O¡C¦pªG¤¸¥ó¦³¤@Ó¥H¤Wªº¨p¦³Åܼƫü¨ì¦Û¤vªºª«¥ó¡A³o¼Ë¤£¯àªý¤îCOM¦b·í¨S¦³«È¤áºÝ¨Ï¥Îª«¥ó®É·´·À¤¸¥ó¡C
¥H«á±¨âÓ¸ü¥X¤¸¥óªº±ø¥ó¨Ó°Q½×¡A±znª`·Nªº¬O¤¸¥ó¤¤ªºµ{¦¡½X¹ê»Ú¤W°µ¤Fþ¨Ç¨Æ¡CÁ|¨Ò¨Ó»¡¡A³\¦h¤¸¥ó§Q¥ÎÁôÂ꺪í³æ®e¯Ç¤@ÓTimer±±¨î¶µ¡A¥H´£¨ÑI´º³B²zªº¯à¤O¡C¦Ò¼{¤U¦C²³æªºµ{§Ç¡G
' In the MyClass module of the MyServer component Sub StartBackgroundPrinting() frmHidden.Timer1.Enabled = True End Sub
³o¼Ëªºªí³æ¯à°÷¦b©Ò¦³«È¤áºÝ³£²×¤î«á¨Ï¤¸¥ó¤´µM¦s¦bµÛ¡Aª½¨ì¨Ï¥ÎµÛ«·s±Ò°Ê¹q¸£©Î¬Oª½±µ±q¤u§@ºÞ²zû©Î¬O¨ä¥L¬Û¦Pªº¤u¨ã±þ±¼¦¹°õ¦æºü¡A§óÁV¿|ªº¬O¤¸¥ó¬O¤£¥i¨£ªº¡A©Ò¥H°£«D±zÀ˵ø¦s¬¡°õ¦æºüªº¦Cªí¡A§_«h±z¤£ª¾¹D°õ¦æºü¤´µM¦s¬¡µÛ¡C·íµM¡A³oÓ°ÝÃDªº¸Ñ¨M¤è¦¡´N¬O¦b Terminate ¨Æ¥óµ{§Ç¤¤¸ü¥X¦¹ªí³æ¡A¤]´N¬O·í«È¤áºÝÄÀ©ñ©Ò¦³¤¸¥óªº¤Þ¥Î®ÉÁ`¬O°õ¦æªºµ{§Ç¡G
' In the MyClass module of the MyServer component Private Sub Class_Terminate() Unload frmHidden End Sub
¦pªG«È¤áºÝ¬O¥¿¦b°õ¦æªºµ{¦¡½X-Á|¨Ò¨Ó»¡¡A¤@Ó¤£Â_ºÊµø§Ç¦C°ð¦³µL©Ò»Ý¸ê®Æªº°j°é - ±z¥²¶·³]p¤@Ó¤èªk¡A·í©Ò¦³ªº¤Þ¥ÎÄÀ©ñ«á°±¤î³oÓµ{¦¡½X¡C¤j¦h¼Æªº®ÉÔ¡A±z¥i¥H¨Ï¥Î¸Ñ¨MÁôÂêí³æªº¤è¦¡¸Ñ¨M³oÓ°ÝÃD¡A´N¬Oª½±µ¦b Terminate ¨Æ¥óµ{§Ç¤¤°±¤î³oÓµ{¦¡½X¡C¤@¨Ç½ÆÂøªº¦øªA¾¹´£¨Ñ¤@Ó¤èªk¡A¹³¬O Quit ©Î¬O Close¡A«È¤áºÝ¥i¥H¨Ï¥Î¦¹¤èªkªí¥Ü¤£¦A»Ýn³oÓ¤¸¥ó¨Ã¥B³]©w©Ò¦³ªº¤Þ¥Î¬°Nothing¡CÁ|¨Ò¨Ó»¡¡A³oºØ¤è¦¡±µªñMicrosoft Excel¥H¤ÎMicrosoft Word©Ò¨Ï¥Îªº¤è¦¡¡C¡]¨£¥»³¹¤@¶}©lªº Spell Checker½d¨Ò ¡^¡C
³Ì«á¤@ÂInª`·Nªº¡G¤@Ó¦øªA¾¹¥²¶·¦b©Ò¦³«È¤áºÝªºªA°È§¹¦¨«á¤~¥i¥Hµ²§ô¡C§Y¨Ï¦øªA¾¹´£¨Ñ¤@Ó¦p Quit ªº¤èªk¡A¦øªA¾¹¤£À³¸Ó¹Á¸Õ¢¨Ï¦Û¤vµ²§ô¡C¦pªG¤@Ó¦øªA¾¹¬ðµM¦Û¤v²×µ²¡ÐÁ|¨Ò¨Ó»¡¡A¨Ï¥Î End ±Ôz¡Ð©Ò¦³¤´µM¤Þ¥Î¦øªA¾¹¤¸¥óªº«È¤áºÝ·|¦¬¨ì¤@Ó¿ù»~¥N½X440ªº¿ù»~¡AAutomation¿ù»~¡CQuit ¤èªkÀ³¸Ó¥u¬O¦øªA¾¹ªº¤@ӽШD¡A¥Î¨Ó¹ïÃö³¬¦øªA¾¹¥»¨°µ·Ç³Æ¡A¸ü¥X©Ò¦³ªºªí³æ¥H¤Î°±¤îI´º¬¡°Ê¡C
«ù¤[©Ê
¡@
Visual Basic 6¤w¸g¥[¤J¤F«Ø¥ß«ù¤[Àx¦s¥\¯àªºª«¥ó¡]persistable objects¡^ªº¥\¯à¡A´N¬Oª«¥óªºª¬ºA¥i¥H³QÀx¦s¥H¤Î«ì´_¡C«ù¤[Àx¦s¥\¯àªºª«¥óªºnÂI¦b©ó·sªº Persistable ª«¥óÄÝ©Ê¥H¤Î¿W¥ßªºPropertyBagª«¥ó¡C¥u¦³¤½¶}ªº¥H¤Î¥i«Ø¥ßªºª«¥ó¥i¥H§@¬°«ùÄòÀx¦s¥\¯àªºª«¥ó¡A©Ò¥H Persistable ÄÝ©Ê¥u¦³¦b°õ¦æÓÅ鬰MultiUse©Î¬OSingleUsecreatable¡]©Î¬O¥¦ÌªºGlobalÅܼơ^¤~·|¦bÃþ§OÄݩʪº¦Cªí¤¤±N¥X²{ Persistable ÄÝ©Ê¡C
Àx¦s¥H¤Î«ì´_ª¬ºA
¡@
·í±z³]©w¤@Ó¤½¶}ªº¥H¤Î¥i«Ø¥ßªºª«¥óªºÄݩʬ°1-Persistable¡Aª«¥ó¼Ò²Õ´£¨Ñ¤TÓ·sªº¤º³¡¨Æ¥ó¡GInitProperties¡BWriteProperties ©M ReadProperties¡C¦b InitProperties ¨Æ¥ó¤¤¡AÃþ§O³Q´Á«Ýªì©l¤Æ¨äÄÝ©Ê¡A³q±`ªí¥Ü«ü©wª«¥óªºÄݩʬ°¹w³]È¡C³oӨƥó³q±`¦b Initialize ¨Æ¥ó¤§«á³QIJµo¡C
' A persistable CPerson class with just two properties Public Name As String Public Citizenship As String ' Default values Const Name_Def = "" Const Citizenship_Def = "American" Private Sub Class_InitProperties() Name = Name_Def Citizenship = Citizenship_Def End Sub
·íª«¥ó³Qn¨DÀx¦s¤º³¡ªºª¬ºA®É¡AClass_WriteProperties ¨Æ¥ó³QIJµo¡C³oӨƥóµ{§Ç¦¬¨ì¤@ÓPropertyBagª«¥ó¡A¤@ÓÀ³¸Ó¶ñº¡ª«¥ó¥Ø«eªºª¬ºAȪºµêÀÀ³U¤l¡C±z¨Ï¥Î±µ¨üÄݩʦWºÙ¥H¤ÎȪºPropertyBagÃþ§Oªº WriteProperty ¤èªk¶ñº¡³oÓ³U¤l¡C
Private Sub Class_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "Name", Name, Name_Def PropBag.WriteProperty "Citizenship", Citizenship, Citizenship_Def End Sub
³Ì«á¡A·íª«¥ó³Qn¨D«ì´_¤º³¡ªºª¬ºA®É¡AClass_ReadProperties ¨Æ¥ó³QIJµo¡C¶Ç»¼µ¹¨Æ¥óµ{§ÇªºPropertyBagª«¥ó¥]§t¤F«e¤@¦¸©ÒÀx¦sªºÄÝ©ÊÈ¡A¨Ã¥Bª«¥ó¥i¥H³z¹LPropertyBagÃþ§Oªº ReadProperty ¤èªk¨Ó¨ú¥XÄÝ©ÊÈ¡C
Private Sub Class_ReadProperties(PropBag As PropertyBag) Name = PropBag.ReadProperty("Name", Name_Def) Citizenship = PropBag.ReadProperty("Citizenship", Citizenship_Def) End Sub
¶Ç»¼µ¹ WriteProperty ¥H¤Î ReadProperty ¤èªk¤¤ªº³Ì«á¤@Ӥ޼ƬOÄݩʪº¹w³]È¡C¹w³]ȬOPropertyBagª«¥ó¥Î¨Ó°µ¸ê·½ªº³Ì¨Î¤Æ¡C¦pªGÄݩʪºÈ»P¹w³]ȬۦP¡A¨º»òÄݩʹê»Ú¤W´N¤£·|³QÀx¦s¨ìPropertyBagª«¥ó¤¤¡C³oӰѼƬO¿ï¾Ü©Êªº¡A
¦ý¬O¦pªG±z¨Ï¥Î¥¦¡A´N¥²¶·¦b©Ò¦³¤TӨƥóµ{§Ç¤¤¨Ï¥Î¬Û¦PªºÈ¡C¦]¦¹¡A¨Ï¥Î²Å¸¹±`¼Æ¬O¾A·íªº¡C
PropertyBagª«¥ó
¡@
n¾Ö¦³¤@Óª«¥ó¥HÀx¦sª¬ºA¡A±z¥²¶·«Ø¥ß¤@Ó¿W¥ßªºPropertyBag ª«¥ó¨Ã¥B¶Ç»¼«ùÄòÀx¦s¥\¯àªºª«¥óµ¹PropertyBagÃþ§Oªº ReadProperty ¤èªk¡C
'Inside a form module Dim pers As New CPerson, pb As New PropertyBag 'Initialize a CPerson object. Private Sub cmdCreate_Click() pers.Name = "John Smith" pers.Citizenship ="Australian" End Sub 'Save the CPerson object in a PropertyBag. Private Sub cmdSave_Click() 'This statement fires a WriteProperties event in the CPerson class. pb.WriteProperty "Aperson", pers End Sub
¦pªGÃþ§Oªº Persistable Äݩʤ£¬O1-Persistable¡A·í±z¸ÕµÛ±q¦¹Ãþ§OÀx¦s©Î¬O«ì´_¤@Óª«¥ó®É¡A·|±o¨ì¤@Ó¿ù»~330¡A"¤£¦Xªkªº°Ñ¼Æ ¤£¯à¼g¤Jª«¥ó¦]¬°¤£¤ä´©«ù¤[Àx¦s¥\¯àªºª«¥ó"¡C
«ì´_ª«¥óªºª¬ºA¤]¬O«Ü²³æªº¡G
Private Sub cmdRestore_Click() 'To prove that persistence works, destroy the object first. Set pers = Nothing 'The next statement fires a ReadProperties event ' in the CPerson class. Set pers = pb.ReadProperty("Apersonl") End Sub
·í±z¶Ç»¼ª«¥óµ¹ WriteProperty ¥H¤Î ReadProperty ¤èªk¡A±z¨S¦³«ü©w¹w³]È¡C¦pªG±z©¿²¤³Ì«á¤@ӰѼƨåBPropertyBag ¨S¦³¬Û¹ïÀ³ªºÈ¡AVisual Basic²£¥Í¤@Ó¿ù»~327"§ä¤£¨ì'property name'ªº¸ê®ÆÈ"¡C³o¬O±z¦bµ{¦¡¦³ÅÞ¿è¤W¿ù»~ªº¼x¥ü¡C°ò¥»¤W¡A±z«÷¿ù¤FÄݩʪº¦WºÙ¡A©Î¬O·í±zÀx¦sª«¥ó®É±z«ü©w¤F¤@Ó¹w³]Ȧý¦b¦^¦s®É©¿²¤¤F¡C¤@¦ý´¿¸g¸ü¤JPropertyBagª«¥ó¨Ã¾Ö¦³¤@Ó¥H¤WªºÄÝ©ÊÈ¡A±z¥i¥H±N³o¨ÇȦs¦^ºÏºÐ¡A¦p¦¹±z¥i¥H¦b¨ä«áªºµ{§Ç¤¤«ì´_ª«¥óªºª¬ºA¡C±z¥i¥H¨Ï¥ÎPropertyBagªº Contents ÄݩʨӰµ³o¼Ëªº¤u§@¡APropertyBagªº Contents ÄݩʬO¤@ÓByte°}¦C¡A¥]§t¤FÀx¦s¦bPropertyBag¤¤©Ò¦³Àx¦sȪº¸ê°T¡A¦p¦P¤U¤@¶µ{¦¡ªº¥Ü½d¡G
' Save the PropertyBag to a binary file. Dim tmp As Variant Open App.Path & "\Propbag.dat" For Binary As #1 tmp = pb.Contents Put #1, , tmp Close #1
«e±ªºµ{§Ç¨Ï¥Î¤@ӼȦsªº Variant ÅܼÆÀx¦sByte°}¦C¡C·í±z±q¸ü¥XªºÀɮתº¤º®e®É±z¥i¥H¨Ï¥Î¦P¼Ëªº§Þ¥©¡C
' Reload the PropertyBag object from file. Dim tmp As Variant Set pb = New PropertyBag Open App.Path & "\Propbag.dat" For Binary As #1 Get #1, , tmp pb.Contents = tmp Close #1
ª`·N
¦pªG±z¦bIDEÀô¹Ò¤¤´ú¸Õµ{¦¡¡A±z¥i¯à·|µoı±zµLªk¸ü¥X«e¤@¦¸Àx¦s¨ìºÏºÐ¤Wªºª«¥óª¬ºA¡A¦]¬°¿ù»~713"Ãþ§O¨S¦³µù¥U"¡C³o¬O¦]¬°propertybag¤¤ª«¥óªºCLSID³QÀx¦s°_¨Ó¡C¹w³]¤W¡A¦bIDE¤¤¨C¦¸±z«·s°õ¦æÀ³¥Îµ{¦¡¡AVisual Basic¬°±M®×¤¤ªº¨C¤@ÓÃþ§O«·s²£¥Í¤@²Õ·sªºCLSID¡A©Ò¥H¤£¯à¸ü¤J¤£¦PCLSIDªºª«¥ó¡Cn§JªA³oÓ°ÝÃD¡A±zÀ³¸Ó³]©w¡u¾÷¾¹½X¬Û®e¼Ò¦¡¡v¡A¦p¦P¦b¥»³¹¤§«eªº³¹¸` ¡qVisual BasicÀô¹Ò¤¤ª©¥»¬Û®e¡r ©Ò¸ÑÄÀªº¡C
ª«¥ó¶¥¼hªº«ù¤[©Ê
¡@
«ù¤[©Ê¡]persistence¡^ªº§Þ³N¤]¥i¥H¥Î¦bª«¥óªº¶¥¼h¤W¡Q¶¥¼h¤¤ªº¨C¤@Óª«¥ó¦³³d¥ô±N¨ä©Ò¨Ì¾aªºª«¥óÀx¦s¦b¥¦ªº WriteProperties¨Æ¥ó¤¤¨Ã¥B¦b ReadProperties µ{§Ç¦^´_¡C©Ò¦³ªº¤u§@¥un¦b¶¥¼h¤¤ªº¨CÓª«¥ó±N¨äPersistableÄݩʳ]©w¬° 1-Persistable¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H±NCPersonÃþ§O©µ¦ù¬°¥]§t¤@Ó¨ä¥LCPersonªº Children¶°¦X¡A¨Ã¥B¦b WriteProperties ¥H¤ÎReadProperties ¨Æ¥óµ{§Ç¤¤¡A°O¿ý·sªºÄÝ©Ê¡G
Public Children As New Collection ' A new public property Private Sub Class_WriteProperties(PropBag As PropertyBag) Dim i As Long PropBag.WriteProperty "Name", Name, Name_Def PropBag.WriteProperty "Citizenship", Citizenship, Citizenship_Def ' First, save the number of children (default = 0). PropBag.WriteProperty"ChildrenCount", Children.Count, 0 ' Next, save all the children, one by one. For i = 1 To Children.Count PropBag.WriteProperty "ChildlW"&1, Children.Item(1) Next End Sub Private Sub Class_ReadProperties(PropBag As PropertyBag) Dim i As Long, ChildrenCount As Long Name = PropBag.ReadProperty("Name", Name_Def) Citizenship = PropBag.ReadProperty("Citizenship", Citizenship_Def) ' First, retrieve the number of children. ChildrenCount = PropBag.ReadProperty("ChildrenCount", 0) ' Next, restore all the children, one by one. For i = 1 To ChildrenCount Children.Add PropBag.ReadProperty("Childle" & 1) Next End Sub
¦³½ì¦a¡A©Ò²£¥ÍªºPropertyBagª«¥ó¥]§t¤F³\¦h¦WºÙ¬° Name¡BCitizenship¡B Child1¡BChild2 µ¥µ¥ªºÄÝ©Ê¡A¦ý¬O³o¤£¬O°ÝÃD¦]¬°¥¦Ì«Ê¸Ë¦b¤@ÓÄݩʪº¶¥¼h¤§¤¤¡A©Ò¥H¤£·|¦³§xÂZ²£¥Í¡C´«¥y¸Ü»¡¡AÀx¦s¦b Child1 ¤l¾ðª¬¥Ø¿ý¤¤ªº Name ªºÈ»PÀx¦s¦b Child2 ¤l¾ðª¬¥Ø¿ý¤¤ªº Name ªº¤£¦P¡A¨ä¾lªº¤]¬O¦p¦¹¡C¦pªG±z·Q¤F¸Ñ§ó¦h³o¤è±ªº§Þ¥©¡A¥iÂsÄýÀH®Ñ¥úºÐ¤¤½d¨Òµ{¦¡ªºµ{¦¡½X¡C
ª`·N
±z»Ýn½T©w¦b¶¥¼hµ²ºc¤¤¤£¥]§t¥ô¦óªº´`Àôªº¤Þ¥Î¡C©Î¬O¦Ü¤Ö±z»Ýn½T©w·í±z¦bÀx¦s¥H¤Î«ì´_ª«¥ó®É¡A¤Þ¥Î¬O¥¿½Tªº¡Cn¸ÑÄÀ³o¬°¤°»ò¬O¤@Ó«nªº¦Ò¶q¡AÅý§ÚÌ°²³]CPersonÃþ§O´£¨Ñ¤@ÓSpouseÄÝ©Ê¡A¥i¥H¶Ç¦^¤@Ópersonªºwife©Î¬Ohusbandªº¤Þ¥Î¡A¸Õ·Q°²¨Ï¨CÓª«¥ó³£¹Á¸ÕÀx¦s³oÓÄݩʪºª¬ºA¡A·|µo¥Í¤°»ò¬O¡CMr. SmithÀx¦sMrs. Smithªºª¬ºA¡A±µµÛMrs. SmithÀx¦sMr. Smithªºª¬ºA¡A±µµÛMr. SmithÀx¦sMrs. Smithªºª¬ºA¡A¤£Â_¦a´`Àô¤U¥hª½¨ì¥X²{"out of stack space" ¿ù»~¡C
¨Ì¾ÚÃö³sªº¦ÛµM©Ê¡A±z¥²¶·µo©ú¥t¤@®Mµ¦²¤¥HÁקK³oºØµL¤î¹Òªº°j°é¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥HÀx¦spersonªº°t°¸ªº¦WºÙ¨Ó¥N´ÀÀx¦s¾ãÓª¬ºA¨Ó¸Ñ¨M³oÓ°ÝÃD¡A¦ý¬O¤§«á±z»Ýn¦bReadProperties¨Æ¥óµ{§Ç¤¤¥¿½T¦a««ØÃö³s¡C
¦b¥ô¦óÃþ§O¼Ò²Õ¤¤¨Ï¥Î PropertyBag
¡@
¤§«eµ§ªÌ¸ÑÄÀ¹L Persistable ÄÝ©Ê¥u¦³¦bPublic¥H¤Î¥i«Ø¥ßªºÃþ§O¤¤¤~¥i¥H¨Ï¥Î¡C´N¬Y¤è±ªº·N¸q¦Ó¨¥¡A³o¬OCOMªº»Ý¨D¡A¦Ó¤£¬OVisual Basic¡CµM¦Ó¡A³o¨Ã¤£ªí¥Ü±z¤£¯à§Q¥ÎPropertyBagª«¥ó¢w¨Ã¥B¬Û®e©óÀx¦s¸ê®Æ¦bAutomation-compliant®æ¦¡¤¤¢w¨Ó¹ê§@¤@ºØª«¥ó«ù¤[©Ê¡C¨Æ¹ê¤W¡A±z°ß¤@¤£¯à°µªº¨Æ¬O¹ê§@¤@Ó¦ÛqªºÃþ§O¨Æ¥ó¡A¤ñ¦p WriteProperties ¥H¤Î ReadProperties¡C¦ý¬O±z¥i¥H¼W¥[¤@Ó¯S®íªºÄÝ©Ê¥H³]©w¥H¤Î¶Ç¦^ª«¥óªºª¬ºA¨Ã¥B¨Ï¥Î¤@Óprivate PropertyBagª«¥ó§@¬°³sÄò¾÷¨îªº§C¶¥¹ê§@¡Cµ§ªÌ¦³¤@ÓCPersonÃþ§O¼Ò²Õ´£¨Ñ¤@Ó¯S®íªº ObjectState ÄÝ©Ê¡G
' The CPerson class module Public FirstName As String, LastName As String Property Get ObjectState() As Byte() Dim pb As New PropertyBag ' Serialize all the properties into the PropertyBag. pb.WriteProperty "FirstName", FirstName, "U" pb.WriteProperty "LastName", LastName, "U" ' Return the PropertyBag's Contents property. ObjectState = pb.Contents End Property Property Let ObjectState(NewValue() As Byte) Dim pb As New PropertyBag ' Create a new PropertyBag with these contents. pb.Contents = NewValue() 'Deserialize the class's properties. FirstName = pb.ReadProperty("FirstName", "") LastName = pb.ReadProperty("LastName", "") End Property
·í¹ê§@¦¹ºØ ¡u«ù¤[©Ê¡v®É¡A¦b«È¤áºÝÀ³¥Îµ{¦¡ªºµ{¦¡½X¦³ÂI¤£¦P¡G
Dim p As New CPerson, state() As Byte p.FirstName = "Francesco" p.LastName = "Balena" 'Save the state into a Byte array. state() = p.ObjectState ' ... ' Create a new object, and restore its state from the Byte array. Dim p2 As New CPerson p2.ObjectState = state() Print p2.FirstName & " " & p2.LastName ' Displays "Francesco Balenal".
·íµM¡A¦pªG¦¹ª«¥ó¨Ì¾a¨ä¥Lª«¥ó¡A¥¦Ì¥²¶·¤]´£¨Ñ ObjectState ÄÝ©Ê¡A¦p¦¹¥Dnªºª«¥ó¤~¯à¥¿½T¦a´`§Ç¤Æ¤lª«¥óªºÄÝ©Ê¡C¤@Ó²M·¡ªº¤èªk¬On©w¸q¤@Ó IObjectState ¤¶±¨Ã¥B¦b©Ò¦³²£¥Í«ù¤[©Êªºª«¥ó¤¤¹ê§@³oÓ¤¶±¡Cª`·N¨ì³oÓ§Þ¥©¥i¥H¥¿±`¤u§@¬O¦]¬°§C³sÄò©Ê¬O¥Ñ¤¸¥óªºµ{¦¡½X©Ò²£¥Íªº¡A¦Ó¤£¬OPropertyBag ª«¥ó¡A©Ò¥H³o¸Ì¨S¦³Ãö©ó Instancing Äݩʪº¨î¡C³oÓ§Þ¥©¤]¥i¥H¦b¼Ð·ÇEXEµ{¦¡¤¤¨Ï¥Î¨Ã¥B¬O±z¨Ï¥ÎPropertyBagª«¥ó©Ò¤£ª¾¹Dªº³Ì¹ê¥Îªº§Þ¥©¡C
ADO Recordsetsªº«ù¤[©Ê
¡@
¦³¤@Ó±z¦bVisual Basic»¡©ú¤å¥ó¤¤§ä¤£¨ìªº¨Æ¹ê´N¬O¦b¬Y¨Ç±ø¥ó¤U±z¬Æ¦Ü¥i¥H¶Ç»¼¤@ÓADO Recordsetµ¹¤@ÓPropertyBagª«¥ó¡C§ó©ú¥Õªº»¡¡A¥ô¦óªºADO Recordset¥i¥H¨Ï¥Î Save ¤èªkÀx¦s¨ìÀɮפ¤¡ÐÁ|¨Ò¨Ó»¡¡A¤@Ó°eµ¹adUseClient¨Ã¥]§t CursorLocation ¶°¦XªºRecordset¡Ð¥i¥H¶Ç»¼µ¹¤@ÓPropertyBagªº WriteProperty ¤èªk¡C³oµ¹¤©±z¦bÀ³¥Îµ{¦¡¶¡¥æ´«¸ê®Æ«e©Ò¥¼¦³ªº¼u©Ê¡CÁ|¨Ò¨Ó»¡¡A¥N´À¨Ï¥ÎSave¤èªkÀx¦s³æ¤@ªºRecordset ¨ì¤@ÓÀɮסA±z¥i¥H¦b¤@ÓPropertyBagª«¥ó¤¤Àx¦s¦hµ§¬ÛÃöªºRecordset¡AµM«á¦A±N¨ä Contents ÄÝ©ÊÀx¦s¨ìÀɮפ¤¡C
«Ø¥ß¤@ÓActiveX DLL¦øªA¾¹
¡@
¦bVisual Basic¤¤«Ø¥ß¤@Ó¦P³B²zºüªºDLL¤¸¥ó©M«Ø¥ß¸ó³B²zºüªº¤¸¥ó¨S¦³¤°»ò¤£¦P¡A©Ò¥H¦b«e¤@³¹¡q «Ø¥ß¤@ÓActiveX EXE¦øªA¾¹¡r¤¤©Ò°Q½×ªº¥Dn§Þ¥©¡A¹ïActiveX DLL¤¸¥ó¤]¬O¥i¥HÀ³¥Î¡C¦b¥»³¹¤¤¡Aµ§ªÌ±NµJÂI©ñ¦b³o¨âºØÃþ«¬ªº¤¸¥ó¤Ö¼Æªº®t²§¤§³B¡C
ª`·N
¦pªG±z©|¥¼·Ç³Æ¦n¡A½Ð¤U¸üVisual Basic³Ì·sªºService Pack¡CÁöµMService Pack¨S¦³¼W¥[¥ô¦ó»y¨¥¤W·sªº¥\¯à¡A¦ý¬O¥¦×¥¿¤F¦bActiveX DLL¤¸¥ó¤W¤@¨ÇÄY«ªº¿ù»~ - ¯S§O¦a¡Aµo¥Í¦b·íÀ³¥Îµ{¦¡¨Ï¥Î¶W¹L¤C©Î¤KÓ¦P³B²zºüªA°È®É¡C
¦bVisual Basic IDE¤¤ªº¦P³B²zºü¤¸¥ó
¡@
¦P³B²zºü¤¸¥ó¥i¥HÂǥѱq ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ôªº³]©w±NÃþ§O°ò¦ªº¼Ð·Ç°õ¦æÀɱM®×Âà´«¬°ActiveX DLL±M®×¨Ó«Ø¥ß¡A¦p¦P±z¦b¸ó³B²zºü¤¸¥ó¤¤©Ò°µªº¡C¬Û¦Pªº¡A±z¥i¥H±q¥\¯àªíªº ÀÉ®× ¿ï¾Ü «Ø¥ß·sÀÉ®× ¡A¦b «Ø¥ß·sÀÉ®× ¹ï¸Ü¤è¶ô¤¤¿ï¾Ü«Ø¥ßActiveX DLL ±M®×¡C
«Ø¥ß¸ó³B²zºü¥H¤Î¦P³B²zºü±M®×ªº³Ì¥Dn®t²§¦b©ó¡A«áªÌ¥i¥H¦b¬Û¦PªºIDEÀô¹Ò¤¤«Ø¥ß«È¤áºÝ¡CVisual Basic 5¥H¤Î6µo®iÀô¹Ò¤ä´©±M®×¸s²Õ¡]project groups¡^ªºÆ[©À¨Ã¥B¥i¥H¦b¦P¤@ÓVisual Basic°õ¦æÓÅ餤®e¯Ç¦hÓ±M®×¡Cn«Ø¥ß±M®×¸s²Õ¡Aº¥ý¥ý¸ò¤@¯ë¤@¼Ë«Ø¥ß¤@Ó±M®×¡AµM«á±q¥\¯àªíªº ÀÉ®× ¿ï¾Ü ¼W¥[·s±M®× ¨Ó«Ø¥ßªþ¥[ªº±M®×©Î¬O±qºÏºÐ¸ü¤J¤@Ó¤w¦s¦bªº±M®×¡C³oºØ¥\¯àÅý±z§Q¥Î¤@Ӽзǰõ¦æÀɫإ߱M®×¸s²Õ¥H¤Î¤@Ó¥H¤WªºActiveX DLLs¡A³o¼Ë±z¥i¥H¦P®É´ú¸Õ¦hÓ¦P³B²zºü¤¸¥ó¡C±z¤]¥i¥H±N±M®×¸s²ÕÀx¦s¦¨°ÆÀɦW¬°.vbgªºÀɮסA³o¼Ë±z¥i¥H§Q¥Î³æ¤@ªº ¶}±Ò «ü¥O¥´¶}¤@Ó±M®×¸s²Õ¡C
·í±z±Ò°ÊRun©R¥O¡A³Q¼Ð°O¬° ±Ò°Ê±M®× ªº±M®×¶}©l°õ¦æ¡]¨£¹Ï16-13¡^¡C³q±`¬O¤@Ӽзǰõ¦æÀɱM®×·í§@¬O«È¤áºÝ¡AµM«á¦A±qActive X DLL±M®×¤¤«Ø¥ß¤@өάO¤@Ó¥H¤Wª«¥ó°õ¦æÓÅé¡C±z¤£»Ýnª½±µ°õ¦æ°õ¦æActiveX DLL±M®×¡]¦p¦P±z±N¸ó³B²zºü¤¸¥ó°õ¦æ¦b¤£¦PªºVisual BasicIDE°õ¦æÓÅ餤¡^¡A¦ý¬O±z¤´µMn¦b¼Ð·Ç°õ¦æÀɪº ¤Þ¥Î ¹ï¸Ü¤è¶ô¤¤¥[¤J¤@ÓDLLªº¤Þ¥Î¡C
¡@
¹Ï16-13 ±z¥i¥H¦b¡u±M®×¡vµøµ¡¤¤«ö¤U·Æ¹«¥kÁä³]©w±Ò°Ê±M®×¡C |
ª`·N¦bIDE¤¤¤Ö¼Æªº©R¥O¶¡±µ¦a»P¥Ø«eªº±M®×¦³Ãö¡Ð¤]´N¬O¦b ±M®×ÄÝ©Ê ¤¤¤Ï¥Õªº±M®×¡CÁ|¨Ò¨Ó»¡¡A ¤Þ¥Î ¹ï¸Ü¤è¶ô·|¦]¬°¤Ï¥Õªº±M®×ªº¤£¦P¦Ó¦³¤£¦Pªº¤º®e¡A ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤]¥uÅý±z¨£¨ì¥H¤Î§ó§ï¥Ø«e¤Ï¥Õ±M®×ªºÄÝ©Ê¡C·í¥Ø«eªº±M®×¬O¼ÐÂà°õ¦æÀɪº®ÉÔ¡Aª«¥óÂsÄý¾¹¥u¯àÅã¥Ü¨ä¥LActiveX DLL ±M®×ªºPublicÃþ§O¥H¤Î¦¨û¥B¤£¤¹³\±z§ó§ï¦¨ûªºÄÝ©Ê¡CnÅã¥Ü©Ò¦³ªºprivate¦¨û©Î¬O§ó§ï¨äÄÝ©Ê©MDLLªº¤èªk¥H¤ÎÄݩʪº´yz¡A±z¥²¶·±NActiveX DLL³]¬°±Ò°Ê±M®×¡C
¹ï©ó¦b¬Û¦Pªº«È¤áºÝÀô¹Ò¤¤°õ¦æDLL¬O¨S¦³¨îªº¡A¦]¬°¤@ÓActiveX DLL¥u¯à¦³¤@ӫȤáºÝ¡CDLL¸ü¤J«È¤áºÝªº¦ì§}ªÅ¶¡¡A©Ò¥H¤£¯à»P¨ä¥LªºÀ³¥Îµ{¦¡¦@¨É¡C¦pªG¨âÓ¤£¦Pªº«È¤áºÝÀ³¥Îµ{¦¡¹ï¦P¼Ëªº¦P³B²zºü¤¸¥ó½Ð¨Dª«¥ó¡ACOM«Ø¥ß¨âÓ¤£¦PªºDLLªº°õ¦æÓÅé¡A¨CÓ°õ¦æÓÅé¦b©Òn¨D«È¤áºÝªº¦ì§}ªÅ¶¡¤º¡C¦]¦¹¡A¨Ï¥ÎActiveX DLL¤ñ¨Ï¥ÎActiveX EXE ²³æªº¦h¡F¨CÓ¤¸¥ó¥u¹ï¤@ӫȤáºÝªA°È¡A©Ò¥H©Ò¦³ªº½Ð¨D¥i¥Hª½±µ°õ¦æ¡C«È¤áºÝÀ³¥Îµ{¦¡¤£»Ýn³B²z¹O®Éªº±¡ªp¡C
¤@ÓActiveX DLL±M®×¤£¯à¥]§tSingleUse©Î¬OGlobalSingleUseÃþ§O¡Cì¦]¬ODLL¦b«È¤áºÝ¬Û¦Pªº³B²zºü¤¤°õ¦æ¨Ã¥B¨S¦³¦U¦Ûªº³B²zºü¡C©Ò¥H·í«È¤áºÝ±q¤¸¥ó«Ø¥ß²Ä¤GÓª«¥ó®É¡ACOM¤£¯à¬°DLL«Ø¥ß¤@Ó·sªº³B²zºü¡C
¦P³B²zºü¤¸¥ó©M¸ó³B²zºü¤¸¥ó¤§¶¡ªº®t²§
¡@
ActiveX DLL¤¸¥ó¤£¥i¯à¨C¥ó¨Æ³£°µ¨ì¡C¦b¤j¦h¼Æªº±¡ªp¤¤¡A¬O¥Ñ©ó¥ý¤Ñ¤W¦P³B²zºüªº¨î¨Ã¥B¤£¯à³QVisual Basic±±¨î¡C
¿ù»~³B²z
¡@
¦b¦P³B²zºü¤¸¥ó¤¤ªº¿ù»~°Q½×´N¦p¦PActiveX EXE¦øªA¾¹¤@¯ë¡CµM¦Ó¡A´N¬YºØ·N¸q¨Ó»¡¡A¦b¦P³B²zºü¤¸¥ó¤¤¿ù»~³B²z§ó¬°«n¡A¦]¬°¦b¦øªA¾¹¤¤¥ô¦óÄY«ªº¿ù»~³£·|¾ÉP«È¤áºÝªºµ²§ô¡A¤Ï¤§¥çµM¡C¦]¬°¨âªÌ¹ê»Ú¤W¬O¦P¤@³B²zºü¡C
¨Ï¥ÎªÌ¤¶±
¡@
ActiveX DLLs¥i¥HÅã¥Ü¥¦Ì¦Û¤vªºªí³æ¡A¦p¦P¸ó³B²zºü¤¸¥ó¤@¯ë¡C¦³½ìªº¬O¡A±q¦P³B²zºü¤¸¥ó©Ò²£¥Íªºªí³æ·|¦Û°Ê©ñ¦b«È¤áºÝªíªºªº«e±¡A©Ò¥H±z¤£»Ý§Q¥Î SetForeground-Window API¨ç¼Æ¾ã²zªí³æ¥H¹F¨ì¥¿½Tªºª¬ºA¡CµM¦Ó¡A¨Ì¾Ú«È¤áºÝªº¯à¤O¡A¤@Ó¦P³B²zºü¤¸¥ó¥i¯à¤£¯àÅã¥Ü«D±j¨î¦^À³ªºªí³æ¡CÁ|¨Ò¨Ó»¡¡A§Q¥ÎVisual Basic5©Î¬O6¡AMicrosoft Office 97 ®M¸Ë³nÅé¡]©Î¬O¤§«áªºª©¥»¡^¤¤©Ò¦³ªºÀ³¥Îµ{¦¡¡A¥H¤Î©Ò¦³¸g¹LVBA»y¨¥µù¥U¦P·Nªº¨ä¥L¼t°ÓªºÀ³¥Îµ{¦¡¡A³£¤ä´©¦P³B²zºü¤¸¥óÅã¥Ü«D±j¨î¦^À³ªí³æ¡C¥t¤@¤è±¡A§Q¥ÎVisual Basic 4©Ò¼gªºÀ³¥Îµ{¦¡¥H¤Î©Ò¦³Microsoft Office¤§«eª©¥»ªºÀ³¥Îµ{¦¡¡A·í¦P³B²zºü¤¸¥ó¸Õ¹ÏÅã¥Ü¤@Ó«D±j¨î¦^À³ªí³æ®É¡A·|²£¥Í¿ù»~369¡C
Visual Basic³z¹L App.NonModalAllowed °ßŪªºÄÝ©ÊÅý±z¯à°÷§PÂ_«È¤áºÝ¬O§_¦³Åã¥Ü«D±j¨î¦^À³ªí³æªº¯à¤O¡CMicrosoft«Øij¦b¤¸¥ó¤¤Åã¥Ü«D±j¨î¦^À³ªí³æ¤§«e¥ý§Q¥Î´ú¸Õ³oÓÄÝ©Ê¡A¨Ã¥B¦pªG¥²n¥H±j¨î¦^À³ªí³æ¥N´À¡C
If App.NonModalAllowed Then frmChart.Show Else frmChart.Show vbModal End If
°²¦p±z¥J²Ó«ä¦Ò¹L·|µoıvbModal±`¼Æ¬O1¨Ã¥B App.NonModalAllowed ¦^¶ÇȬO0©Î¬O-1¡A±z¥i¥H¤@¥y³¯z¦¡°µ©Ò¦³ªº¨Æ¡G
frmChart.Show (1 + App.NonModalAllowed)
¤£©¯¦a¡AY±z¨S¦³±N¤¸¥ó½sĶ¦¨¹ê»ÚªºActiveX DLL ¡A±NµLªk´ú¸Õ³o¶µ¥\¯à¡A¦]¬°·í¦¨¬O¦bVisual BasicÀô¹Ò¤¤°õ¦æ®É App.NonModalAllowed ÄÝ©ÊÁ`¬O¶Ç¦^True¡C
Ãö³¬¦øªA¾¹
¡@
¦P³B²zºü¤¸¥ó²×¤îªºª¬ºA³W«h¸ò±z¦b¸ó³B²zºü¤¸¥ó¤¤©Ò¨£¨ìªº¤£¦P¡C³Ì¥Dnªº®t²§¦b©ó¦P³B²zºü¤¸¥ó¨Æ¸òÀHµÛ«È¤áºÝªº©R¹B¡G·í«È¤áºÝ²×¤î¤¸¥ó´N²×¤î¡A§Y¨Ï¬O¤@Ó¥i¨£ªºªí³æ¤]¤@¼Ë¡C·í«È¤áºÝ¤´µM¦b°õ¦æ¡AY¤U¦C±ø¥ó¥þ³¡²Å¦X¡A¤@Ó¦P³B²zºü¤¸¥ó´N·|²×¤î¡C
¨Æ¹ê¤W¤@Ó¦P³B²zºü¤¸¥óÂǥѦۨ¤º³¡ªº¤Þ¥Î«O«ù¦s¬¡¡A²£¥Í¤F¤@Ó¤£©ö³B²zªº°ÝÃD¡CÁ|¨Ò¨Ó»¡¡A¦pªG¤¸¥ó¥]§t¨âÓ¤¬¬Û¤Þ¥Îªºª«¥ó¡A·í«È¤áºÝÄÀ©ñ©Ò¦³¹ï©ó¤¸¥óªº¤Þ¥Î«á¡A«h¦¹¤¸¥ó±N¥Ã»·¤£·|Ãö³¬¡C´«¥y¸Ü»¡¡A´`Àô¤Þ¥Î±N¨Ï¦P³B²zºü¤¸¥ó¤@ª½¦s¬¡µÛª½¨ì«È¤áºÝ²×¤î¡C¥Ø«e¨S¦³Â²³æªº¤èªk¸Ñ¨M³oÓ°ÝÃD¡A¨Ã¥Bn¨Ïµ{¦¡³]p¤Hû¶O¤OÁקK²£¥Í´`Àô¤Þ¥Î¡C(¦³Ãö´`Àô¤Þ¥Îªº§ó¦h¸ê°T¡A¨£
²Ä¤C³¹ )¥t¤@ÓnÂI¬O¦P³B²zºü¤¸¥óªºª¬ºA¥i¯à§xÂZ³\¦hµ{¦¡³]p¤Hû¡C¦bActiveX EXE¤¸¥ó¡A·í©Ò¦³ªº«È¤áºÝÄÀ©ñ¤Þ¥Î¡A¦øªA¾¹«K²×¤î¡]´£¨Ñ©Ò¦³¨ä¥L©Ò»Ýnªº±ø¥ó¡^¡A¦P³B²zºü¤¸¥ó¤£¬Oª½±µ²×¤î¡C¤@¯ë¤W¡AVisual Basic·|¨Ï¤¸¥ó¦s¬¡¼Æ¤ÀÄÁ¡]µM¦Ó,ºë½Tªº®É¶¡¥i¯à·|§ïÅÜ¡^©Ò¥H¦pªG¨ä¥L«È¤áºÝªº½Ð¨D¡ACOM¤£·|¥h«·s¸ü¤J¦øªA¾¹¡C¦pªG¤¸¥óªº°±¯d®É¶¡¹L¤F¡ADLL·|ÀRÀRªº¸ü¥X¨ÃÄÀ©ñ¥X°O¾ÐÅé¡C¦¹®É¤@Ó·sªº«È¤áºÝ½Ð¨D·|ªá¸û¦hªº®É¶¡¡A¦]¬°COM»Ýn«·s¸ü¤J¤¸¥ó¡C
ª`·N
¥u¦³¤Þ¥Î¨ìpublicª«¥ó¤~¯à«O«ù¦s¬¡¡C§Y¨Ï¤@Ó¦P³B²zºüDLL³]ªk°µ¨ì¶Ç»¼¤@Ó«ü¦Vprivateª«¥óªº«ü¼Ðµ¹¤©«È¤áºÝ¡]Á|¨Ò¨Ó»¡¡A¨Ï¥Î As Object °Ñ¼Æ©Î¬O¦^¶ÇÈ¡^¡A³o¼Ëªº¤Þ¥Î¤£¯à«O«ù¤¸¥óªº¦s¬¡¡C¦pªG«È¤áºÝÄÀ©ñ©Ò¦³¹ï©óPublicª«¥óªº¤Þ¥Î¡A¤@¬q®É¶¡¤§«á¤¸¥ó´N·|¸ü¥X¡C¥Ñ«È¤áºÝ©Ò¾Ö¦³ªºÅܼÆÅܦ¨µL®Äªº¨Ã¥B¤@¨Ï¥Î´N·|¨ÏÀ³¥Îµ{¦¡·í¾÷¡C¦]¦¹¤¸¥ó¤£À³¸Ó¶Ç¤@Óprivateª«¥óµ¹«È¤áºÝ¡C
«Âжi¤Jªº°ÝÃD
¡@
©I¥s¤@Ó¦P³B²zºü¤¸¥óªº¤èªk©Î¬OÄÝ©Ê·|ª½±µªºªA°È¡A§Y¨Ï¤¸¥ó¥¿¦bªA°È¨ä¥Lªº»Ý¨D¡C³o¨Ç¤£¦P©ó¸ó³B²zºü¤¸¥óªº¦æ¬°¨Ã¥B²£¥Í¤F¤@¨Ç±z¥²¶·¸Ñ¨Mªº°ÝÃD¡G
³o¨âÓ°ÝÃD³£µo¥Í¦b·í¤¸¥ó¥¿¦bªA°È«e¤@¶µ»Ý¨Dªº¦P®É¡A«È¤áºÝ©I¥s¤¸¥ó¡A³o·|µo¥Í¦b°²¨Ïª«¥ó°õ¦æ¤@ӨϫȤáºÝ¦A¦¸±Ò°ÊªºDoEvents©R¥O¡B©Î¬O°²¨Ï¤¸¥ó¦b«È¤áºÝ²£¥Í¤@Өƥó¡A©Î¬O°²¨Ï«È¤áºÝ±qTimer±±¨î¶µªº Timer ¨Æ¥óµ{§Ç¤¤©I¥s¤@Ó¤¸¥ó¡C¦pªG±zÁקK³o¨Ç´`Àô¡A±zÀ³¸Ó¤£·|µo¥Í«Âжi¤Jªº°ÝÃD¡C¥t¤@¤èªk¬O¡A±z¥i¥H¹ê°µ¤@Ó«H¸¹¾÷¡]semaphore¡^¡A¥H«È¤áºÝªº¤@Ó¥þ°ì¼Æ§PÂ_¬O§_¥i¥H¦w¥þ¦a©I¥s¤¸¥ó¡C
ActiveX DLL©M¼Ð·Ç°õ¦æÀɵ{¦¡¤§¶¡ªº®t²§
¡@
±zÀ³¸Ó·NÃѨì¤@Ó¦P³B²zºü¤¸¥ó¦æ¬°ªº¤@¨Ç¯S¦â¡F·í±z±q¤@ӼзÇVisual BasicÀ³¥Îµ{¦¡ªº¤@¨ÇÃþ§OÂà´«¬°¤@ÓActiveX DLL®É¡A³o¨Ç¯S¦â¬O«Ü«nªº¡CÁ|¨Ò¨Ó»¡¡A¤@¨Çª«¥ó¥H¤ÎÃöÁä¦r»P¤¸¥óªºÀô¹Ò¦³Ãö¡A¦Ó¤£¬O«È¤áºÝ¡G
¤@¨Ç¨ä¥Lªº¥\¯à¤]¬O¥¦Ì¤£¯à°µ¨ìªº¡G
DLL¤¤ªº´O¤J¦¡ªí³æ
¡@
ActiveX DLL¦øªA¾¹´£¨Ñ¤@Ó¤£¿ùªº¤èªk¨Ó«ÂШϥΤ@¯ëªºªí³æ¥H¤Î¹ï¸Ü¤è¶ô¡C¦p¦P±z©Òª¾¹Dªº¡Aªí³æ¼Ò²Õ¤£¯à¬°Public¡A©Ò¥H¦b±M®×¥H¥~¤£¯à³Q¬Ý¨ì¡A¦ý¬O±z¥i¥H«Ø¥ß¤@Ó¥]»qµÛªí³æªºPublicÃþ§O¡A¨Ã¥B´£¨Ñ¬Û¦Pªº¤¶±¡A³o¼Ë±z´N¥i¥H±q¨ä¥LªºÀ³¥Îµ{¦¡«Ø¥ßªí³æ¡C¤w¦s¦bªºÀ³¥Îµ{¦¡¥u»Ýn¤p´Tªº×§ï©ÎªÌµ·²@¤£¥Îק諸´N¥i¥H¨Ï¥Î¥N´Àªí³æªº¤¸¥ó¡C¨Æ¹ê¤W¡An°µ¨ì¦p¦¹°ß¤@ªº»Ý¨D´N¬OÀ³¥Îµ{¦¡¥Ã»·¤£nª½±µ¤Þ¥Îªí³æ¤Wªº±±¨î¶µ¡A¤]´N¬O»¡µL½×¦p¦ó¤]¤£n³o»ò°µ¥H«O«ùªí³æªº«Ê¸Ë©Ê¡]»Ýn§ó¦hªº¸ê°T¡A¨£ ²Ä¤E³¹ ¡^
°²³]±z»Ýn«Ø¥ß¤@ÓfrmLoginªí³æ±µ¨ü¨Ï¥ÎªÌªº¦WºÙ¥H¤Î±K½X¡A¥H§PÂ_¨Ï¥ÎªÌªº¦Xªk©Ê¡C¦b³oÓ²³æªº¨Ò¤l¤¤¡A°ß¤@¦Xªkªº¨Ï¥ÎªÌ¦WºÙ¬°francesco¡A¹ïÀ³ªº±K½X¬°balena¡C³oÓªí³æ¦³¨âÓTextBox±±¨î¶µ¡A¦WºÙ¬° txtUsername¥H¤ÎtxtPassword¡A¥H¤Î¤@ÓcmdOK CommandButton±±¨î¶µ¡Cªí³æ¤]´£¨Ñ¤@Өƥó¡AWrongPassword¡A¨Æ¥ó¬O¥Ñ©ó¨Ï¥ÎªÌ«ö¤UOK«ö¶s¡A¦ý¬O±K½X¤£¦Xªk©Ò²£¥Íªº¡C³oӨƥó¥i¥H¥Ñ«È¤áºÝªºµ{¦¡½X§ì¨ú¨Ã¥BÅã¥Ü¤@Ó°T®§¹ï¸Ü¤è¶ôµ¹¨Ï¥ÎªÌ¡A¦p¦P±z¦b¹Ï16-14©Ò¨£¨ìªº¡C³o¬Oªí³æ¼Ò²Õªº§¹¾ãµ{¦¡½X¡G
Event WrongPassword(Password As String) Public UserName As String Public Password As String Private Sub cmdOK_Click() 'Validate the password. If LCase$(txtUserName="Francesco" And LCase$(txtPassword) = _ "balena" Then Unload Me Else RaiseEvent WrongPassword(txtPassword) End If End Sub Private Sub Form_Load() txtUserName = UserName 'Load properties into fields. txtPassword = Password End Sub Private Sub Form_Unload(Cancel As Integer) UserName = txtUserName 'Load field values into properties. Password = txtPassword End Sub
±z¥i¥H¹³¨Ï¥ÎÃþ§O¤@¼Ë¨Ó¨Ï¥Î³oÓªí³æ¡A¦Ó¤£¥Îª½±µ¤Þ¥Î¨ìªí±ªº±±¨î¶µ¡C³o¬O¦bÀH®Ñ¥úºÐ¤¤½d¨Òµ{¦¡ªº¥Dªí³æªºµ{¦¡½X¡G
Dim WithEvents frmLogin As frmLogin Private Sub Command1_Click() Set frmLogin = New frmLogin frmLogin.Show vbModal MsgBox "User " & frmLogin.UserName & "logged in", vbInformation End Sub Private Sub frmLogin_WrongPassword(password As String) MsgBox "Wrong Password" End Sub
¡@
¹Ï16-14 ¤@Ó¦P³B²zºü¤¸¥ó¥i¥H¤è«K¦a«Ê¸Ë¤@Óªí³æ¨Ã¥B´£¨Ñ¨ä¨Æ¥óµ¹¤©«È¤áºÝÀ³¥Îµ{¦¡¡C |
¦]¬°ªí³æ¤£¯àÂǥѪ½±µ¦s¨ú¨ä±±¨î¶µ¨Ó¨Ï¥Î¡A©Ò¥H±z¥]»q¤@ÓCLoginÃþ§O¼Ò²Õ¦b frmLoginªí³æ¤W¨Ã¥B«Ê¸Ë¨âÓÃþ§O¥H¤Îªí³æ¼Ò²Õ¦bLoginSvr DLL¤¤¡ALoginSvr DLL¹ï¥~¬É´£¨Ñªí³æªº¥\¯à¨ç¼Æ¡C©³¤U¬OCLoginÃþ§Oªºì©lµ{¦¡½X¡G
Event WrongPassword(Password As String) Private WithEvents frmLogin As frmLogin Private Sub Class_Initialize() Set frmLogin = New frmLogin End Sub Public Property Get UserName() As String UserName = frmLogin.UserName End Property Public Property Let UserName(ByVal newValue As String) frmLogin.UserName = newValue End Property Public Property Get Password() As String Password = frmLogin.Password End Property Public Property Let Password(ByVal newValue As String) frmLogin.Password = newValue End Property Sub Show(Optional mode As Integer) frmLogin.Show mode End Sub Private Sub frmLogin_WrongPassword(Password As String) RaiseEvent WrongPassword(Password) End Sub
±z¥i¥H¬Ý¨ì¡AÃþ§Oªº UserName ¥H¤Î Password ÄÝ©Ê¥H¤Î Show¤èªk²³æ¦a¥H¬Û¦Pªº¦WºÙ¥Nªíªí³æªº¦¨û¡C¦¹¥~¡AÃþ§OºI¨ú±qªí³æ¦Ó¨Óªº WrongPassword ¨Æ¥ó¨Ã¥B¦b«È¤áºÝÀ³¥Îµ{¦¡¤¤²£¥Í¤@Ó¬Û¦P¦WºÙªº¨Æ¥ó¡CÁ`¤§¡AÃþ§O¥¿¦n´£¨Ñ»Pì©lªí³æ¬Û¦Pªº¤¶±¡C¦pªG±z³]©wÃþ§OªºInstancingÄݩʬ°5-MultiUse¡AÃþ§O¡]¥H¤Îªí³æ¡^¥i¥H³Q¥ô¦óªº«È¤áºÝÀ³¥Îµ{¦¡«·s¨Ï¥Î¡C±z¥i¥H§ó§ïì©lªº«È¤áºÝÀ³¥Îµ{¦¡ªº´X¦æµ{¦¡½X¨Ï¨ä¥i¥H»P¥N´ÀfrmLoginÃþ§OªºCLogin Ãþ§O¤u§@¡]§ó§ïªºµ{¦¡½X¥H²ÊÅé¦rªí¥Ü¡^
Dim WithEvents frmLogin As CLogin Private Sub Command1_Click() Set frmLogin = New CLogin frmLogin.Show vbModal MsgBox "User " & frmLogin.UserName & "logged in", vbInformation End Sub Private Sub frmLogin_WrongPassword(password As String) MsgBox "Wrong Password" End Sub
±z¥i¥H¨Ï¥Î³oÓ§Þ¥©«Ø¥ß±j¨î¦^À³¥H¤Î«D±j¨î¦^À³ªº«½Æ¨Ï¥Îªºªí³æ¡CµM¦Ó¡A±z¤£¯à¦b¦p¦PMDIÀ³¥Îµ{¦¡¤¤ªºMDI¤lªí³æªº¤è¦¡´O¤Jªí³æ¦bDLL¤¤¡C
®Ä¯à
¡@
±z¥i¥H¨Ï¤U¦Cªº¤èªk¼W¥[±zActiveX DLL¦øªA¾¹ªº®Ä¯à¡G
¶Ç»¼¸ê®Æ
¡@
¦]¬°DLL»P«È¤áºÝ¦b¦P¤@¦ì§}ªÅ¶¡°õ¦æ¡ACOM¤£»Ýn³B²z«È¤áºÝ¨ì¤¸¥óªº¥~³¡°Ñ¼Æ¶Ç»¼¡]marshal¡^ªº¸ê®Æ¡C¹ê»Ú¤W¡ACOM¦b¦P³B²zºü¤¸¥ó¤¤©Ò§êºtªº¨¤¦â¤ñ¸ó³B²zºü¤¸¥ó²³æ¡A¦]¬°COM¥un½T©w·í«È¤áºÝ¦³½Ð¨D®É¯à¥¿½T¦a«Ø¥ß¤¸¥óªº°õ¦æÓÅé¡C±q¦¹Æ[ÂI¨Ó¬Ý¡A«È¤áºÝª½±µ»P¤¸¥óÁpô¡C·í«È¤áºÝ¤£¦A»Ýn¤¸¥ó®É¡ACOM±N·|¦A¦¸±Ò°Ê¥H½T«ODLL³QÄÀ©ñ¡C
·í¤@ӫȤáºÝ©I¥s¸ó³B²zºü¤¸¥ó®É¡A³B²zºüªºÂà´«·|µo¥Í¦b¥ô¦ó®ÉÔ¡A³o·|©ìºC ActiveX EXE¤¸¥ó¬Û·íªº³t«×¡CÁ|¨Ò¨Ó»¡¡A©I¥s¤@Ó¸ó³B²zºü¤¸¥ó¤¤¡AªÅªº¡B¤£§t¥ô¦ó¤Þ¼Æªºµ{§Ç¡A¤ñ°_©I¥s¤@Ó¦P³B²zºüDLL¤¤¡AªÅªº¡B¤£§t¥ô¦ó¤Þ¼Æªºµ{§Ç¤j¬ùºC¤F500¿¡CÅå¤H¦a¡A©I¥sDLL¤¤ªº¤èªk»P«È¤áºÝÀ³¥Îµ{¦¡¤¤PrivateÃþ§Oªº¤èªk¦h¤Ö¦³¨Ç¬Û¦P¡A©Ò¥Hpºâ©I¥s¤@Ó¦P³B²zºü¤¸¥óªº®É¶¡¬O¨S¦³·N¸qªº¡C
¯Ê¥F¥~³¡°Ñ¼Æ¶Ç»¼¡]marshaling¡^¤]·t¥Ü¶Ç»¼¸ê®Æµ¹¤©¦P³B²zºü¤¸¥óªº³Ì¨Î³W«h¡A¥i¯à»P©M¸ó³B²zºüEXE¦øªA¾¹¤@°_¤u§@©Òn¿í¦uªº³W«h¤£¤Ó¤@¼Ë¡CÁ|¨Ò¨Ó»¡¡A¦b¦P³B²zºü¤¸¥óªºµ{§Ç¤¤¨Ï¥Î ByRef ©Î¬O ByVal ªº¤è¦¡¶Ç»¼¤Þ¼Æ¨Ã¨S¦³·N¸q¤Wªº¤£¦P¡C¦ý¬O±z¶Ç»¼ªø¦r¦ê®É¨Ï¥Î¶Ç§}ªº¤è¦¡¤ñ¨Ï¥Î¶ÇȪº¤è¦¡¨Î¡Gµ§ªÌ«Ø¥ß¤F¤@ӼзÇÀˬdµ{¦¡¡]benchmark¡^¡]±z¥i¥H¦bÀH®Ñ¥úºÐ¤¤§ä¨ì¡^¡A¤ñ¸û¦P³B²zºü»P¸ó³B²zºü¦øªA¾¹¡Cµ§ªÌµoı§Q¥Î¶Çȶǻ¼¤@Ó1000¦r¤¸ªº¦r¦ê¬ù¤ñ§Q¥Î¶Ç§}ªº¤è¦¡ºC¤W¤Q¿¡C¶Vªøªº¦r¦ê¡A§Q¥Î¶ÇȪº¤è¦¡¶Ç»¼·|¶VºC¡C
³]©wDLL °ò©³¦ì§}
¡@
¦pªG±z¦P®É¦³¦hӫȤáºÝ¨Ï¥Î¬Û¦Pªº¦P³B²zºü¤¸¥ó¡A¤£¦PDLLªº°õ¦æÓÅé·|¸ü¤J¨CӫȤáºÝªº¦ì§}ªÅ¶¡¡C³o¼Ë¥i¯à®ö¶O³\¦h°O¾ÐÅéªÅ¶¡¡A°£«D±z°µ¤@¨Ç¹w¨¾¡C
·PÁÂWindows µêÀÀ°O¾ÐÅé¤l¨t²Î¥ý¶iªº¥\¯à¡A±z¥i¥H¦b¤£¦Pªº¦ì§}ªÅ¶¡¸ü¤J¬Û¦PªºDLL¡A¦Ó¤£·|¤ñ³æ¤@DLL°õ¦æÓÅ骺½Ð¨Dªá¶O¸û¦hªº°O¾ÐÅé¡C§óºë½Tªº»¡¡A¦hӫȤáºÝÀ³¥Îµ{¦¡¥i¥H¤À¨É¬Û¦P±qºÏºÐ¾÷¸ü¤JªºDLL¡CµM¦Ó¡A¥u¦³·í©Ò¦³DLLªº°õ¦æÓÅé¸ü¤J¦b¤£¦P¦æµ{ªº°O¾ÐÅéªÅ¶¡ªº¬Û¦P¦ì§}¡A³o¤~¬O¥i¯àªº¡A¨Ã¥B¦¹¦ì§}»PDLLªº°ò©³¦ì§}¬Û¦P¡C
¤@ÓDLLªº°ò©³¦ì§}¡]base address¡^´N¬OWindows¸ÕµÛ¦b«È¤áºÝªº¦ì§}ªÅ¶¡¤º¸ü¤JDLLªº¹w³]¦ì§}¡C¦pªG³oÓ¹Á¸Õ¦¨¥\¡AWindows¥i¥H§Ö³t¦a¸ü¤JDLL¡A¦]¬°Windows¥un¹w³]¤@¶ô°O¾ÐÅé¨Ã¥B±NDLLÀɮתº¤º®e¸ü¤J¨ì¦¹°O¾ÐÅ餤¡C´«¥y¸Ü»¡¡A°²¦pWindows¤£¯à±NDLL¸ü¤J¨ì«È¤áºÝªº°ò©³¦ì§}¡]³Ì±`¨£ªº¬O¦]¬°¾ãÓ°Ï°ì¤w¸g¤À°tµ¹¨ä¥LªºDLL¡^¡AWindows»Ýn´M§ä¤@¶ô¨S¦³¨Ï¥Î¨Ã¥B¥i¥H®e¯ÇDLLªº°O¾ÐÅé°Ï¶ô¡A¨Ã¥B¥²¶·«·s©w¦ì¡]relocate¡^DLLªºµ{¦¡½X¡C«·s©w¦ìªºµ{§Ç§ïÅÜDLL¾÷¾¹½X¤¤Âà¦V¡]jump¡^¥H¤Î©I¥s¡]call¡^«ü¥Oªº¦ì§}¡A±N¦ì§}¥[¤W¤£¦PDLLªº¸ü¤J¦ì§}¡C
Á`µ²¨Ó¬Ý¡A¤@ÓDLL¦b°ò©³¦ì§}¸ü¤J¬O¤@ӫܦnªº¤èªkªºì¦]¦³¨âÓ¡G
Visual Basic¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ôªº ½sĶ ¶ÅÒ¤¤Åý±z¿ï¾Ü¤@Ó¦P³B²zºü¤¸¥óªº°ò©³¦ì§}¡A¦p¦P±z¦b¹Ï16-15©Ò¨£¡C¦¹¦ì§}ªº¹w³]Ȭ°H11000000,¦ý¬Oµ§ªÌ±j¯Pªº«Øij±z¦b½sĶ¤¸¥óªº³Ì²×ª©¥»¤§«e§ó§ï°ò©³¦ì§}ªºÈ¡C¦pªG¨S¦³§ó§ï¡ADLLªº°ò©³¦ì§}·|»P¨ä¥L¥HVisual Basic©Ò¼gªºDLL½Ä¬ð¡C¥u¦³¤@ÓDLL·|Ĺ¡A¨ä¥Lªº¥²¶·«·s©w¦ì¡]relocated¡^¡C
¡@
¹Ï16-15 ±z¥i¥H§ó§ïDLLªº°ò©³¦ì§}¥H¼W¥[®Ä¯à¡C |
©¯¹B¦a¡A¨ä¥Lªºµ{¦¡»y¨¥¾Ö¦³¤£¦Pªº°ò©³¦ì§}¹w³]È¡CÁ|¨Ò¨Ó»¡¡A¥HMicrosoft Visual C++©Ò¼gªºDLLªº°ò©³¦ì§}¹w³]Ȭ°H10000000¡A©Ò¥H§Y¨Ï¨ä¥L»y¨¥ªºµ{¦¡³]p¤Hû¨S¦³§ó§ï¹w³]È¡A³o¨Ç¥HVisual Basic©Ò¼gªºDLL¤]¤£·|»P¨ä¥LªºDLL¦³©Ò½Ä¬ð¡C
·í±z¨M©wÀ³¸Ó¬°Visual Basic DLL§ó§ï°ò©³¦ì§}®É¡A½Ð±N¤U¦C´XÂI¦C¤J°Ñ¦Ò¡G
Á|¨Ò¨Ó»¡¡A¤@Ó®e¯Ç±z©Ò¯à«Ø¥ßªº³Ì¤jªº«È¤áºÝÀ³¥Îµ{¦¡¡A¤j©ó1GB (&H40000000) ªº°ò©³¦ì§}¡A¤´µM¯d¤U1 GB µ¹DLL¡C«ê¦n¥H64-KB¶±¤j¤p¨Ópºâ¡A·í±z³]©w°ò©³¦ì§}µ¹¤©DLL®É¡A¯dµ¹±z16,384¤£¦PªºÈ¨Ñ±z¿ï¾Ü¡C
¥H«D°ò¥»»y¨¥¡]Satellite¡^DLLsÂX®i¤@ÓÀ³¥Îµ{¦¡
¡@
ActiveX DLL¦øªA¾¹¹ï©ó³z¹LºÙ¬°«D°ò¥»»y¨¥¡]Satellite¡^DLLÂX®i¤@ÓÀ³¥Îµ{¦¡ªº¥\¯à¬O«D±`¦³¥Îªº¡Cn¤F¸Ñ«D°ò¥»»y¨¥¡]Satellite¡^DLL¬°¦ó¨º»ò¦³¥Î¡AÅý§ÚÌ¥ý¨Ó¤F¸Ñ¤°»ò¬O¸ê·½ÀÉ¡]resource files¡^¡C
¸ê·½ÀÉ
¡@
¸ê·½ÀÉ´N¬OÀɮסA³q±`¥H.res¬°°ÆÀɦW¡A¥i¥H¥]§t¦r¦ê¡BÂI°}¹Ï¥H¤ÎÀ³¥Îµ{¦¡©Ò¨Ï¥Îªº¾÷¾¹½X¡C±z¥H¨âÓ¨BÆJ«Ø¥ß¸ê·½ÀÉ¡C²Ä¤@¡B±z·Ç³Æ¤@Ó¥]§t¸ê·½Àɤº®eªº¤å¦rÀÉ¡]°ÆÀɦW³q±`¬°.rc¡^¡C³oÓ¤å¦rÀÉn¿í´`©ú½T©w¸qªº»yªk¡CÁ|¨Ò¨Ó»¡¡A³o¸Ì¦³¤@Ó©w¸q¤@Ó¦r¦ê¥H¤Î¹ÏÀɪºRCÀɪº¤ù¬q¡G
STRINGTABLE BEGIN 1001 "Welcome to the Imaging application" 1002 "Do you want to quit now?" END 2001 BITMAP c:\windows\clouds.bmp
²Ä¤G¡B±N.rcÀɽsĶ¦¨¤@Ó.resÀÉ¡A¦b©R¥O¦C¥HRc.exe¸ê·½½sĶ¾¹¥[¤W /r°Ñ¼Æ¡C¡]Visual Basic©Ò´£¨Ñªº¤u¨ã¡^¡C
RC /r TEST.RC
·í½sĶ§¹¦¨¥H«á¡A·|±o¨ì¤@Ó¥DÀɦW»P.rcÀɬۦPªº.resªºÀɮס]¦b³oÓ¨Ò¤l¤¤¬Otest.resÀÉ¡^¡C²{¦b±z¥i¥H§Q¥ÎVisual Basic¥\¯àªí¤¤ªº¡u±M®×¡v¤¤ªº¡u·s¼WÀɮסv±N³oÓ·sªº.resÀÉ¥[¤JVisual BasicªºÀô¹Ò¤¤¡C
»¡©ú
Visual Basic 6 ¨Ï¥Î·sªº¡u¼W¯q¶°¡v«D±`²¤Æ¤F¸ê·½Àɪº«Ø¥ß¥H¤Î½sĶ¹Lµ{¡AVisual Basic¸ê·½ÀÉ®×½s¿è¾¹¡A¦p¹Ï16-16¡C³oÓ¼W¯q¶°¤]¤ä´©¦h«¦r¦êªí®æ¡A¥i¥H¨Ï±zªºÀ³¥Îµ{¦¡¦Û°Ê¦a²Å¦X¨Ï¥ÎªÌªº»y¨¥¡C¤@ÓVisual Basic 5ª©¥»ªº¼W¯q¶°¤]¥i¥H¥ÑMicrosofªººô¯¸¤U¸ü¡C
¡@
¹Ï16-16 VB ¸ê·½ÀÉ®×½s¿è¾¹¥i¥H«Ø¥ßÂI°}¹Ï¡B¤p¹Ï¹³¡BÁnµ¥H¤Î¦h«¦r¦êªí®æ¡C |
·í±z«Ø¥ß¦n¤@Ó.resÀɮסA±zªºµ{¦¡½X¥i¥HÂÇ¥Ñ LoadResString¡BLoadResPicture ¥H¤Î LoadResData ¨ç¼Æ¤Þ¥Î¸ê·½ÀÉ©Ò¥]§tªº¸ê·½¡C¦p¤U¦C¨Ò¤l©Ò¥Ü¡G
' Print a welcome message. Print LoadResString(1001) ' Load an image into a PictureBox control. Picture1.Picture = LoadResString(2001, vbResBitmap)
·í±z«Ø¥ß¤@Ó¥²¶·¦b§Oªº°ê®a©Òµo¦æªºÀ³¥Îµ{¦¡¡A¸ê·½ÀɬO¤@ӫܤ£¿ùªº¿ï¾Ü¡Cì©lµ{¦¡½X§¹¥þ»Pµ{¦¡©Ò¨Ï¥Îªº¦r¦ê¥H¤ÎÂI°}¹Ï¿W¥ß¶}¨Ó¡A·í±z»Ýn«Ø¥ß¤@Ó¤£¦P°ê®a·sª©¥»ªºÀ³¥Îµ{¦¡®É¡A¥u»Ýn·Ç³Æ¤£¦Pªº¸ê·½ÀÉ¡Cn¾Ç²ß§ó¦h¦³Ãö¸ê·½Àɪº¨Ï¥Î¤è¦¡¡A½Ð¬ÝVisual Basic 6¤¤ªºATM.VBP½d¨Ò¡C
µM¦Ó¡A§Y¨Ï¾Ö¦³VB¸ê·½ÀÉ®×½s¿è¾¹ªºÀ°§U¡A³B²z¸ê·½ÀÉ·|¦]¬°¤U¦Cì¦]¦ÓÅã±o³Â·Ð¡G
³o¨âÓ°ÝÃD³£¥i¥H¨Ï¥Î«D°ò¥»»y¨¥¡]Satellite¡^DLL¨Ó¸Ñ¨M¡C
«D°ò¥»»y¨¥¡]Satellite¡^DLL
¡@
«D°ò¥»»y¨¥¡]Satellite¡^DLL©Ò°ò©óªºÆ[©À«Ü²³æ¡C¥N´À¸ê·½Àɸü¤J¦r¦ê¥H¤Î¨ä¥Lªº¸ê·½¡A±z±qActiveX DLL¸ü¤J¡C§Þ¥©¬O±z¨Ï¥Î CreateObject ¥N´ÀNew¹Bºâ¤l±qDLL«Ø¥ß¤@Óª«¥óªº°õ¦æÓÅé¡A¦]¦¹±z¥i¥H¦b°õ¦æ®É¿ï¾Ü±z©Òn¸ü¤JªºDLL¡C³oÓ§Þ¥©¬Æ¦Ü¨Ï±z¥i¥H¦bÅU«Èªº¥Dnµ{¦¡¦w¸Ë¦n¤§«á¡A¦A¦w¸ËDLL¡A¦p¦¹¤@¥¹±z·Ç³Æ¦n·sªºDLL¡A±z´N¥i¥H¦³®Äªº¼W¥[¹ï·s»y¨¥ªº¤ä´©¡C¨Ï¥ÎªÌ¥i¥H¦b°õ¦æ´Á¶¡Âà´«¨ì¨ä¥LªºDLL¡AÁ|¨Ò¨Ó»¡¡A¥\¯àªí¡C
µ§ªÌ·Ç³Æ¤F¤@Ó½d¨Òµ{¦¡¡A¨Ï¥Î«D°ò¥»»y¨¥¡]Satellite¡^DLL«Ø¥ß¤@Ó²³æªº¸ê®Æ®wµ{¦¡¡A¨ä¤¶±¥»¨¾AÀ³¨Ï¥ÎªÌªº°ê®a¡C·íÀ³¥Îµ{¦¡±Ò°Ê¡Aµ{¦¡¿ï¾Ü»PWindows§@·~¨t²Î©Ò²Å¦XªºDLLª©¥»¡A¦pªG¨S¦³§ä¨ì¥¿½Tªº»y¨¥¡A¹w³]Ȭ°English¡]¨£¹Ï16-17¡^
¡@
¹Ï16-17 ¤@ӨϥΫD°ò¥»»y¨¥¡]Satellite¡^DLL¦h«»y¨¥À³¥Îµ{¦¡¡A¤ä´©English¥H¤ÎItalian¡C |
¤@Ó´£¨Ñ¦r¦ê¡BÂI°}¹Ï¥H¤Î¾÷¾¹½Xªº«D°ò¥»»y¨¥¡]Satellite¡^DLL¦Ü¤ÖÀ³¸Ó´£¨Ñ¤TºØ¨ç¼Æ¡Cn¨Ï«D°ò¥»»y¨¥¡]Satellite¡^DLL¬Ý°_¨Ó¦p¦P¸ê·½ÀÉ¡A±z¥i¥H±N¨ç¼Æ¦WºÙ¤À§O¥s°µLoadResString¡BLoadResPicture¥H¤ÎLoadResData¡C©³¤U¬O½d¨Òµ{¦¡©Ò´£¨ÑªºDLLµ{¦¡½Xªº¤@³¡¥÷¡G
'The Resources class module in the Application000 project Enum ResStringID rsDataError = 1 rsRecord rsPublishers '(Other enumerated values omitted...) End Enum Enum ResPictureID rpFlag = 1 End Enum Enum ResDataID rdDummy = 1 'This is a necessary placeholder. End Enum Function LoadResString(ByVal ID As ResStringID) As String Select Case ID Case rsPublishers: LoadResString = "Publishers" Case rsClose: LoadResString = "&Close" Case rsRefresh: LoadResString ="&Refresh" '(Other Case clauses omitted...) End Select End Function Function LoadResPicture(ByVal ID As ResPictureID, _ Optional Format As Long) As IPictureDisp 'Loads images from the frmResources form Select Case ID Case rpFlag: Set LoadResPicture = _ frmResources000.imgFlag.Picture End Select End Function Function LoadResData(ByVal ID As ResDataID, _ Optional Format As Long) As Variant 'Not used in this sample program End Function
³oÓ¯S§OªºDLL¥u¥]§t¤@ÓÂI°}¹Ï¨Ã¥B¤£¥]§t¥ô¦ó¾÷¾¹½X¡C¬°¤F²³æªº¥Øªº¡AÂI°}¹Ï¦b³]p¶¥¬q¤w¸g¸ü¤JfrmResourcesªí³æªºImage±±¨î¶µ¡C³oÓªí³æ¤£·|Åã¥Ü¥H¤Î¤u§@¡A¥¦¥u¬O¤@ÓÂI°}¹Ïªº¾Ö¦³ªÌ¡C±z¥i¥H§Q¥Î³oÓ¤èªkÀx¦s¹Ï¥Ü¥H¤Î´å¼Ð¡C
µM¦Ó¡A¦pªG±z»ÝnÀx¦s¨ä¥LÃþ«¬ªº¾÷¾¹½X¡A±z¥i¥H§Q¥Î¸ê·½ÀÉ¡CµM¦Ó¡A¦b³oÓ¨Ò¤l¤¤¡A¨CÓ«D°ò¥»»y¨¥¡]Satellite¡^DLL¾Ö¦³¦Û¤vªº¸ê·½ÀÉ¡C
¨Ï¥Î«D°ò¥»»y¨¥¡]Satellite¡^DLLªº§Þ¥©¬O¨Ï¥Î¥Dnªº¡]primary¡^DLL¡]¨º´N¬O´£¨Ñ¹w³]»y¨¥¸ê·½ªºDLL¡Ð¦b³oÓ¨Ò¤l¤¤ªºEnglish¡^·í§@¬O¤¶±¡A¨ä¥L»y¨¥ªºDLL¥²¶·¹ê§@¡CÅý§Ú̬ݬÝItalian DLL¬O¦p¦ó¹ê§@ªº¡G
' The Resources class module in the Application410 project Implements MyApplication000.Resources Private Function Resources_LoadResString(ByVal ID As _ MyApplication000.ResStringID) As String Dim res As String Select Case ID Case rsPublishers: res = "Editori" Case rsClose: res = "&Chiudi" Case rsRefresh: res = "&Aggiorna" ' (Other Case clauses omitted...) End Select Resources_LoadResString = res End Function Private Function Resources_LoadResPicture(ByVal ID As _ MyApplication000.ResPictureID, Optional Format As Long) _ As IPictureDisp Select Case ID Case rpFlag: Set Resources_LoadResPicture = _ frmResources410.imgFlag.Picture End Select End Function Private Function Resources_LoadResData(ByVal ID As _ MyApplication000.ResDataID, Optional Format As Long) As Variant ' Not used in this program End Function
ª`·N¨ì³oÓÃþ§O¦b¥Dnªº¤¶±¤¤¨S¦³¦¨û¡CItalian DLLÀx¦s¦¨ MyApplication410.vbp¡A¦Ó¹w³]ªºDLLÀx¦s¦¨MyApplication000.vbp¡C³oÓ©R¦Wµ²ºcªºì¦]«Ý·|´N·|²M·¡©úÁA¡C
¥»¤g¤Æ¡}Locale-aware¡~«È¤áºÝÀ³¥Îµ{¦¡
¡@
Åý§Ú̬ݬݤ@ӫȤáºÝªºÀ³¥Îµ{¦¡¦p¦ó¯à§Q¥Î«D°ò¥»»y¨¥DLLªº¤O¶q¥H¤Î¼u©Ê¡A¦Û°Ê¦a¾AÀ³¨Ï¥ÎªÌªº°ê§O¡A¦P®É¤´µM´£¨Ñ¥¦Ì¦b°õ¦æ®ÉÂà´«¨ì¨ä¥L»y¨¥ªº¯à¤O¡C³oÓ¯µ±K´N¬O¤@ÓAPI¨ç¼Æ¡AGetUserDefaultLangID¡A¶Ç¦^°ê§OÃѧO½Xµ¹¤¬°Êªº¨Ï¥ÎªÌ¡C«È¤áºÝÀ³¥Îµ{¦¡§Q¥ÎÃѧO½X«Ø¥ßDLLªº¦WºÙµM«á¶Ç»¼µ¹ CreateObject ¨ç¼Æ¡A¦p¤U±ªº½d¨Ò©Ò¥Ü¡G
' The main BAS module in the client application Declare Function GetUserDefaultLangID Lib iikernel32lu () As Long Public rs As New MyApplication000.Resources Sub Main() InitLanguage ' Load the satellite DLL. frmPublishers.Show ' Show the startup form. End Sub ' Load the satellite DLL that corresponds to the current user's locale. Sub InitLanguage() Dim LangId As Long, ProgID As String ' Get the default language. LangId = GetUserDefaultLangID() ' Build the complete class name. ProgID = App.EXEName & Hex$(LangId) & "Resources" ' Try to create the object, but ignore errors. If this statement ' fails, the RS variable will point to the default DLL (English). On Error Resume Next Set rs = CreateObject(ProgID) End Sub
³oÓ§Þ¥©ªº¥DnÃöÁä¦b InitLanguage µ{§Ç¡A¤]´N¬OÀ³¥Îµ{¦¡°ÊºA«Ø¥ß´£¨Ñ¸ê·½µ¹¤©¥¿½T°ê§OªºDLLªºµ{§Ç¡CÁ|¨Ò¨Ó»¡¡A°õ¦æ¦bItalianª©¥»ªºWindows¡AGetUserDefaultLangID API¨ç¼Æ¦^¶ÇȬ°1040¡A©Î¬O&H410¡C
±z¥i¥H«Ø¥ß¨ä¥L»y¨¥ªº«D°ò¥»»y¨¥DLLsµM«á°eµ¹¤£¦P°ê®aªºÅU«È¡C³oӤ覡¤@ª½°õ¦æªº«Ü¦n¡A´£¨Ñ±z³]©w¤@Ó±M®×¦WºÙ¦pMyApplicationXXX¡A¦ÓXXX ´N¬O¤Q¤»¶i¦ìªº°ê§OÃѧO½X¡C¡]¹ï©ó°ê§OÃѧO½Xªº¦Cªí¡A¨£Windows SDK ¡^¡C±M®×¦WºÙ«e±ªº³¡¤À¥²¶·¹ïÀ³¨ì«È¤áºÝÀ³¥Îµ{¦¡±M®×ªº¦WºÙ¡]¦b³oÓ¨Ò¤l¤¤ªºMyApplication¡^¡A¦ý¬O±z¥i¥Hµo©ú³]p¨ä¥Lªº¤è¦¡°ÊºA«Ø¥ßDLLªº¦WºÙ¡C¦pªG CreateObject ¨ç¼Æ¥¢±Ñ¡Ars ÅܼƤ£·|¦b InitLanguage µ{§Ç¤¤³Qªì©l¤Æ¡A¦ý¬O¦]¬°¥¦³Q³]©w¬°¦Û°Ê°õ¦æÓÅé¤Æ¡]auto-instancing¡^ªºÅܼơA¥¦¦Û°Ê¦a«Ø¥ßMyApplication000.Resource¤¸¥óªº°õ¦æÓÅé¡C¦b³o¸ÌªºÃöÁäÂI¬O¹ï©ó³oÓ¯S®íªºÀ³¥Îµ{¦¡¤¤ªº©Ò¦³«D°ò¥»»y¨¥DLL¹ê§@¤F¬Û¦Pªº¤¶±¡A©Ò¥HrsÅܼƥi¥H¨Ï¥Î¦´Á³sµ²§ì¦í¥ô¦ó«D°ò¥»»y¨¥DLLªº¤Þ¥Î¡C¬Ý¬Ý¦b«È¤áºÝÀ³¥Îµ{¦¡ªºªí³æ¤¤¦p¦ó¨Ï¥Î rs ÅܼơG
Private Sub Form_Load() LoadStrings End Sub Private Sub LoadStrings() Me.Caption = rs.LoadResString(rsPublishers) cmdClose.Caption = rs.LoadResString(rsClose) cmdRefresh.Caption = rs.LoadResString(rsRefresh) ' (Other string assignments omitted...) Set imgFlag.Picture = rs.LoadResPicture(rpFlag) End Sub
¦]¬°MyApplication000.ResourceÃþ§O¹ï©ó©Ò¦³«D°ò¥»»y¨¥DLL¤¤ªº¦r¦ê¥H¤Î¨ä¥L¸ê·½«Å§i¬°¦CÁ|±`¼Æ¡A±z¥i¥H¨Ï¥ÎIntelliSense¨Ó¥[³tµo®i¶¥¬q¥H¤Î¦b¦P®É²£¥Í§ó¨ã¦³¥iŪ©Ê¥H¤Î¤å¥ó¤è¦¡ªºµ{¦¡½X¡C
¦h°õ¦æºüACTIVEX¤¸¥ó
¡@
Visual Basic 5¥H¤Î6³£¥i¥H«Ø¥ß¦h°õ¦æºüActiveX¤¸¥ó¡CµM¦Ó¡A¦bVisual Basic 5²Ä¤@Óµo¦æª©¥»¤¤¥u¦³¤£§t¨Ï¥ÎªÌ¤¶±ªº¤¸¥ó¾Ö¦³¦h°õ¦æºü¡A³o¬O¤@ÓÄY«ªº¨î¡C³oÓ¨î¦bService Pack 2¤¤¸Ñ°£¤F¡C
°õ¦æºü¼Ò«¬
¡@
·§¬A¨Ó»¡¡A¦h°õ¦æºü´N¬O¦bÀ³¥Îµ{¦¡¤¤¦P®É¥i¥H³B²z¤£¦P³¡¤Àµ{¦¡½Xªº¯à¤O¡C³\¦h¨üÅwªïªºWindowsÀ³¥Îµ{¦¡³£¬O¦h°õ¦æºü¡CÁ|¨Ò¨Ó»¡¡AMicrosoft Word¦Ü¤Ö¨Ï¥Î¨âÓ°õ¦æºü¡AVisual Basicµo®iÀô¹Ò¦Ü¤Ö¨Ï¥Î¤Ó°õ¦æºü¡C·í±zn¦bI´º°õ¦æ½ÆÂøªº¤u§@¡]Á|¨Ò¨Ó»¡¡A¬°¤å¥ó¼Ð¤W¶¼Æ¡^©Î¬O·í±zn«O«ù¨Ï¥ÎªÌ¤¶±¦Ó±zªºÀ³¥Îµ{¦¡¥¿¦b°µ¨ä¥L¨Æ±¡ªº®ÉÔ¡A¦h°õ¦æºü¬O±z¤£¿ùªº¿ï¾Ü¡C·í±z«Ø¥ß¤@Ó¥²¶·¦b¦P®ÉªA°È¤W¦ÊӫȤáºÝªºscalable»·ºÝ¤¸¥ó®É¡A¦h°õ¦æºü¯S§O¬O¥²nªº¡C
³o¸Ì¦³¨âÓ¥Dnªº¦h°õ¦æºü¼Ò«¬¡G¦Û¥Ñ°õ¦æºü¡]free threading¡^¥H¤Î¤½´J°õ¦æºü¡]apartment threading¡^¡C¦b¦Û¥Ñ°õ¦æºü¼Ò«¬¤¤¡A¨CÓ°õ¦æºü¥i¥H¦s¨ú¾ãÓ³B²zºüªº¸ê®Æ°Ï°ì¥H¤Î¥i¥H¤À¨É©Ò¦³ªº¥þ°ìÅܼơC¦Û¥Ñ°õ¦æºü¬O¥\¯à±j¤j¨Ã¥B¦³®Ä²vªº¡A¦ý¬O¥¦«o¬O¤@Ó´c¹Ú¡A§Y¨Ï¹ï¦³¸gÅ窺µ{¦¡³]p¤Hû¦Ó¨¥¡A¦]¬°±z¥²¶·¥òµô©Ò¦³ªº¦@¨É¸ê·½¡A¥]§tÅܼơCÁ|¨Ò¨Ó»¡¡A§Y¨Ï¬O¤@ÓµL®`ªºµ{¦¡¡G
If x > 1 Then x = x - 1 ' X should always be greater than 1.
³£¯à»s³y°ÝÃD¡C·Q¹³³o¼Ëªº±¡¸`¡G°õ¦æºüAŪ¨úxÅܼƪºÈ¬°2¡A¦ý¬O·í¥¦°õ¦æ¨ì Thenªº³¡¤À¡ACPUÂà´«¨ìB¡C°õ¦æºüB¶}©l°õ¦æ¦P¼Ëªºµ{¦¡¡AµoıÅܼƬ°2¡AµM«á´î¬°1¡C·í°õ¦æºüA«·s±o¨ìCPUªº±±¨îÅv¡A¤S±NÅܼƴ0¡A³o¬O¤@Ó¤£¦XªkªºÈ¨Ã¥B¦bµy«áªºµ{¦¡¥Í©R¤¤¥i¯à³y¦¨¨ä¥LÅÞ¿è¤Wªº¿ù»~¡C
¤½´J¼Ò«¬±N¨CÓ°õ¦æºü«Ê¸Ë¦b¤½´J¤§¤¤¥H¸Ñ¨M³o¼Ëªº°ÝÃD¡C¦b¤½´J¤¤ªºµ{¦¡½X¤£¯à¦s¨ú¨ä¥L¤½´J¤¤ªºÅܼơC¨CÓ¤½´J¾Ö¦³¦Û¨ªºÅܼƶ°¦X¡A©Ò¥H¦pªG¦³¨âÓ°õ¦æºü¦P®É¦s¨úÅÜ¼Æ x¡A¹ê»Ú¤W¥¦Ì©Ò°Ñ¦Òªº¨Æ¤£¦P°O¾ÐÅé¦ì§}ªºÅܼơC³oÓ¾÷¨î«ê¦n¸Ñ¨M¤§«e©Ò´£¨ìªº¦P¨B°ÝÃD¡A¦]¦¹¤½´J°õ¦æºü¼Ò«¬¤ñ°_¦Û¥Ñ°õ¦æºü¼Ò«¬¨Óªº¦w¥þ¡C¦bVisual Basic¤¤¡A±z¥u¯à«Ø¥ß¤ä´©¤½´J¼Ò«¬ªºActiveX¤¸¥ó¡C
¦h°õ¦æºüActiveX EXE¤¸¥ó
¡@
Visual Basic 5¥H¤Î6Åý±z«Ø¥ß¸ó³B²zºü¦øªA¾¹®É¡A«È¤áºÝ·s«Ø¥ß¤@Ó°õ¦æÓÅé¡A´N¼W¥[¤@Ó·sªº°õ¦æºü¡C±N¤@Ó¥¿³WªºActive X EXEÂà´«¦¨¦h°õ¦æºüªº¤¸¥ó¡A±z©Òn°µªº´N¬O¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ôªº ¤@¯ë ¶ÅÒ¿ï¾Ü¤@ӿﶵ¡A¡]¨£¹Ï16-18¡^¡C³o¸Ì¦³¤Tӿﶵ³]©w¡C¦b °õ¦æºü¦@¥Î°Ï ªº¹w³]Ȭ°1Ó°õ¦æºü¡A¹ïÀ³¨ì³æ¤@°õ¦æºü¤¸¥ó¡C
¡@
¹Ï16-18 ¦b¡u±M®×ÄÝ©Ê¡v¹ï¸Ü¤è¶ô¤¤¡A¨Ï¥Î·Æ¹«ÂI¥h¼Æ¤U¡A«Ø¥ß¤@Ó¦h°õ¦æºü¤¸¥ó¡C |
¦pªG±z¿ï¾Ü ¿W¥ßªº°õ¦æºü ¿ï¶µ¡A±z©Ò«Ø¥ßªº¦h°õ¦æºü¤¸¥ó¡A¬O·í¦³«È¤áºÝªº½Ð¨D®É¡A´N¹ï¨C¤@Óª«¥ó«Ø¥ß¤@Ó°õ¦æºü¡C¦]¬°¨C¤@Óª«¥ó¾Ö¦³¦U¦Ûªº°õ¦æºü¡A¨S¦³«È¤áºÝ·|³Q¨ä¥Lªº«È¤áºÝªý¶ë¡A©Ò¥H³o¨Ç¤¸¥ó¾Ö¦³³Ì§Ö³tªº¤ÏÀ³¡C³oӤ覡ªº¯ÊÂI¬O¡A§Y¨Ï¬O±j¤jªº¨t²Î¤]·|³Q©ìºC¦]¬°Windowsnªá¶O³\¦hªº®É¶¡°µ°õ¦æºüªº¥æ´«¡C
°õ¦æºü¦@¥Î°Ï
¡@
¦pªG±z¿ï¾Ü °õ¦æºü¦@¥Î°Ï ¿ï¶µ¡A¨Ã¥B¦b°õ¦æºüÄæ¦ì¤¤¿é¤J¶W¹L1ªºÈ¡A±z«Ø¥ß¤F¤@Ó¥u¯à¤¹³\¤@©w¼Æ¶qªº°õ¦æºüªº¦h°õ¦æºü¤¸¥ó¡C³o¬O¤@ÓÅܳqªº¸Ñ¨M¤è¦¡¡A·í±z³¡¸p±zªº¤¸¥ó¦b¥\¯à¸û±jªº¨t²Î®É¡A±z¥i¥H¼W¥[°õ¦æ¦@¥Î°Ïªº¤j¤p¡C¡]ÁöµM±zn«·s½sĶ¡^³oÓ³]©w¨¾¤î¨t²Îªá¤Ó¦hªº®É¶¡¦b°õ¦æºüªººÞ²z¤W¡A¦]¬°°õ¦æ¦@¥Î°Ï¤£¯à¶W¹L±z©Ò³]©wªºÈ¡C¤À°t°õ¦æºüµ¹¤©ª«¥ó¡A¦@¥Î°Ï¨Ï¥Îround robinºtºâªk¡AÁ`¬O¸ÕµÛ¤À°t³Ì¥ý¥i¨Ï¥Îªº°õ¦æºüµ¹¤©¨CÓª«¥ó·sªº½Ð¨D¡C
§ÚÌ°²³]±z«Ø¥ß¤@Ó°õ¦æ¦@¥Î°Ï¤j¤p¬°10ªº¦h°õ¦æºü¤¸¥ó¡C·í²Ä¤@ӫȤáºÝ½Ð¨D¤@Óª«¥ó®É¡ACOM¸ü¤J¤¸¥ó¡A¦b²Ä¤@Ó°õ¦æºü¶Ç¦^©Ò«Ø¥ßªº¤¸¥ó¡C·í²Ä¤GӫȤáºÝ½Ð¨Dª«¥ó¡ACOM¦A²Ä¤GÓ°õ¦æºü«Ø¥ßª«¥ó¡AµM«á·Ó¦¹¤è¦¡¤@ª½¤U¥h¡Aª½¨ì²Ä¤QӫȤáºÝ±o¨ì³Ì«á¤@Ó°õ¦æºü¡C·í²Ä¤Q¤@ӽШD¨Ó®É¡A¤¸¥ó»Ýn¶Ç¦^¤§«e¤w¸g«Ø¥ßªº¨ä¤¤¤§¤@°õ¦æºü¤¤ªºª«¥ó¡C³oÓ·sª«¥ó©Ò¨Ï¥Îªº°õ¦æºüµLªk¦b¤§«e¹w´ú¡A¦]¬°³o¬O³\¦h¦]¯À¦Ó©w¡C¬°³o¨Ç¦]¯À¡Around robinºtºâªk¥i¥H»¡¬O¤£¥i¹w´úªººtºâªk¡C
³o¸Ì¦³´XÂIÃö©ó°õ¦æºü¦@¥Î°Ï¦³©Êªº¨Æ¶µ¡G²Ä¤@¡B·íª«¥ó¼Æ¶q¤j©ó°õ¦æºü®É¡A¨CÓ°õ¦æºüªA°È¤@Ó¥H¤Wªºª«¥ó¡Aª«¥ó¥i¯àÄݩ󤣦Pªº«È¤áºÝ¡C¦b³oºØ±¡ªp¤U¡A¦pªG°õ¦æºü¤w¸gªA°È¨ä¥Lªºª«¥ó¡A«h¦¹°õ¦æºü¥Ø«e¤£¯à°õ¦æ¦¹ª«¥óªº¤èªk¡C´«¥y¸Ü»¡¡A¤@Óª«¥ó¦@¥Î°Ï¨Ã¤£¯à§¹¥þ¦a¨¾¤îª«¥ó¤§¶¡ªºªýê¡]¦p¦P³æ¤@°õ¦æºüª«¥ó¤@¯ë¡^¡A§Y¨Ï³oºØ°ÝÃD¤ñµo¥Í¦b³æ¤@°õ¦æºü¤¸¥óªºÀW²v¤Ö¡C
²Ä¤G¡Bª«¥ó¤@¦ý¦b°õ¦æºü¤¤«Ø¥ß°_¨Ó¡A¥¦¥²¶·¤@ª½¦b¦¹°õ¦æºü¤¤°õ¦æ¡A³o¬O¤½´J°õ¦æºü¼Ò²Õªº¥²n±ø¥ó¡C¦]¦¹¡A§Y¨Ï¦³¨ä¥L¥¼³Q¤À¬£ªº°õ¦æºü¡A¤@ӫȤáºÝ¤´¦³¥i¯à³Q²o¨î¦í¡C·Q¹³¤@Ó±¡¸`¡G±z¾Ö¦³¤QÓ°õ¦æºüªº¦@¥Î°Ï¡A±z«Ø¥ß¤F¤G¤QÓª«¥ó¡C¦b²z·Qªºª¬ªp¤U¡A¦@¥Î°Ïºû«ù«Ü¦nªº¥¿Å¡A¨CÓ°õ¦æºüªA°È¨âÓª«¥ó¡C¦ý¬O¥[³]1¨ì9°õ¦æºüªº©Ò¦³ª«¥ó³£³QÄÀ©ñ¤F¡A¦¹®É¤´¦³¨âÓª«¥ó¦b°õ¦æºü10¡C¦b³oºØ±¡ªp¤U¡A¦@¥Î°ÏÅܪº·¥¬°ªº¤£¥¿Å¨Ã¥B¨âÓª«¥ó·|¤¬¬Û²o¨î¡A§Y¨Ï¦@¥Î°Ï¤´¦³9Ó°õ¦æºü¡C
³Ì«á¡A§Y¨Ï¤½´J¼Ò«¬«OÃÒ¨CÓ¤½´J¦³¤£¦PªºÅܼƶ°¦X¡A¦b¦P¼Ë°õ¦æºü¤¤ªºª«¥ó¤À¨É¬Û¦Pªº¤½´J¨Ã¥B¤À¨É¬Û¦Pªº¥þ°ìÅܼơC³o¥i¯à¬O¤@Ó¦bª«¥ó¤§¶¡¥æ´«¸ê®ÆªºÂ²³æ¤è¦¡¡A¦ý¬O¹ê»Ú¤W±z¤£¯à¨Ï¥Î³oÓ¤èªk¦]¬°±z¤£¯à¹w´úþ¨Çª«¥ó·|¤À¨É¦P¤@Ó°õ¦æºü¡C
¦h°õ¦æºüªº¦n³B
¡@
³\¦hµ{¦¡³]p¤Hû»~»{¬°¦h°õ¦æºü´N¬O¦nªº¤è¦¡¡CµM¦Ó¡A¨Æ¹ê¤W¤j¦h¼Æªº¹q¸£³£¥u¦³¤@ÓCPU¡An°õ¦æ¨t²Î¤¤©Ò¦³³B²zºü¤¤ªº©Ò¦³°õ¦æºü¡C¦pªG±z¦b¦hÓCPUªºWindows NT¥¥x¤W°õ¦æ±zªº¤¸¥ó¡A¦h°õ¦æºü¬O¤@¥ó¦n¨Æ¡A¦b³oºØ±¡ªp¤U¡A§@·~¨t²Î¦Û°Ê§Q¥Î¦h¾lªºCPU¥¿Å¤u§@t¸ü¡CµM¦Ó¡A¦b¤j¦h¼Æ¤@¯ëªº±¡ªp¤¤¡A±z¬O¦b³æ¤@CPUªº¹q¸£¤W¤u§@¡A¨Ã¥B±z·|µo²{¦h°õ¦æºü¨Ï±zªº®Ä¯à°§C¡C³o¸òª½Ä±¤W¦³ÂI¤£¦P¡A©Ò¥Hµ§ªÌ¦bµy«áªº¨Ò¤l¤¤°µ¸ÑÄÀ¡C
°²³]±z¾Ö¦³¨âÓ°õ¦æ¤£¦P¤u§@ªº°õ¦æºü¡A¨CÓ¤u§@»Ýn10¬í§¹¦¨¡C¦b³æ¤@°õ¦æºüªºÀô¹Ò¤¤¡A¨CÓ¤u§@»Ýn10¬í¨Ó§¹¦¨¡A¥t¤@Ó¤u§@µ¥«Ý²Ä¤@Ó§¹¦¨«á¦b±µµÛ§¹¦¨¤u§@¡A¦]¦¹»Ýn20¬í¡Cµ²ªG¬O¨CÓ¤u§@¥§¡n15¬í¨Ó§¹¦¨¡C¦b¦h°õ¦æºüªºÀô¹Ò¤¤¡A¨âÓ¤u§@¥i¥H¥¦æ¦a§¹¦¨¨Ã¥Bªá¶O®t¤£¦h¬Û¦Pªº®É¶¡§¹¦¨¡C°£«D±z¦³¨âÓCPU¡A¦b³oÓ¨Ò¤l¤¤¡A¥§¡ªá¶O20¬í¡A®Ä¯à¤ñ³æ¤@°õ¦æºün®t¡C
Á`µ²¨Ó¬Ý¡A¦h°õ¦æºü¨Ã¤£Á`¬O³Ì¨Îªº¸Ñ¨M¤è¦¡¡CµM¦Ó¡A¦³®É²M·¡¦a´£¨Ñ¶W¶V³æ¤@°õ¦æºü¦n³B¡C
·í±z¦b³æ¤@°õ¦æºü¥H¤Î¦h°õ¦æºü¤§¶¡§@¨M©w®É¡A¤£n§Ñ°OVisual Basic¶¡±µ¦a¦b¬Y¨Ç¤u§@¤¤¨Ï¥Î¦h°õ¦æºü¡ÐÁ|¨Ò¨Ó»¡¡A¦p¦C¦L¸ê®Æ¡C¦¹¥~¡A¤@¨Ç¸ê®Æ®w¤ÞÀº¡]³ÌÅãµÛ¦a¡AMicrosoft Jet¤ÞÀº¡^¤º³¡¨Ï¥Î¦h°õ¦æºü¡C
¨Ï¥ÎªÌ¤¶±ªº°ÝÃD
¡@
Visual Basic 6Åý±z«Ø¥ß´£¨Ñ¨Ï¥ÎªÌ¤¶±ªº¦h°õ¦æºü¤¸¥ó¡]±z¦bVisual Basic 5¤¤»ÝnService Pack 2¥H´£¨Ñ³o¶µ¥\¯à¡^¡C±z¥i¥H¹F¨ì³oӥتº¬O¦]¬°©Ò¦³±z«Ø¥ßªºªí³æ¥H¤ÎActiveX±±¨î¶µ¬O¦w¥þ©ó°õ¦æºüªº¡]thread safe¡^¡A¤]´N¬O»¡¦b¨C¤@Ó°õ¦æºü¤¤ªº°õ¦æÓÅé¬O¤£¬ÛÃöªº¡C¦bActiveX¤å¥ó¥H¤Î³]p®v¤]¬O¬Û¦Pªº¡A¨Ò¦pDataEnvironment³]p®v¡A©M¤j³¡¤À¦bpackage¤¤ªºActiveX±±¨î¶µ¤@¼Ë - Á|¨Ò¨Ó»¡¡AMaskEdBox ±±¨î¶µ¥H¤Î©Ò¦³Windows¤@¯ëªº±±¨î¶µ¡C
¦ý¬O¦³¤Ö¼ÆªºActiveX±±¨î¶µ¤Ñ¥Í´N¬O³æ¤@°õ¦æºü¨Ã¥B¤£¯à¦w¥þ¦a¨Ï¥Î©ó¦h°õ¦æºü¤¸¥ó¤¤¡ÐÁ|¨Ò¨Ó»¡¡AMicrosoft Chart (MSCHRT20.OCX)¥H¤ÎMicrosoft Data Bound Grid (DBGRID32.OCX)±±¨î¶µ¡C¦pªG±z¸Õ¹Ï±N³o¨Ç±±¨î¶µ¥[¤J¤@Ó°õ¦æºü¼Ò«¬¬°¤½´J¼Ò«¬ªºActiveX DLL ±M®×©Î¬O¥[¤J¤@Ó°õ¦æºü¼Ò«¬¬° ¿W¥ßªº°õ¦æºü ©Î¬O°õ¦æºü¼Æ¶q¤j©ó1ªº °õ¦æºü¦@¥Î°Ï ªºActiveX EXE ±M®×¡A±z·|±o¨ì¤@Ó¿ù»~°T®§¨Ã¥B±±¨î¶µ¤£¯à¥[¤J¤u¨ã¦C¤§¤¤¡C¦pªG±z¦³¤@Ó¤w¸g¥]§t¤@Ó¥H¤Wªº³æ¤@°õ¦æºü±±¨î¶µ¨Ã¥B±N±M®×Ãþ«¬§ó§ï¦¨»P³o¨Ç±±¨î¶µ¤£¬Û®e¡A±z¤]·|±o¨ì¤@Ó¿ù»~°T®§¡C·í±zÁʶR¤@Ó¨ä¥L¼t°Ó´£¨Ñªº±±¨î¶µ¡A½Ð»P½æ¥D®Ö¹ï±±¨î¶µ¬O§_¤ä´©¦h°õ¦æºü¡C
ª`·N
±z¥i¥H¤â°Ê½s¿èVBPÀÉ®×ÅýVisual Basic¦b¦h°õ¦æºüªº±M®×¤¤±j¨î±µ¨ü³æ¤@°õ¦æºüªºActiveX±±¨î¶µ¡CµM¦Ó¡A¦³³\¦h²z¥ÑÅý±z¤£n³o»ò°µ¡C¦b¦h°õ¦æºüÀ³¥Îµ{¦¡¤¤°õ¦æ³æ¤@°õ¦æºüªº®Ä¯à«Ü®t¡A¨Ã¥B·|²£¥Í³\¦h°ÝÃD¥H¤Î¤£¥i¹w´Áªº¦æ¬°¡CÁ|¨Ò¨Ó»¡¡ATabÁä¥H¤ÎAlt+Á䪺²Õ¦X¤£¯à¦p¤@¯ëªº¥¿±`¤u§@¡AÂI¨ú±±¨î¶µ¥i¯à¤£¯à±Ò°Êªí³æ¡C¦¹¥~¡A¦³¨ÇÄÝ©Ê(³Ì¯S§Oªº¬OPictureÄÝ©Ê)ªºÈ¤£¯à¦b°õ¦æºü¤§¶¡¶Ç»¼¡A¹Á¸Õ¥h°µ·|²£¥Í°õ¦æ®É´Áªº¿ù»~¡C
³o¸Ì¦³Ãö©ó¦h°õ¦æºü¤ºªºªí³æªº¤@¨Ç¤p°ÝÃD¡G
°õ¦æ®ÉµL¨Ï¥ÎªÌ¤¶±
¡@
¦pªG±zªº¤¸¥ó¤£¥]§t¤@Óªí³æ¡BUserControl©Î¬OUserDocument¤èªk¡A±z¥i¥HÂI¨ú ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤ªº ¤@¯ë ¶ÅÒªº °õ¦æ®ÉµL¨Ï¥ÎªÌ ¤¶±¡C³oªí¥Ü±zªº¤¸¥ó°õ¦æ®É¨S¦³¨Ï¥ÎªÌªº¤¬°ÊÃö«Y¡A·í±z«Ø¥ß¤@Ó»·ºÝ¹q¸£ªº¤¸¥ó®É¾A·íªº¿ï¶µ¡C
°õ¦æ®ÉµL¨Ï¥ÎªÌ¤¶± §í¨î¥ô¦ó°T®§¤è¶ô©Î¬O¤Íµ½ªº¨Ï¥ÎªÌ¤¶±¡]¥]§t¿ù»~°T®§¡^¨Ã¥B±N°T®§Âà¦s¨ì°O¿ýÀɮשάOWindows NTÀ³¥Îµ{¦¡¨Æ¥óÀ˵ø¾¹¡C±z¤]¥i¥H¶Ç°e¦Û¤vªº°T®§¹D°O¿ýÀɤ¤¡C¹ï©ó»·ºÝª«¥ó¨Ï¥Î¦¹¿ï¶µ¬O«D±`«nªº¦]¬°¥ô¦óªº°T®§¤è¶ô·|°±¤î¤¸¥óªº°õ¦æª½¨ì¨Ï¥ÎªÌÃö³¬°T®§¤è¶ô¡A·í¨Æ·í¤¸¥ó¦b»·ºÝ°õ¦æ®É¨S¦³¤¬°Êªº¨Ï¥ÎªÌ·|¹ê»Ú¥hÃö³¬°T®§¤è¶ô¡C
Appª«¥óªº StartLogging ¤èªkÅý±z¿ï¾Ü±zªº°T®§±N°e¨ì¦ó³B¡C»yªk¦p¤U¡G
App.StartLogging LogFile, LogMode
LogFile ¬O°O¿ýÀɪº¦WºÙ¡ALogMode ªí16-2¤¤ªº¤@ÓÈ¡CVbLogOverwrite¥H¤ÎvbLogThreadID ªº³]©w¥i¥H»Pªí¤¤¨ä¥LªºÈµ²¦X¡C·í±z¶Ç°e¤@Ó°T®§µ¹Windows NTÀ³¥Îµ{¦¡¨Æ¥óÀ˵ø¾¹¡A"VBRunTime" ·í§@À³¥Îµ{¦¡ªº¨Ó·½¡AApp.Title ÄÝ©Ê¥X²{¦b´yz¤¤¡C·í±z¦bWindows 95©Î¬O98°õ¦æ®É¡A°T®§°e¨ì¹w³]ªºVbevents.logÀɮסC
»¡©ú
¤p¤ß¨âÓ¿ù»~¡C²Ä¤@¡B¦pªG±z«ü©w¤@Ó¤£¦Xªkªº¦WºÙ¡A¤£·|¦³¿ù»~²£¥Í¨Ã¥B¤£ª¾¤£Ä±¦a±N°T®§°e¨ì¹w³]ªº¦a¤è¡C¨Ã¥B¡AvbLogOverwrite¿ï¶µ¨Ï±o StartLogging ¤èªkªº¦æ¬°¦p¦PvbLogAuto¿ï¶µ³Q«ü©w¡C©Ò¥H±zÀ³¸ÓÁ`¬O¤â°Ê§R°£°O¿ýÀɨåB¤£n¬Û«HvbLogOverwrite¿ï¶µ¡C
±`¼Æ | È | ´yz |
---|---|---|
VbLogAuto | 0 | Y±z¦b Windows 95 ¤W°õ¦æ¡A«h³oӿﶵ·|µù¥U°T®§¨ì LogFile ÄÝ©Ê©Ò«ü©wªºÀɮפ¤¡C¦ýY±z¬O¦b Windows NT ¤W°õ¦æ¡A«h·|µù¥U¨ì Windows NT À³¥Îµ{¦¡ Event Log ¤¤¡C¥H¡uVBRunTime¡v§@¬°À³¥Îµ{¦¡ªº¨Ó·½¡A¨Ã¥H App.Title §@¬°´yz¡C |
VbLogOff | 1 | Ãö³¬©Ò¦³ªºµù¥U¡C±q UI Âà´«¥H¤Î±q LogEvent ¤èªk¤¤ªº°T®§³£·|©¿²¤¨ÃÃö³¬¡C |
VbLogToFile | 2 | ±j¨îµn¤J¨ìÀɮפ¤¡C¦pªG¦b LogPath ¤¤¨S¦³¥i¨Ï¥ÎªºÀɮצWºÙ¡A¨º»ò±N©¿²¤µù¥U¡A¨Ã³]©wÄݩʬ° vbLogOff¡C |
VbLogToNT | 3 | ±j¨îµn¤J¨ì NT ¨Æ¥óµù¥UÀɤ¤¡CY¤£¬O¦bWindows NT ¤W°õ¦æ¡A©Î¨Æ¥óµù¥UµL®Ä¡A±N©¿²¤µù¥U¡A¨Ã±NÄݩʳ]©w¬°vbLogOff¡C |
VbLogOverwrite | 16 | «ü¥Ü¨C¦¸±Ò°ÊÀ³¥Îµ{¦¡®É¡AÀ³¸Ó«·s«Ø¥ßµù¥UÀÉ¡CY¨Ï¥Î OR ¹Bºâ¤l¡A«K¥i»P¨ä¥L¼Ò¦¡ªº¿ï¶µ¨Ã¥Î¡C¦Óµù¥Uªº¹w³]°Ê§@¬°ªþ¥[¨ì²{¦sªºÀɮפ¤¡C¦b NT ¨Æ¥óµù¥Uªº±¡ªp¤U¡A³oÓºX¼Ð´N¤£¨ã¥ô¦ó·N¸q¡C |
VbLogThreadID | 32 | «ü¥X¦bªí³æ ¡u[T:0nnn]¡v ¤¤¡A¥Ø«e³Q¹w³]¨ì°T®§¤¤ªº³q¦æ ID ¡CY¨Ï¥Î OR ¹Bºâ¤l¡A«K¥i»P¨ä¥L¼Ò¦¡ªº¿ï¶µ¨Ã¥Î¡C¥u¦³·íÀ³¥Îµ{¦¡¬°¦h¤u¨Ï¥Î®É¡A¹w³]°Ê§@¤~·|Åã¥Ü³q¦æ ID (¥i¯à¬O©ú½T¼Ð¥Ü¬°¦w¥þ³q¦æªº¡A©ÎªÌ¬O§@¬°³B²z¦h¤u¨Ï¥ÎÀ³¥Îµ{¦¡ªº¤u¨ã¡A¨Ò¦p¦h¤u¨Ï¥Îªº°Ï°ì¦øªA¾¹¡A¨ä¬YÓÄݩʳ]©w Single-Use)¡C |
ªí16-2 Appª«¥óªºStartLogging¤èªkªºLogMode¤Þ¼Æ©Ò¦³ªºÈ¡Q³o¨Ç¤]¬OLogMode °ßŪÄÝ©Ê¥i¯à¶Ç¦^ªºÈ¡C |
¤@¦ý±z¤w¸g³]©w°O¿ýÀÉ¡A±z¥i¥H¨Ï¥ÎAppª«¥óªº LogEvent ¤èªk°O¿ý°T®§¡C»yªk¦p¤U¡G
App.LogEvent LogMessage, EventType
LogMessage ¬O°T®§ªº¤å¦r¤º®e¡AEventType ¿ï¾Ü©Êªº¤Þz¡A¥Nªí¨Æ¥óÃþ«¬ªºª¬ºA¡]¤U¦Cȱo¨ä¤¤¤§¤@¡G1-vbLogEventTypeError¡B2-vbLogEventTypeWarning©Î¬O4-vbLogEventTypeInformation¡^¡CÁ|¨Ò¨Ó»¡¡A¤U¦Cµ{¦¡½Xªº¤ù¬q¡G
App.StartLogging "C:\Test.Log", vbLogAuto App.LogEvent "Application Started", vbLogEventTypeInformation App.LogEvent "Memory is running low", vbLogEventTypeWarning App.LogEvent "Unable to find data file", vbLogEventTypeError MsgBox "Press any key to continue", vbCritical
¦pªG¦bWindows 95 ©Î¬O 98 °õ¦æ¡A±N¿é¥X°e¨ìC:\TEST.LOG ÀɮסA©Î¬O¦bWindows NT°õ¦æ¡A«h¿é¥X¨ìÀ³¥Îµ{¦¡¨Æ¥óÀ˵ø¾¹¡C¡]¨£¹Ï16-19¡^
¡@
¹Ï16-19 Visual BasicÀ³¥Îµ{¦¡©Ò²£¥Íªº°O¿ý°T®§¡A¥X²{¦b¤@Ó°O¿ýªº¤å¦rÀɤ¤¡}¤W±ªºµøµ¡¡~©Î¬OWindows NTÀ³¥Îµ{¦¡¨Æ¥ó°O¿ý¾¹¤¤(©³¤Uªºµøµ¡)¡C |
±z¥i¥H±qAppª«¥ó°ßŪªº UnattendedApp Äݩʱqµ{¦¡¤¤´ú¸Õ¡u°õ¦æ®ÉµL¨Ï¥ÎªÌ¤¶±¡vÄÝ©Ê¡C¦P¼Ë¦a¡A±z¥i¥H¨Ï¥ÎAppª«¥óªº LogPath ¥H¤Î LogMode ÄݩʤÀ§O¦a¨ú¥X¥¿½Tªº°O¿ýÀÉ®×¥H¤Î°O¿ý¼Ò¦¡¡C·í±z¨Ï¥Î¡u°õ¦æ®ÉµL¨Ï¥ÎªÌ¬É±¡vÄݩʽsĶµ{¦¡¡A©Ò¦³ªº MsgBox ©R¥O°e¥X¿é¥Xµ¹¤©°O¿ýÀɩάOWindows NTÀ³¥Îµ{¦¡¨Æ¥ó°O¿ý¾¹¡A¦p¦P LogEvent ¤èªk¥[¤W vbLogEventTypeInformation ¤Þ¼Æªºµ²ªG¡C
³Ì«ánª`·Nªº¡G¦pªG±z¦bVisual Basic IDE¤¤°õ¦æµ{¦¡¡A¡u°õ¦æ®ÉµL¨Ï¥ÎªÌ¤¶±¡v ³]©w¨S¦³¼vÅT¡A©Ò¦³ªº°T®§¤è¶ô¦p¦P¤@¯ë¦aÅã¥Ü¦b¿Ã¹õ¤W¡A¨Ã¥B App.StartLogging ¥H¤Î App.LogEvent ¤èªk¤£¯à¨Ï¥Î¡Cn±Ò°Ê°O¿ý¼Ò¦¡¡A±z¥²¶·±NÀ³¥Îµ{¦¡½sĶ¦¨³æ¤@ªºÀ³¥Îµ{¦¡¡C
¦h°õ¦æºüActiveX DLL ¤¸¥ó
¡@
±z¥i¥H¨Ï¥ÎVisual Basic 6«Ø¥ß¦h°õ¦æºüªºActiveX DLL¡CµM¦Ó¡A¤£¦P©óActiveX EXE¦øªA¾¹¡AVisual BasicªºDLL¤£¯à«Ø¥ß·sªº°õ¦æºü¨Ã¥B¥u¯à¨Ï¥Î¥¦Ì«È¤áºÝªº°õ¦æºü¡C¦]¦¹¡A¦h°õ¦æºüDLL³Ì±`¨Ï¥Î©ó¦h°õ¦æºü«È¤áºÝÀ³¥Îµ{¦¡¡C¦]¬°¤@ÓActiveX DLL¹ê»Ú¤W¤£¯à«Ø¥ß¥ô¦óªº°õ¦æºü¡A¦b ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤ªº¿ï¶µ¦p¦P¤@ÓActiveX EXE±M®×©Ò´£¨Ñªº¤@¯ë¡C¹ê»Ú¤W¡A±z¥u¯à¨M©w«Ø¥ß¤@Ó ³æ¤@°õ¦æºü ©Î¬O ¤½´J¼Ò«¬°õ¦æºü ¦øªA¾¹¡C¡]¨£¹Ï16-20¡^¡C
³æ¤@©Î¬O¦h«°õ¦æºü¤¸¥ó³£¬O¦w¥þªº°õ¦æºü¡]thread safe¡^¡A³oªí¥Ü·í¤@Ó°õ¦æºü¤¤ªºª«¥ó³Q¨ä¥L°õ¦æºü©Ò©I¥s¡A©I¥sªº°õ¦æºü·|¼È°±ª½¨ì³Q©I¥sªÌ¶Ç¦^¡C³oÁקK¤F¤j¦h¼Æ«½Æ¶i¤J¡]reentrancy¡^ªº°ÝÃD¨Ã¥B¤j¶q´î§Cµ{¦¡³]p¤Hûªº¤u§@¡C
ÁöµM¹ï¦h°õ¦æºü«È¤áºÝ¨Ï¥Î³æ¤@°õ¦æºüDLL¬O¬Û·íªº¦w¥þ¡A¦ý¦b¥DÀ³¥Îµ{¦¡¤¤¥u¦³¤@Ó°õ¦æºü¥i¥Hª½±µ¦a©I¥sDLL©Ò«Ø¥ßªºª«¥óªº¤èªk¡C³oÓ¯S®íªº°õ¦æºü¬O«È¤áºÝÀ³¥Îµ{¦¡²Ä¤@ӫإߪº°õ¦æºü¡A§óºë½Tªº»¡¡A¬O²Ä¤@Ó¤º³¡©I¥s OleInitialize ¨ç¼Æªº°õ¦æºü¡C©Ò¦³³æ¤@°õ¦æºüDLL©Ò´£¨Ñªº©Ò¦³ª«¥ó³Q«Ø¥ß¦b³oÓ°õ¦æºü¤¤; ·í¥¦Ì³Q«È¤áºÝÀ³¥Îµ{¦¡¤¤ªº¨ä¥L°õ¦æºü¨Ï¥Î¡A¤Þ¼Æ¥H¤Î¶Ç¦^ȱµ¨üºÙ¬°°õ¦æºü¶¡ªº¥~³¡°Ñ¼Æ¶Ç»¼¡]cross-thread marshaling¡^¡A´X¥G¸ò³B²zºü¶¡ªº¥~³¡°Ñ¼Æ¶Ç»¼¡]cross-process marshaling¡^¤@¼ËºC¡C
¡@
¹Ï 16-20 ¦b¦b¡u±M®×ÄÝ©Ê¡v¹ï¸Ü¤è¶ô¤¤¿ï¾Ü°õ¦æºü¼Ò«¬¿ï¶µ¡C |
·í±z¤£ª¾¹D¦p¦ó±zªºDLL·|¦p¦ó³Q¨Ï¥Î®É¡A¤½´J°õ¦æºü¼Ò«¬³q±`¬O³Ì¨Îªº¿ï¾Ü¡C¨Æ¹ê¤W¡A¤@Ó¦h°õ¦æºüDLL¥i¥H³Q³æ¤@°õ¦æºü«È¤áºÝ©Ò¨Ï¥Î¡A¤£·|¦³¥ô¦ó°ÝÃD©Î«¤jªº¨t²Ît¾á¡C¦b¤@Ó¨Ò¤l¤¤¡A¤@Ó³æ¤@°õ¦æºüDLL¥i¥H¤è«K¦a³Q¤@Ó¦h°õ¦æºü«È¤áºÝ¨Ï¥Î¡A¤]´N¬O»¡¡A·í±z·Qn´£¨Ñ«È¤áºÝ©Ò¦³ªº°õ¦æºü¤@Ó²³æªº¤èªk¬Û¤¬ªº·¾³q¥H¤Î¤À¨É¸ê®Æ¡CÃö©ó³oÓ§Þ¥©ªº¤@Ó½d¨Ò¦b¥»³¹µy«áªº¡q´ú¸Õ¦h°õ¦æºüÀ³¥Îµ{¦¡¡r¤¤¡C
¦h°õ¦æºüVisual Basic À³¥Îµ{¦¡
¡@
³\¦hµ{¦¡³]p¤Hû¨S¦³·NÃѨìVisual Basic¥i¥H«Ø¥ß¦h°õ¦æºüªº¥¿³WªºÀ³¥Îµ{¦¡¡A¦Ó¤£¥u¬O¤¸¥ó¡C¦Ñ¹ê»¡¡A«Ø¥ß¦p¦¹ªº¦h°õ¦æºüÀ³¥Îµ{¦¡¨Ã¤£¦p¨Ï¥Î¨ä¥LªºVisual Basicªº¯S®í¥\¯à¤@¼Ëªºª½±µÂ²³æ¡A¨Ã¥B±zn¸Ñ¨M¤@¨Ç«nªº°ÝÃD¡C
«Ø¥ß¦h°õ¦æºüÀ³¥Îµ{¦¡ªº¯µ³Z¬O²³æªº¡GÀ³¥Îµ{¦¡¥²¶·¬O¤@Ó¦h°õ¦æºüªºActiveX EXE¦øªA¾¹¡A¨Ã¥B´£¨Ñ¤@Ó¥H¤W¦b¤£¦P°õ¦æºü°õ¦æªºª«¥ó¡Cn«Ø¥ß³o¼ËªºÀ³¥Îµ{¦¡¡A¥²¶·§¹¥þ²Å¦X¥H¤U©Ò¦C¥Xªº±ø¥ó¡G
·í±z¨Ï¥ÎNew¹Bºâ¦¡«Ø¥ß¤@ÓÀ³¥Îµ{¦¡©Ò´£¨Ñªºª«¥ó¡AVisual Basic¨Ï¥Î¤@Ó¤º³¡ªº«Ø¥ß°õ¦æÓÅ骺¤è¦¡¡A¸õ¹LCOM¨Ã¥B¨Ï¥Î¤@ӧ󦳮IJv¡B¤£±µ¨ü¥ô¦ó¨îªº¾÷¨î¡C¡]¨Æ¹ê¤W¡A±z¬Æ¦Ü¥i¥H±qPrivate©Î¬OPublicNotCreatableÃþ§O«Ø¥ßª«¥ó¡C¡^¤Ï¤§¡A·í±z¨Ï¥Î CreateObject¡AVisual BasicÁ`¬O³z¹LCOM«Ø¥ßª«¥ó¡C¦]¦¹¡Aª«¥óÀ³¸Ó¬O¥i«Ø¥ßªº(MultiUse)¡C
¨M©w¥D°õ¦æºü
¡@
¦p¦P¤§«eµ§ªÌ»¡©úªº¡A¦b¤@ÓVisual Basic¦h°õ¦æºüÀ³¥Îµ{¦¡¤¤ªº Sub Main µ{§Ç¦b¨C¤@¦¸¤@Ó·s°õ¦æºü«Ø¥ß®É´N°õ¦æ¡C³o³q±`¹ï©óActiveX EXE©Î¬ODLL¨Ó»¡¤£¬O¤@Ó°ÝÃD¡A¦ý¬O·í±z«Ø¥ß¤@ÓActiveX EXE¦h°õ¦æºüÀ³¥Îµ{¦¡®É¡A³o«o¬O¤@Ó°ÝÃD¡C¦b³oÓ¨Ò¤l¤¤¡A«Ü«nªº¨Æ¬O±zn§â²Ä¤@¦¸ªº°õ¦æ»P¨ä¥L©Ò¦³ªº°õ¦æ¤À§O¥X¨Ó¡C·í²Ä¤@¦¸ Main µ{§Ç°õ¦æ®É¡Aµ{¦¡¥²¶·Åã¥Ü¥X¥Dnªºµøµ¡¡A¤Ï¤§¨ä¥L©Ò¦³ªº°õ¦æ¤£À³¸ÓÅã¥Ü¥ô¦ó¨Ï¥ÎªÌ¤¶±¡C§óºë½T¦a»¡¡A·íµ{§Ç³Q°õ¦æ¦p¦P¹ï©ó¤@Ó·sª«¥ó½Ð¨Dªºµ²ªG®É¡AÀ³¸Ó°¨¤WÂ÷¶}¥HÁקK¦]²£¥Í¹O®É¿ù»~¦Ó½Ð¨D¥¢±Ñ¡C¦]¦¹¡A±z±q¤£À³¸Ó¦b Class_Initialize ¨Æ¥óµ{§Ç¤¤°õ¦æ¤¾ªøªº°Ê§@¡C
n¤F¸Ñ Main µ{§Ç¤§«e¬O§_±q¨Ó¨S¦³°õ¦æ¹L¨Ã¤£¬O¤@¥ó´¶³qªº¤u§@¡C±z¤£¯à²³æ¦a¨Ï¥Î¤@Ó¥þ°ìÅܼƧ@¬°ºX¼Ð¡A¦]¬°Åܼƨ䣯à³Q¨ä¥L¤½´J¤¤ªº°õ¦æºü¬Ý¨ì¡C¦b Main ¤¤«Ø¥ß¤@ӼȦsÀɮפ]¤£¬O¤@Ó¥i¦æªº¤è¦¡¡A¦]¬°À³¥Îµ{¦¡¥i¯à¦]¬°ÄY«ªº¿ù»~¦Ó²×¤î¨Ã¥B¦b¤]¤£·|¥h±þ±¼³oӼȦsÀÉ¡C
³o¸Ì¦³¦Ü¤Ö¨âºØ¤èªk¸Ñ¨M³oÓ°ÝÃD¡C²Ä¤@ºØ¬O°ò©óWindowsªº FindWindow API¨ç¼Æ¡A¦bVisual Basicªº¤å¥ó¤¤¦³©Ò´yz¡C¦b¤U¤@¶¤¤¡Aµ§ªÌ±N·|®i¥Ü¥t¤@ºØ¤èªk¡A³oºØ¤èªkµ§ªÌ¬Û«H¸û¤£½ÆÂø¨Ã¥B¸û¦³®Ä²v¡A¦]¬°¤£»Ýn±z«Ø¥ß¤@Óµøµ¡¡C³oÓ¤èªk¬O°ò©óì¤lª«¥ó( atom objects)¡A¥ÑWindows§@·~¨t²Î¾ã²z¤ÀÃþ¥þ°ìÅܼơCWindows API´£¨Ñ¨ç¼ÆÅý±z¼W¥[¤@Óatom¡B§R°£¤@Ó¦s¦bªºatom©Î¬O¬d¸ß¤@ÓatomªºÈ¡C
¦b¦h°õ¦æºüÀ³¥Îµ{¦¡¤¤ªº Main µ{§Ç¡A±z´ú¸Õ¤@Óµ¹¤©ªºatom¬O§_¦s¦b¡C¦pªG¤£¦s¦b¡A³o¬OÀ³¥Îµ{¦¡ªº²Ä¤@Ó°õ¦æºü¡A¨Ã¥B±z»Ýn«Ø¥ß¤@Óatom¡Cn¨Ï³oÓ¤èªk¶¶§Q¤u§@¡A±z¥²¶·¦bÀ³¥Îµ{¦¡Â÷¶}®É§R°£atom¡C¦b¤@ÓÃþ§O¤¤²z·Qªº¬O¦b Class_Initialize µ{§Ç¤¤«Ø¥ßatom¡A¦b Class_Terminate µ{§Ç¤¤·´·À«Ø¥ßatom¡C³o¸Ì¬O¦bÀH®ÑCD¤¤À³¥Îµ{¦¡½d¨Ò¤¤CthreadÃþ§O§¹¾ãªºì©lµ{¦¡½X¡C
Private Declare Function FindAtom Lib "kernel32" Alias "FindAtom" _ (ByVal atomName As String) As Integer Private Declare Function AddAtom Lib "kernel32" Alias "AddAtomA" _ (ByVal atomName As String) As Integer Private Declare Function DeleteAtom Lib "kernel32" _ (ByVal atomName As Integer) As Integer Private atomID As Integer Private Sub Class_Initialize() Dim atomName As String ' Build an atom name unique for this instance of the application. atomName = App.EXEName & App.hInstance ' Create the atom if it doesn't exist already. If FindAtom(atomName) = 0 Then atomID = AddAtom(atomName) End Sub Private Sub Class_Terminate() ' Delete the atom when this thread terminates. If atomID Then DeleteAtom atomID End Sub Function IsFirstThread() As Boolean ' This is the first thread if it was the one which created the atom. IsFirstThread = (atomID <> 0) End Function
atomªº¦WºÙ¬O¥HÀ³¥Îµ{¦¡ªº¦WºÙ¥H¤Î°õ¦æÓÅ骺handle(App.hInstance ÄÝ©Ê)©Ò«Ø¥ß¡C«á±ªºÈ¹ï©ó¦P¼ËÀ³¥Îµ{¦¡ªº¨CÓ¤£¦Pªº°õ¦æÓÅé³£¬O¤£¦Pªº¡A¥H½T«O¨Ï¥ÎªÌ±Ò°Ê¦P¼Ëµ{¦¡ªº¦hÓ°õ¦æÓÅé®É¥i¥H¥¿±`ªº¤u§@¡CCThread Ãþ§O¼Òªý¤î´£¨Ñ¤@Ó¤èªk¡AIsFirstThread¡C¥H¤Uªºµ{¦¡®i¥Ü±z¦p¦ó¦b¦h°õ¦æºüÀ³¥Îµ{¦¡¤¤¨Ï¥Î³oÓÃþ§O¤F¸Ñ¦¹°õ¦æºü¬O§_¬°²Ä¤@Ó°õ¦æºü¡C
' This is global because it has to live for the entire application's life. Public Thread As New CThread Sub Main() If Thread.IsFirstThread Then 'First thread, refuse to be instantiated as a component. If App.StartMode = vbSModeAutomation Then Err.Raise 9999, , "Unable to be instantiated as a component" End If 'Show the user interface. frmMainForm.Show Else ' This is a component instantiated by this same application. End If End Sub
¹ê§@¦h°õ¦æºü
¡@
¨Ï¥Î CreateObject ¨ç¼Æ«Ø¥ß¤@Ó·sªº°õ¦æºü¹ê»Ú¤W¤£¨¬¥H¹ê§@¤@Ó¦h°õ¦æºüªºVisual BasicÀ³¥Îµ{¦¡¡C¨Æ¹ê¤W¡AVisual Basic©Ò´£¨Ñªº¦P¨B³B²zªº§Þ³N¥i¥H¨¾¤î¤@¨ÇÃø¥H³B²zªºÄY«°ÝÃD¡A¦p¦b³oÓ¨Ò¤l¤¤©Ò¬Ý¨ìªº¡C·í¤@Óµ{¦¡¤Þ¥Î¤@Ó¨ä¥L°õ¦æºüª«¥óªº¤èªk®É¡A©I¥sºÝªº°õ¦æºü¤@ª½°±¤î¦íª½¨ì©Ò©I¥sªº¤èªk¦^¶Ç¡C©Ò¥H±z¥i¯à¦³¦hÓ°õ¦æºü¡A¦ý¬O¦P®É¥u¦³¤@Ó°õ¦æºü¦b¯S©wªºªº®É¶¡¸Ì°õ¦æ¡A³oÅãµM¤£¬O±z©Ò·Qnªº¡C
§ïÅܳoÓ°ÝÃDªºÂ²³æ¤èªk´N¬O¨Ï¥Î¤@ÓTimerªº±±¨î¶µ¡A¦b¤£¦Pªº°õ¦æºü¶Ç¦^±±¨îÅvµ¹©I¥sªº°õ¦æºü¤§«á¡A¡u¥s¿ô¡v³oÓ¤£¦P°õ¦æºü¤¤ªºª«¥ó¡C±z¤£»Ýn¤@Ó¥i¨£ªºªí³æ¨Ó¹F¨ì¦¹¥\¯à¡C±z¥i¥H§Q¥Î·sªº CallByName ¨ç¼Æ¨Ó«Ø¥ß¤@Óªí³æ¼Ò²Õ¡A±z¥i¥H¦b©Ò¦³»Ýn³oºØ¦^©I§Þ¥©ªºÀ³¥Îµ{¦¡¤¤«½Æ¨Ï¥Î¡C¤U±¬O«Ê¸Ë³oºØ¥\¯àªºCCallBackªí³æ¼Ò²Õªº§¹¾ãµ{¦¡½X¡C
Dim m_Obj As Object Dim m_MethodName As String Public Sub DelayedCall(obj As Object, Milliseconds As Long, _ MethodName As String) Set m_Obj = obj ' Save the arguments. m_MethodName = MethodName Timer1.Interval = Milliseconds ' Start the timer. Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Timer1.Enabled = False ' We need just one call. Unload Me CallByName m_Obj, m_MethodName, VbMethod ' Do the callback. End Sub
CcallBackªí³æ¥i¥H¦bÀ³¥Îµ{¦¡ªº¨ä¥L³¡¤À¥H¤@Óª«¥ó¼Ò²Õªº¤è¦¡¨Ï¥Î¡C¦bÀH®Ñ¥úºÐ¤¤¡A±z±N§ä¨ì¤@Ó²³æªº¦h°õ¦æºüÀ³¥Îµ{¦¡½d¨Ò¡AÀ³¥Îµ{¦¡¥i¥H«Ø¥ß¥H¤ÎÅã¥Ü¦h«ªº count-down ªí³æ(¨£¹Ï16-21¡C) ³o¬O¤@Óª«¥óÃþ§Oªº³¡¥÷µ{¦¡½X¡A·í¥DÀ³¥Îµ{¦¡n¦b¥t¤@Ó°õ¦æºü¤¤«Ø¥ß¤@Ó·sªºË¼Æªí³æ®É¡Aµ{¦¡½X·|t³dªì©l¤Æ¡C
(¹ê§@¦^©I§Þ¥©ªºµ{¦¡¥H²ÊÅé¦Ûªí¥Ü)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim frm As frmCountDown Dim m_Counter As Integer 'The Counter property. Values > 0 display the form and start ' the countdown. Property Get Counter() As Integer Counter = m_Counter End Property Property Let Counter(newValue As Integer) Dim cbk As New CCallBack m_Counter = newValue cbk.DelayedCall Me, 50, i.Start" End Property Sub Start() Static active As Boolean If active Then Exit Sub 'Prevent reentrancy. active = True ' The code that shows the countdown form (omitted...) ' ... active = False End Sub
¡@
¹Ï16-21 ¦h°õ¦æºüÀ³¥Îµ{¦¡ªº½d¨Òcountdown¡Cª`·N¨C¤@Ówindow¦b¼ÐÃDÅã¥Ü¤@Ó¤£¦Pªº°õ¦æºüID¡C |
³o¬O count-down ½d¨ÒÀ³¥Îµ{¦¡¥Dªí³æ¤¤ªºµ{¦¡½X¡G
Private Sub cmdStart_Click() Dim x As CCountDown ' Create a new CCountDown object in another thread. Set x = CreateObject("MThrApp.CCountDown") ' Set the counter using the value currently in the TextBox control. x.Counter = Val(txtSeconds) Set x = Nothing Beep End Sub
ª`·N
¥H¹ê§@Visual Basic¦h°õ¦æºü¨Ó»¡¡A³o¸Ì¦³¤@Ó¨S¦³¤å¥ó°O¸üªºnÂI¡A±zÀ³¸Ó¯S§Oª`·Nªº¡C¦pªGª«¥ó¥¿¦b°õ¦æ¬Y¨Çµ{¦¡½X¡A¦Ó«È¤áºÝ±N³Ì«á¤@Óª«¥óªº¤Þ¥Îª½±µ©Î¬O¶¡±µ¦a³]¬°Nothing¡A¨º»ò«È¤áºÝ·|¤@ª½µ¥«Ý¨ìª«¥ó¤¤ªºµ{§Ç²×¤î¡C³o¤@ÂI«Ü«nªº¡CÁ|¨Ò¨Ó»¡¡A¦pªG±z¦b«e±ªºµ{§Ç¤¤§R°£¤F Set x = Nothing ±Ôz¡A¨º»ò·íª«¥ó¤w¸g³Q¦^©Iµ{§Ç¥s¿ô¨Ã¥B¥¿¦b°õ¦æ count-downµ{¦¡½X®É¡AxÅܼƦb Beep ±Ôz¤§«á·|³Q³]¬°Nothing¡C³oªí¥Ü«È¤áºÝ»Ýnµ¥«Ý±Nªñ10¬íÄÁ¡Aª½¨ìª«¥ó§¹¥þ¦a¾P·´¡A¦b¦¹´Á¶¡¥Dªí³æµLªk¦^À³¨Ï¥ÎªÌªº°Ê§@¡C±z¥i¥H¿ï¾Ü±q¥H¤U¨âºØ¤è¦¡×¥¿³oÓ°ÝÃD¡G
´ú¸Õ¤@Ó¦h°õ¦æºüÀ³¥Îµ{¦¡
¡@
°»¿ù¤@Ó¦h°õ¦æºüªºÀ³¥Îµ{¦¡©Î¬O¤¸¥ó¨Ã¤£¹³°»¿ù¤@¯ëªºµ{¦¡¨º»ò²³æ¡CÁ|¤@¥ó¨Æ¨Ó»¡¡A±z¥²¶·±N¦h°õ¦æºüªºÀ³¥Îµ{¦¡©Î¬O¤¸¥ó½sĶ¦¨³æ¤@¿W¥ßªº°õ¦æÀÉ¡A¦]¬°Visual BasicªºIDEÀô¹Ò¥u¤ä´©³æ¤@°õ¦æºüªºÀ³¥Îµ{¦¡¥H¤Î¤¸¥ó¡C ³oªí¥Ü±z»Ýn±Ë±ó©Ò¦³Àô¹Ò©Ò´£¨Ñªº«K§Q³]¬I¡A¥]§t¤¤Â_ÂI¡BºÊ¬Ýµøµ¡¡B°Ï°ìÅܼƵøµ¡¥H¤Î³v¨Bªº°lÂܯà¤O¡C¦]¦¹¡A±z¥²¶·¦bÂà´«¨ì¦h°õ¦æºü«e¡A§¹¾ã¦a¦bÀô¹Ò¤¤´ú¸Õ±zªºÀ³¥Îµ{¦¡ªºÅÞ¿è¡A±z¥²¶·³]p¥X´À¥Nªº°»¿ùµ¦²¤¡CÁ|¨Ò¨Ó»¡¡A¦]¬°±z¤£¯à§Q¥Î Debug.Print ¤èªk±NÅܼÆȪ½±µ¦L¦b§Y®É¹Bºâµøµ¡¤¤¡A±z»Ýn¼g¤J¤@ÓÀɮשάO¨Ï¥Î²³æªºMsgBox©R¥O¡C¤@ӫܦnªº·Qªk´N¬O¦b±zªº°T®§¤¤Åã¥Ü°õ¦æºüID¡A³o¼Ë±z¥i¥HÀòª¾þ¤@Ó¯S§Oªº°õ¦æºü¥¿¦bÅã¥Ü°T®§¡G
MsgBox "Executing the Eval proc", vbInformation, "Thread: " & App.ThreadID
³æ¤@°õ¦æºüActiveX DLL¦øªA¾¹¹ï¦¹°ÝÃD´£¨Ñ¤@Ó¸û¦nªº¸Ñ¨M¤è¦¡¡C¥i¯à±zÁÙ°O±o¡A±z¥i¥H¦w¥þ¦a¦b¦h°õ¦æºü«È¤áºÝ¨Ï¥Î³æ¤@°õ¦æºüActiveX DLL¡A¤£ºÞ¥¦Ì¬O³æ¤@ªºÀ³¥Îµ{¦¡©Î¬O¤¸¥ó¡CÁ|¨Ò¨Ó»¡¡A±z¥i¥H¹ê§@¤@Ó´£¨ÑCLogª«¥óªºDLL¡ACLogª«¥ó¦¬¶°«È¤áºÝªº°lÂܸê°T¨ÃÂà¦V¨ì¤@ÓWindow¡C¹ê§@³o¼ËªºDLL¤£§xÃø¡C³o¸Ì¬O ClogÃþ§Oªºì©lµ{¦¡½X¡C¡]¦bÀH®Ñ¥úºÐ¤¤¦³§¹¾ãªº¡A¥]§tªþ¥[ªº¥\¯àªº®i¥Üµ{¦¡¡C¡^
' If this property is nonzero, the ThreadID is added to the message. Public ThreadID As Long Sub StartLogging(LogFile As String, LogMode As Integer) ' Note that this refers to the global hidden form reference. ' This form will therefore be shared by all the instances ' of the class. frmLog.Show End Sub Sub LogEvent(ByVal LogText As String) If ThreadID Then LogText = "[" & Hex$(ThreadID) & "]" & LogText End If frmLog.LogText.SelStart = Len(frmLog.LogText.Text) frmLog.LogText.SelText = LogText & vbCrLf End Sub
frmLog ªí³æÄÝ©óActiveX DLL±M®×¨Ã¥B¥]§tÅã¥Ü¨Ó¦Û¦h°õ¦æºü«È¤áºÝªº¤å¦r°T®§ªºtxtLog TextBox ±±¨î¶µ¡A¤@ÓCheckBox±±¨î¶µÅý¨Ï¥ÎªÌ±Ò°Ê¥H¤Î°±¤î¼g¤J¡A¨Ã¥B¤@ÓCommandButton±±¨î¶µ²M°£txtLog±±¨î¶µªº¤º®e¡C¦b¤U¤@¶ªº¹Ï16-22Åã¥Ü¤@Ó·sª©¥»ªº¦h°õ¦æºü½d¨Ò¡A¤w¸g¥[¤J°lÂܪº¯à¤O¡C¤U±¬Oקï¹LªºÀ³¥Îµ{¦¡ªºBAS¼Ò²Õ¡C
Public Log As New CLog Sub Main() Log.StartLogging "", 0 ' Initialize the CLog object. Log.ThreadID = App.ThreadID Log.LogEvent "Entering Sub Main" 'Here is the code that displays the main form (omitted...) '... Log.LogEvent "Exiting Sub Main" End Sub
¡@
¹Ï16-22 ¨Ï¥Î¤@Ó³æ¤@°õ¦æºüªºActiveX DLL ¼W¥[¦h°õ¦æºüÀ³¥Îµ{¦¡°lÂܪº¯à¤O¡C¨CÓ°T®§¥]§t¶Ç°õ¦æºüªºID¡C |
¹ï©ó§ó½ÆÂøªº´ú¸Õ¡A±zÀ³¸ÓÂI¨ú ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤ªº ½sĶ ¶ÅÒªº²£¥Í Symbolic¿ù»~¸ê°T ¿ï¶µ¡AµM«á«·s½sĶÀ³¥Îµ{¦¡¨Ã¥B¦b¤@Ó¯u¹êªº°»¿ù¾¹¤U°õ¦æ¡A³o¼Ëªº°»¿ù¾¹¦bMicrosoft Visual C++¤¤¡C
»·ºÝACTIVEX¤¸¥ó
¡@
ActiveX ¤¸¥ó¥i¥H¦b»·ºÝªº¥t¤@¥x¹q¸£¤W°õ¦æ¡C³o¼Ë¤@¥x¹q¸£¥i¥H¦b¬Û¦P©Î¬O¤£¦Pªº¾÷©Ð¤¤¡B¤£¦Pªº«Ø¿vª«¬Æ¦Ü¬O¤£¦Pªº«°¥«¡C·PÁÂCOM¦ì¸m³z©ú¤Æªº¯à¤O¡A«È¤áºÝÀ³¥Îµ{¦¡Á`¬Oı±o¤¸¥ó¦b¥»¾÷¤@¯ë¡C»P»·ºÝ¤¸¥ó°õ¦æªº°ß¤@¤@Ó°ÝÃD´N¬O©Ò¦³©I¥sª«¥ó¤èªk¥H¤ÎÄݩʪº°Ê§@³£«ÜºC¡C
°Q½×¦³ÃöCOM»·ºÝ°õ¦æ¤@Óª«¥óºÙ°µ Distributed COM¡A©Î¬O²ºÙDCOM¡A¦p¦Pµ§ªÌ¦b¦¹³¹¤¤©Ò¤¶²Ðªº¡CDCOM²Ä¤@¦¸¬O»PWindows NT 4µo¦æ¡A¨Ã¥BÀ³¸Ó«Ü²M·¡ªºªí¥Ü¡AWindowsNT¬O¨Ï¥Î»·ºÝª«¥óªº¿ï¾Ü¡A¦]¬°Windows NT¬O°ß¤@¦b¦h¨Ï¥ÎªÌªºÀô¹Ò¤¤¡A¥i¥H´£¨Ñ¥²nªº¦w¥þ©Ê¡C¦b¤@Ó¤À´²»s§@ªºÀô¹Ò¤¤¡AWindows 95¥H¤Î98¹q¸£À³¸Ó¥u¯à°µ¬°DCOM«È¤áºÝ¡C
Visual Basic¤]¤ä´©¨ä¥L»·ºÝ±Ò°Êªº¨î«¬ªí³æ¡ARemote Automation¡Cµ§ªÌ¤£·Q¦b¥»®Ñ¤¤°Q½×³oÓ¹L®Éªº§Þ³N¦]¬°³oÓ§Þ³N¤ñDCOMºC¨Ã¥B¤£¥i¾a¡C¦p¤µ¡A¨Ï¥ÎRemote Automation°ß¤@ªº²z¥Ñ´N¬O¤ä´©16-bit«È¤áºÝ¡A³o¬ODCOM¤£¥i¯à°µ¨ìªº¡A¦]¬°DCOM¬O¥u¾A¥Î©ó32-bitªº§Þ³N¡C
¦¹³¹³Ñ¤Uªº³¡¤À°Q½×¦³Ãö»·ºÝªºActiveX EXE¤¸¥ó¡C±z¤]¥i¥H¦b»·ºÝ°õ¦æ¤@ÓActiveX DLL¡A¥i¥H¨Ï¥Î¼Ð·Çªº¥N²z³B²z§Ç¡A¦pDllHost.Exe©Î¬O¨Ï¥ÎMicrosoft Transaction Server (MTS)¡C¦bMTS¤¤«Ø¥ß¤¸¥ó¤£¥]§t¦b¦¹®Ñ¤¤¡C
»¡©ú
ÁöµMWindows 95©Î¬O98ªº¹q¸£¦b²£«~Àô¹Ò¨Ó»¡¡A¤£¬O¤@Ó¦nªºDCOM¦øªA¾¹¡A¦ý¬O±z¤´µM¥i¥H¦bµo®i¶¥¬q§@¬°¦øªA¾¹¡C³o¤£¬O¤@Ó¦³®Ä²v¸Ñ¨M¤è¦¡¨Ã¥BÁÙ¦³¨ä¥Lªº¯ÊÂI¡CÁ|¨Ò¨Ó»¡¡A¨S¦³±Ò°Êªº¯à¤O¡ACOM¤¸¥ó¥²¶·¬O¤w¸g°õ¦æ¥H±µ¨ü»·ºÝªº½Ð¨D¡CÃö©ó§ó¦hªº¸ê°T¡A¨£Microsoft Knowledge Base article Q165101¡C
«Ø¥ß¥H¤Î´ú¸Õ¤@Ó»·ºÝ¤¸¥ó
¡@
¦pªG±z¤w¸g¦b¥»¾÷¹q¸£«Ø¥ß¨Ã¥B´ú¸Õ¤@ÓActiveX EXE¤¸¥ó¡AÂà´«¦¨»·ºÝ¤¸¥ó¤£»Ýn«¥ý½sĶ¡C±z©Òn°µªº¥u¬O¦b¥»¾÷¹q¸£ªºµn¿ý¸ê®Æ®w¤¤§ïÅÜ´XÓ¾÷½X¡A¦p¦¹©Ò¦³¹ï©ó¦¹ª«¥óªº½Ð¨D¦Û°ÊÂà¨ì¨ä¥Lªº¹q¸£¡C²z½×¤W¡A±z¥i¥H¥H±M·~ª©ªºVisual Basicµo¦æ»·ºÝ¤¸¥ó¡AµM¦Ó¡A¹ê»Ú¤W¡A¥u¦³¥ø·~ª©ªºVisual Basic¥]§t¥i¥HÅý±z®e©ö³¡¸p¤¸ºÝ¤¸¥óªº©Ò¦³¤u¨ã¡C
½sĶ®Éªº»·ºÝ¦øªA¾¹³]©w
¡@
²Ä¤@¥ó±z©Òn°µªº¨Æ¬O·í±z«Ø¥ß¤@Ó»·ºÝª«¥ó®É¡AÂI¨ú ±M®×ÄÝ©Ê ¹ï¸Ü¤è¶ô¤¤¤¸¥ó¶ÅÒ¤¤ªº »·ºÝ¦øªA¾¹ÀÉ®× ®Ö¨ú¤è¶ô¡A¦p¤U¶ªº¹Ï16-23©Ò¥Ü¡C¦pªG¿ï¾Ü¦¹¿ï¶µ¡A·í±z½sĶ±M®×®É¡AVisual Basic«Ø¥ß¨âÓªþ¥[ªºÀɮסCÀÉ®×¾Ö¦³¬Û¦Pªº¦WºÙ¦ý¬O°ÆÀɦW¤£¦P¡G.tlb«¬ºAµ{¦¡®w¥H¤Î.vbrµù¥UÀɮסC³o¨ÇÀÉ®×µy«á¨Ï¥Î©óµù¥U¤¸¥ó¦b«È¤áºÝ¤u§@¯¸ªºµn¿ý¸ê®Æ®w¤W¡A¦Ó¤£¥Î¹ê»Ú¦w¸ËEXEÀɮסC
¡@
¹Ï16-23 ·Ç³Æ¤@ÓActiveX EXE¤¸¥ó©ó»·ºÝ°õ¦æ¡C |
³]©w¦øªA¾¹
¡@
¤U¤@¨BÆJ´N¬O¦b¦øªA¾¹¤u§@¯¸¤W¦w¸Ë¥H¤Îµù¥U¤¸¥ó¡C±z¥i¥H½Æ»sEXEÀɮרì¤@Ó¥»¾÷ºÏºÐ¡A¨Ã¥B¦b©R¥O¦C¥[¤W /REGSERVER ¤Þ¼Æ°õ¦æ¦¹Àɮרӧ¹¦¨³o¨Ç¨BÆJ¡C±N¤¸¥ó©ñ¸m¦b¥»¾÷ºÏºÐ¾÷¦Ó¤£¬Oºô¸ôºÏºÐ¾÷ªº°µªk¬O©ú´¼ªº¡A¦]¬°³o¨Ç³]©w·|²£¥Í¤@¨Ç¦w¥þ¤Wªº°ÝÃD¡C¦b¤¸¥óµù¥U§¹¦¨«á¡A±z¥i¥HÄ~ÄòÅý¤¸¥ó¦b»·ºÝ«È¤áºÝ¥i¥H¨Ï¥Î¡C±z¥i¥H¿ï¾Ü¤@¨Ç¤u¨ã§¹¦¨³oºØ¤u§@¡C
²Ä¤@ӳ̲³æªº¤u¨ã¸s²Õ´N¬ORemote Automation Connection Manager¡C³oÓµ{¦¡¦³¤@ÓÂù«ªº¥Øªº¡G±z¥i¥H¨Ï¥Î «È¤áºÝ¦s¨ú ¶ÅÒªº©R¥O¨Ï¥»¾÷ªº¤¸¥ó¥i¥HÅý»·ºÝªº«È¤áºÝ¨Ï¥Î¡A¥H¤Î±z¥i¥H¦b«È¤áºÝªº¹q¸£¤W°õ¦æ³oÓ¤u¨ã¨Ó§ó§ïµn¿ý¸ê®Æ®w¤¤ªºÄæ¦ì¡A¦p¦¹©Ò¦³¨Ó¦Û¯S©wª«¥óªº½Ð¨D·|Âà´«¨ì¦øªA¾¹¹q¸£¡C
·íRemote Automation Connection Manager¶}©l®É¡A¥¦Åã¥Ü©Ò¦³¹q¸£¤W©Òµù¥Uªº¤¸¥óªº¦Cªí¡A¦p¹Ï16-24¡C¨Ï¥Î «È¤áºÝ¦s¨ú ¶ÅÒ¤¤ªº¿ï¶µ¡A±z¥i¥H¨M©wÓ§Oªº¤¸¥ó¬O§_À³¸Ó¥Ñ»·ºÝ±Ò°Ê¡C
¤£¤¹³\«Ø¥ß»·ºÝª«¥ó¡G ¦¹¶µ³]©wÅý©Ò¦³µù¥Uªº¤¸¥ó¤£¯à³Q»·ºÝ«È¤áºÝ©Ò¨Ï¥Î¡C
¤¹³\¨Ï¥Î¯Á¤Þ¨£«Ø¥ß»·ºÝª«¥ó¡G ±z¥i¥HÅýÓ§Oªºª«¥ó»·ºÝ±Ò°Ê¡A¨CÓ¤¸¥óªºª¬ºA¨Ì¾Ú ¤¹³\»·ºÝ±Ò°Ê Àˬd¤è¶ô¡C¦bWindows 98¥H¤Î95¨Ó»¡³o¬O¤@¶µ¦nªº¿ï¾Ü¦]¬°§@·~¨t²Î¤£¤ä´©ACLs (¨£¤U¤@ӿﶵ)¡C
¡@
¹Ï16-24 Remote Automation Connection Managerªº¡u«È¤áºÝ¦s¨ú¡v¶ÅÒ |
¤¹³\¨Ï¥ÎACL«Ø¥ß»·ºÝª«¥ó¡G ³oӿﶵ¥u¦³¦bWindows NT¤U¤~¥i¥H¨Ï¥Î¨Ã¥BÅý±z¨M©wþ¨Ç¨ÏªÌ¦P·N©Î¬O¤£¤¹³\¨Ï¥Î¤¸¥ó¡C
¤¹³\«Ø¥ß©Ò¦³»·ºÝª«¥ó¡G ©Ò¦³µù¥Uªº¤¸¥ó³£¥i¥H»·ºÝ±Ò°Ê¡A³oÓ³]©wÀ³¸Ó¥u¯à¥Î©óµo®i¥H¤Î°»¿ù¶¥¬q¡A¦]¬°³oÓ³]©w·|Åý¦øªA¾¹¹q¸£Ãø¥H¨¾¦u«È¤áºÝ´c·Nªº¯}Ãa¡C
´ú¸Õ«È¤áºÝ
¡@
¤@Ó§Ö³t´ú¸Õ±z¤¸¥ó¦p¦ó»·ºÝ¦a¤u§@ªº¤èªk¬O¦w¸Ë¦b¤@ӫȤáºÝªº¹q¸£¦p¦P¤@Ó¥»¾÷¤¸¥ó¤@¯ë¡}½Æ»sEXEÀɮרåB¥[¤W /REGSERVER ¤Þ¼Æ°õ¦æ¡~¡C±Ò°Ê«È¤áºÝÀ³¥Îµ{¦¡¡A½T©w¤@¤Á¦p¹w´Á¯ëªº¹B§@¡C³oÓ¨BÆJ¹ï©ó¾ã²z¤ÀªR¤¸¥ó¬°¦ó¤£¯à»·ºÝ±Ò°Êªº°ÝÃD¨Ó»¡¬O«Ü«nªº¡C
²{¦b±z¥i¥H°õ¦æRemote Automation Connection Manager¥H§ó§ïµn¿ý¸ê®Æ®w¡A¦p¦¹©Ò¦³ªºª«¥ó½Ð¨D±NÂà¦V¨ì¦øªA¾¹¡C¦b³oÓ¨Ò¤l¤¤¡A±z»Ýn¨Ï¥Îµ{¦¡ªº ¦øªAºÝ³sµ² ¶ÅÒ¡A¦p¤U¶ªº¹Ï16-25©Ò¥Ü¡A±z¿ï¾Ü Distributed COM ³]©wµM«á§Q¥ÎCtrl+R©Î¬O µù¥U ¥\¯àªí¤¤ªº »·ºÝ¹q¸£ ©Î¬O¦bµøµ¡¤¤«ö¤U·Æ¹«¥kÁä¿ï¨ú »·ºÝ¹q¸£ ¨Ïª«¥ó¦¨¬°»·ºÝ¡Cn§¹¦¨¦¹µù¥Uµ{§Ç¡A±z»Ýn«ü©w¤¸¥ó°õ¦æÓÅé©Ò¦bªººô¸ô¦ì¸m¡C·í±z¨Ï¥ÎDCOM®É¡A³oÓ¤u¨ã¤£¤¹³\±z«ü©wºô¸ô³q°T¨ó©w¥H¤Î»{ÃÒµ¥¯Å¡C
¦A¦¸°õ¦æ«È¤áºÝ¨Ã¥B½T©w¨C¤@¥ó¨Æ³£¥¿±`¤u§@¡A¦pªG±z¨S¦³µo¥Í¥ô¦ó¿ù»~¡Aª«¥ó±N·|¦b¦øªA¾¹«Ø¥ß¹êÅé¡C±z¥i¯à¦b¦øªA¾¹ªº¿Ã¹õ¤W¬Ý¤£¨ì»·ºÝª«¥ó¡A¦ý¬O·í«È¤áºÝ½Ð¨D®É±z¥i¥HÀˬd¨Ãµo²{¥X²{¦b³B²zºüªº¦Cªí¤¤¡C
¡@
¹Ï16-25 Remote Automation Connection Managerªº¡u¦øªAºÝ³sµ²¡v¶ÅÒ¡C |
CreateObject¨ç¼Æ
¡@
Visual Basic 6 §ï¶i¤F CreateObject ¨ç¼Æ¡A´£¨Ñ²Ä¤GÓ¿ï¾Ü©Êªº°Ñ¼Æ¡Aµ¹¤©«È¤áºÝ¥i¥H«ü©w¯S©wªº»·ºÝ¹q¸£«Ø¥ß°õ¦æÓÅé¡C¦p¤U¦Cµ{¦¡½X¡G
Set x = CreateObject("RemoteSvr.TestClass", "ServerNT")
³o¨Ç¥\¯àÅý¨Ï¥ÎªÌ¥i¥H¼g¥X§óÁo©úªº«È¤áºÝ¡A¥i¥H¹ê§@¥X¤@Ó®e¿ùªº¾÷¨î¡A¨Ã¥B¦pªGµn¿ý¸ê®Æ®w©Ò«ü¨ìªº¹q¸£¤£¯à¨Ï¥Î¡A¥i¥H¦b¥t¥~¤@¥x¤u§@¯¸«Ø¥ßª«¥óªº¹êÅé¡C·PÁ³o¶µ¯à¤O¡A¤@Ó¤À´²¦¡ªºÀ³¥Îµ{¦¡¤]¥i¥H¹ê§@¤@Óºë±Kªºt¸ü¥¿Å¡]load-balancing¡^ªººtºâªkÅýt¸ü«ªº¤¸¥ó¥i¥H¦b¶¢¸mªº¹q¸£¤W°õ¦æ¡C
³¡¸p¤¸¥ó
¡@
Remote Automation Connection Manager¹ï©ó´ú¸Õ³sµ²¨ì¤¸¥óªº«È¤áºÝÀ³¥Îµ{¦¡¨Ó»¡¬O«Ü¦nªº¡A¦ý¬O¥¦ªº¤¬°Ê¦¡©Ê½è«o§«Ãª¤F¹ê»Ú±N³o¨ÇÀ³¥Îµ{¦¡³¡¸p¨ì¦h¥x¤u§@¯¸¤W¡C³oÓ°ÝÃDªº¸Ñ¨M¤è¦¡¦b«È¤áºÝ³]©w¤u¨ã¡ACliReg32.Exe¡C±z¥i¥H¦bVisual Studio ¥D¥Ø¿ý¤UªºCommon\Tools\CliReg ¥Ø¿ý¤¤§ä¨ì³oÓÀɮסA¨Ã¥B±zÀ³¸Ó½T©w¥¦¬O¦b«È¤áºÝ¦w¸Ë«Ê¥]¤¤¡C
±z¡]©Î¬O±z¦w¸Ëªºµ{§Ç¡^»Ýn°õ¦æCliReg32À³¥Îµ{¦¡¨Ã¥B¶Ç»¼¤¸¥ó½sĶ®É©Ò²£¥ÍªºVBRÀÉ®×µ¹¤©CliReg32¡CVBR ÀÉ®×¥u¤£¹L¬O¤@Ó¤£¦P°ÆÀɦW¥H¤Î¤£¦PÀɮ׶}ÀYªºREGÀɮסCCliReg32¤u¨ãŪ¨ú³oÓÀɮסA¨Ï¥Î©R¥O¦C©Òµ¹¤©ªº³]©w¡A±N©Ò¦³¬ÛÃöªº¾÷½X¥[¤Jµn¿ý¸ê®Æ®w¤¤¡A»yªk¦p¤U¡G
CliReg32 <vbrfile> <options>
©Ò¦³¥i§Q¥Îªº¿ï¶µ¦C¦bªí16-3¡C
¿ï¶µ | ´yz |
---|---|
-d | ¨Ï¥ÎDCOM<¦Ó¤£¬ORemote Automation> |
-t <typelib> | «ü©wtypelibÀɬ°<typelib> |
-a | «ü©w¦w¥þ»{ÃÒµ¥¯Å¬°<a>¡]1-6¡^ |
-s <address> | «ü©wºô¸ô¦ì¸m<s> |
-p <protocol> | «ü©wºô¸ô³q°T¨ó©w¬°<p> |
-u | ²¾°£<VBRFile>ªº¦w¸Ë |
-l | ±N¿ù»~°T®§°O¿ý¦Ü"clireg.log"Àɤ¤ |
-q | ¦wÀR¼Ò¦¡¡G¤£¥X²{¹ï¸Ü¤è¶ô |
-nologo | ¤£Åã¥Üª©¥»¸ê°T |
-h or -? | Åã¥Ü¥»°T®§ |
ªí16-3 CliReg32 ¤u¨ãªº¿ï¶µ¡C |
³]©wDCOM
¡@
DCOMCNFG¬O³]©wDCOM¥Dnªº¤u¨ã¡C·í±z²Ä¤@¦¸°õ¦æ³oÓ¤u¨ã¡A¥¦§Ö³t±½´y¨t²Î¤¤¤w¸gµn¿ýªº¤¸¥ó¨Ã¥B±N¥¦ÌªºÃѧO½X¥[¤Jµn¿ý¸ê®Æ®w¤¤ªºHKEY_CLASSES_ROOT\AppID¡A·Ç³Æ±N³o¨Ç¤¸¥ó¨Ñµ¹»·ºÝ°õ¦æ¡Cµn¿ý¸ê®Æ®w¤¤ªº³oÓ¦ì¸m¶°¦X¤F©Ò¦³¤¸¥óªº¦w¥þ©Êªº¸ê°T¡CÁöµM¦³¤Ö¼Æªº¤¸¥ó¦Û¦æµù¥U³o¨Ç¾÷½X¡A¦ý³o¤£·|µo¥Í¦bVisual Basic©Ò½s¼gªº¤¸¥ó¤W¡Cª`·NDCOMCNFG¹ï©ó¨C¤@ÓActiveX¦øªA¾¹Åã¥Ü¤@ÓAppID¡A¬Æ¦Ü©ó¦øªA¾¹´£¨Ñ¦hÓÃþ§O¡C
DCOMCNFG±Ò°Ê¥H¤Î¤£±Ò°ÊDCOM¬O¥H¤@¾ãÓ¾ãÅé¨Ó¬Ý¡C¦b ¹w³]ÄÝ©Ê ¶ÅÒ¤W¡A¦p¤U¤@¶ªº¹Ï16-26¡A±zÀ³¸ÓÂI¨ú ¦b³o¥x¹q¸£¤W°_¥ÎDCOM ¡C¦¹¿ï¶µ¥²¶·³Q¿ï¾Ü¥H¾Ö¦³¥¿½Tªº¹q¸£¤u§@¡A¦bDCOM³sµ²¤¤§@¬°¦øªA¾¹©Î¬O«È¤áºÝ¡C
±z¥²¶·«·s¶}¾÷¥H¨Ï³]©w§¹¦¨¡C
¹w³]»{ÃÒµ¥¯Å¥H¤Î¼ÒÀÀµ¥¯Å
¡@
DCOMCNFGÅý±z³]©wDCOM¹w³]¦w¥þ©Ê¥H¤Î¹ï©ó¨CÓ¯S©w¤¸¥óªº¦w¥þ©Ê¡C³oºØ¦w¥þ©ÊªººØÃþºÙ¬°declarative security¡A¨Ã¥B¥i¥H±q¤¸¥ó¥~³¡°µ³]©w¡CDCOM ¤]¤ä´©programmatic security¡AÅýµ{¦¡³]p¤Hû¥i¥H¦b¤¸¥ó°õ¦æ®É°ÊºA§ó§ï¤¸¥óªº¦w¥þ©Ê¡A¬Æ¦Ü¹ï©ó¨CÓ°ò¦ªº¤èªk³]©w¤£¦Pªº¦w¥þµ¥¯Å¡C¤£©¯¦a¡Ap¹º©Êªº¦w¥þ©Ê¦bVisual Basicªº¯à¤O¤§¥~¡C
¡@
¹Ï16-26 DCOMCNFG ¤u¨ãªº¡u¹w³]ÄÝ©Ê¡v¶ÅÒ¡C |
¹w³]»{ÃÒ µ¥¯Å¿ï¶µ§i¶DDCOMÀ³¦p¦óÀˬd¹ê»Ú¤W¨Ó¦Û«È¤áºÝªº¸ê®Æ¡C¸û°ªªº»{ÃÒµ¥¯Å«OÅ@¦øªA¾¹§K©ó¸ê®Æ«§ï¡A¦ý¦P®É°§C¤F¹ï«È¤áºÝªº³q°T¡CDCOM©Ò¤ä´©ªº»{ÃÒµ¥¯Å¦C©óªí16-4¡G
È | µ¥¯Å | ´yz |
---|---|---|
0 | ¹w³] | ¹ïÀ³³sµ²»{ÃÒ |
1 | µL | DCOM¤£¥H¥ô¦ó¤è¦¡»{ÃÒ¸ê®Æ |
2 | ³sµ² | DCOM¥u¦b²Ä¤@¦¸³sµ²¨ì«È¤áºÝ®É»{ÃҫȤáºÝ |
3 | ©I¥s | DCOM ¦b¨C¤@Ó©I¥s¤èªk¥H¤ÎÄݩʪº¶}©l»{ÃҫȤáºÝ |
4 | «Ê¥] | DCOM»{ÃÒ¨C¤@ӨӦ۫ȤáºÝªº¸ê®Æ«Ê¥] |
5 | «Ê¥]§¹¾ã©Ê | ¸ò«e¤@µ¥¯Å¬Û¦P¡A¦ý¬OÀˬdªº§Þ¥©½T«O¸ê®Æ¦b¶Ç¿é¤¤¨S¦³§ó°Ê¡C |
6 | «Ê¥]¥[±K | ¸ò«e¤@µ¥¯Å¬Û¦P¡A¦ý¬O¸ê®Æ¥[±K¥H½T«O¤£·|³Q¨ýºë»{ÃÒªºµ{¦¡©Ò¨Ï¥Î¡C |
ªí16-4 DCOM»{ÃÒµ¥¯Å¡C |
¼ÒÀÀµ¥¯Å©w¸q¤F¦b«È¤áºÝ¤¸¥ó©Ò¯à°µªº°Ê§@¡C¸û§Cªº¼ÒÀÀµ¥¯Å¡A«È¤áºÝ¹ï©ó¦æ¬°¤£ºÝªº¤¸¥ó¦³¸û¦hªº«OÅ@¡C¹w³]ªº¼ÒÀÀµ¥¯ÅÄæ¦ì¡A¬O´ú©w¤À¬£µ¹©Ò¦³¤¸¥óªº¼ÒÀÀµ¥¯Å¡A¤£n¥H¤£¦PªºÈÂл\³oÓ³]©w¡CDCOM´£¨Ñ¥|ºØ¼ÒÀÀµ¥¯Å¡A¦C©óªí16-5¡C
È | µ¥¯Å | ´yz |
---|---|---|
1 | °Î¦W | ¦øªA¾¹¤£ª¾¹D¥ô¦óªº«È¤áºÝ¡A¦]¦¹¤£¯à¼ÒÀÀ¡]³oÓµ¥¯Å¤£¬O¥¿½Tªº¤ä´©¡A¹w³]Ȭ°ÃѧO¡^ |
2 | ÃѧO | ¦øªA¾¹¦³¨¬°÷ªº¸ê°T¦bACL¤¤¼ÒÀÀ¡A¥i¥HÀˬd¦ý¬O¤£¯à¦p¦P«È¤áºÝ¤@¯ë¦s¨ú¨t²Îª«¥ó¡C |
3 | ¼ÒÀÀ | ¦øªA¾¹¥i¥H¼ÒÀÀ«È¤áºÝªº¦æ¬° . |
4 | ¥N²z | ¦øªA¾¹¥i¥H¼ÒÀÀ«È¤áºÝ©I¥s¨ä¥Lªº¦øªA¾¹(¥u¦³Windows 2000.¤ä´©) |
ªí16-5 DCOM¼ÒÀÀµ¥¯Å¡C¹w³]¬°ÃѧO¡C |
¦s¨ú»P±Ò°ÊÅvªº¹w³]È
¡@
¦b ¹w³]¦w¥þ©Ê ¶ÅÒ¡A±z¿ï¾Ü¦Cªí¤¤ªº¨Ï¥ÎªÌ¨Ï¨ä¥i¥H°õ¦æ©Î¬O¨Ï¥Î©Ò¦³ªº¤£´£¨Ñµ¹»{ÃҨϥΪ̦Cªíªº¤¸¥ó¡Cn¨Ï¥Î¤@Ó¤¸¥ó¡A¤@ӨϥΪ̥²¶·¥]§t¦b¡u¦s¨úÅv¡v¦Cªí¤¤¡An±Ò°Ê¤@Ó¤¸¥ó¡A¨Ï¥ÎªÌ¥²¶·¥]§t¦b ±Ò°ÊÅv ¦Cªí¤¤¡C¨âªÌ³£¬OWindows NT ¦s¨ú±±¨î¦Cªí¡A¦p¹Ï16-27¡C±z¤£À³¸Ó§ó§ï³o¨Ç¦Cªí¡F±zÀ³¸Ó§ó§ïÓ§OªºÃö©ó¨CÓ¤¸¥óªºACLs¡A¦p¦Pµ§ªÌ¤§«e©Ò¸ÑÄÀªº¡C«nªº¬O SYSTEMn¥]§t¦b¦s¨ú¥H¤Î±Ò°Êªº¦Cªí¤¤¡A§_«h¡A¤¸¥ó¤£¯à±Ò°Ê¡C
¹w³]³]©wÅv ¦Cªí¥]§t©Ò¦³¤¹³\§ó§ï©Ò¦³¤£´£¨Ñµ¹»{ÃҨϥΪ̦Cªíªº¤¸¥óªº¦w¥þ³]©w¡C±z¤£À³¸Ó§ó§ï³o¨Ç³]©wÈ¡A¦]¬°¨î¦s¨úµn¿ý¸ê®Æ®w¥i¯à¤Þµo¥HVisual Basic©Ò¼gªº¤¸¥óªº°ÝÃD¡A´N¬O¦b¨C¦¸±Ò°Ê®Éµù¥U¥¦Ì¦Û¤v¡C
¡@
¹Ï16-27 DCOMCNFG¤u¨ãªº¡u¹w³]È¡v¶ÅÒ¡C |
¨¤À³]©w
¡@
¦pªG±zÂà´«¨ìDCOMCNFG¤u¨ãªº À³¥Îµ{¦¡ ¶ÅҨåB¦b¤@Ó¤¸¥óªº¦WºÙ¤W«ö¨â¤U¡A¥t¤@Óµøµ¡·|¥X²{¡F³oÓµøµ¡´N¬O±z§ó§ï¯S©w¤¸¥óªº¦w¥þ³]©w¥H¤Î¨ä¥LÄݩʪº¦a¤è¡CÁ|¨Ò¨Ó»¡¡A¦b ¤@¯ë ¶ÅÒ¤¤¡A±z¥i¥H¹ï©ó¦¹¤¸¥ó³]©w¤@Ó¦w¥þµ¥¯Å¡A±z¥i¥H§¹¥þ¦a©w¸qþ¨Ç¨Ï¥ÎªÌ¥i¥H¦s¨ú¥H¤Î±Ò°Ê¦¹¤¸¥ó¥H¤Î¥i¥H§ó§ï³]©wÅv¡C
³Ì¦³½ìªº¬O³]©w¬O ¨¤ÀÅçÃÒ ¶ÅÒ¡A¦p¹Ï16-28¡C
¡@
¹Ï16-28 DCOMCNFG¤u¨ãªº¡uÃѧO½X¡v¶ÅÒ¡C |
³o¸Ì±z¨M©w¦b¦óºØ¨Ï¥ÎªÌ±b¸¹¤U¤¸¥ó±N·|°õ¦æ¡CDCOM´£¨Ñ¤U¦C¤TºØ¿ï¾Ü¡G
¤¬°Êªº¨Ï¥ÎªÌ ³oӿﶵ¤À°t¤¸¥óªº¨Ï¥ÎªÌªº¦w¥þ©Ê¾ÌÃÒ¬O¥Ø«eµn¤J¹q¸£¨Ï¥ÎªÌ¡C¹ê»Ú¤W³o¤£¬O¤@Ó¦nªº¿ï¾Ü¡A¦]¬°Åv¦P·N¤¸¥ó¨Ì¾Úµn¿ý¨Ï¥ÎªÌªº¤£¦P¦Ó§ïÅÜ¡C¦pªG¨S¦³¨Ï¥ÎªÌµn¤J¡A¤¸¥ó¬Æ¦Ü¤£¥i¥H°õ¦æ¡C¹ê»Ú¤W¡A¦¹¿ï¶µ¥u¦³±z¥¿¦b´ú¸Õ¤¸¥ó®É¦³·N¸q¡C
©Ò¦³ªº¤¸¥ó°õ¦æªº±b¸¹¤£¦P©ó°õ¦æ¦b¤@Ónoninteractive window stationªº¤¬°Ê¦¡¨Ï¥ÎªÌªº±b¸¹¡A¨Ã¥B¦b®à¤W«¬¹q¸£¤W¬Ý¤£¨ì¡C¦pªG±z·Qn¨£¨ì¤¸¥óªº¿é¥X¡A¥²¶·°õ¦æ¦b ¤¬°Êªº¨Ï¥ÎªÌ ªº ¨¤ÀÅçÃÒ ¤§¤U¡C¬°¤F¬Û¦Pªºì¦]¡A°£«D±z¦Ê«D¤§¦Êªº½T©w±zªº¤¸¥ó·|°õ¦æ¦b¤¬°Êªº¨Ï¥ÎªÌ±b¸¹¤§¤U¡A±zÀ³¸Ó¨Ï¥Î °õ¦æ®ÉµL¨Ï¥ÎªÌ¤¶± ¿ï¶µ¶i¦æ½sĶ¡C¦pªG±z¨S¦³³o»ò°µ¨Ã²£¥Í¤@Ó¿ù»~¡A¨º»ò¤¸¥ó±N¥Ã»·ªºµ¥«Ý¦]¬°¨S¦³¨Ï¥ÎªÌ¥i¥HÂI¨ú¿ù»~°T®§¤è¶ô¡C
±Ò°Êªº¨Ï¥ÎªÌ ³oӿﶵ¤À°t¤¸¥óªº¨Ï¥ÎªÌªº¦w¥þ©Ê¾ÌÃÒ¬O¥¿¦b°õ¦æ«È¤áºÝªºÀ³¥Îµ{¦¡ªº¨Ï¥ÎªÌ¡C³oӿﶵ³q±`¤]¤£¬O¤@Ó¦nªº¿ï¾Ü¡A¦]¬°¤£¦Pªº«È¤áºÝ«Ø¥ßªº»·ºÝª«¥óªº°õ¦æÓÅ饲¶·°õ¦æ¦b¤£¦Pªº¾ÌÃÒ¤§¤U¡A©Ò¥H¤£¥i¯à¥u°õ¦æ¦P¤@¤¸¥óªº¦hÓ°õ¦æÓÅé¡C¦b³oºØ±¡§Î¤¤¡A¤¸¥óªºªí²{¦h¤Ö¹³¬O¤@ÓSingleUse¤¸¥ó¡A¬Æ¦Ü¤¸¥ó¨Æ½sĶ¦¨MultiUse¡C¨Ã¥B¡A¦pªG¤@Ó¤¸¥ó°õ¦æ¦b¤@Ó»·ºÝ«È¤áºÝªº±b¸¹¤U¡A¤¸¥ó±N¤£¯à©I¥s¨ä¥L¹q¸£¤Wªº¤¸¥ó¡A¦Ü¤Ö¦bWindows NT 4 (¤£¤ä´©¥N²z¼ÒÀÀµ¥¯Å)¡C
«ü©wªº¨Ï¥ÎªÌ ³oӿﶵ¤À°t¤¸¥óªº¨Ï¥ÎªÌªº¦w¥þ©Ê¾ÌÃÒ¬O¤¸¥óªº¡C¦b²£«~ªºÀô¹Ò¤¤¡A³o±`±`¬O³Ì¨Îªº¿ï¾Ü¦]¬°¥u¦³¤@ÓMultiUse¤¸¥óªº°õ¦æÓÅé·|³Q«Ø¥ß¡C¹ê»Ú¤W¡A³Ì¦n´N¬O¬°¦¹¥Øªº«Ø¥ß¤@Ó·sªº¨Ï¥ÎªÌ¡Aµ¹¤©¨ä¾A·íªº¨t²Î¦s¨úÅv¡AµM«áÅý¤¸¥ó»P·sªº¨Ï¥ÎªÌ¾ÌÃÒ¤@°_°õ¦æ¡C¨Ï¥Î³oºØ¤èªk¡A±z¥i¥H§Q¥Î³oÓµêÀÀªº¨Ï¥ÎªÌ§ó§ï¦hÓ¤¸¥óªº¦s¨úÅv¡C
«nªº¬O³oӨϥΪ̥i¥H¦p§å¦¸Àɪº¤è¦¡³Q¤À°tµn¤JªºÅv¡A¥t¥~·í¤¸¥ó±Ò°Ê±N¥¢±Ñ®É¡Aµn¤Jµ{§Ç±N¤£ª¾¤£Ä±ªº±Ò°Ê¡C¦b«ü©wªº¨Ï¥ÎªÌÄæ¦ì¡ADCOMCNFG·|¦Û°Ê¤À°t³oºØÅv½uµ¹¤©¨Ï¥ÎªÌ¡A±z©Òn°µªº¨Æ¤£n·N¥~¦a±qWindows NT¨Ï¥ÎªÌºÞ²z¤u¨ãºM¾P³oºØÅv¤O¡C
¹ê§@¤@Ó¦^©Iªº§Þ¥©
¡@
±z¥i¥H¤j¤jªº¼W¶i±z»·ºÝ¤¸¥óªº®Ä²v´N¬O¨Æ¥ó³qª¾¡CÁöµM±z®t«lªº¦bDCOM¤U¤u§@(¦ý¬O¨S¦³¦bRemote Automation)¡A¥¦Ì¬O¦h»òªº¨S¦³®Ä²v¦]¦¹µ§ªÌ±j¯P«Øij±z¤£n¨Ï¥Î¡C¨ú¦Ó¥N¤§ªº¡A±zÀ³¸Ó®É°µ¤@Ó¦^©Iªº§Þ¥©¡C
¦^©Iªº§Þ¥©¤u§@¤è¦¡¦p¤U¡G·í«È¤áºÝ©I¥s¤@Ó¤¾ªøªºª«¥ó¤èªk¡A¦P®É¶Ç»¼¤@Ó©w¸q¦b«È¤áºÝªºª«¥óªº¤Þ¥Î¡A¤¸¥ó±N¦¹¤Þ¥ÎÀx¦s¦b°Ï°ìÅܼƤ¤¡Cª«¥óªº¤Þ¥Î¬O¨Ï¥Î¦b·í¦³¨Ç¨Æ±¡µo¥Í¡A¦Ó¤¸¥ón¦^©I«È¤áºÝªº®ÉÔ¡C
¦´Á³sµ²»P±ß´Á³sµ²ªº¦^©I
¡@
¦^©I§Þ¥©¦bVisual Basic 4ªº®ÉÔ´N¥i¥H¨Ï¥Î¡A¦ý¬O¦bVisual Basic 4¤¤¥u¦³±ß´Á³sµ²ªº¦^©I¥i¥H¨Ï¥Î¡AÅý§ÚÌ´yz¤@Ó¦^©Iªº½d¨Ò¡A°²³]±z¤w¸g«Ø¥ß¦n¤@Ó¤@¯ëªº«½Æ¨Ï¥Îªº³ø§i¦C¦L¤ÞÀº¡G¥ô¦óªº«È¤áºÝ³£¥i¥H«Ø¥ß¹êÅé¨Ã¥B±Ò°Ê¤@Ó¦C¦L¤u§@¡C·í¦C¦L§¹¦¨©Î¬O¦³¿ù»~µo¥Í¡A¦øªA¾¹´N¦^©I«È¤áºÝ¡C
¦b³oºØ±¡¸`¤¤¡A¦C¦L¦øªA¾¹¦b½sĶ®É¤£ª¾¹D«È¤áºÝ©Ò¶Ç»¼¹L¨Óªºª«¥óÃþ«¬¡C¤¸¥ó¥u¯à¥Î As Object Àx¦sª«¥óªº¤Þ¥Î¡Aªí¥Ü³o¬O³qª¾¬O³z¹L±ß´Á³sµ²¨Ó§¹¦¨¡C«È¤áºÝ¥H¤Î¤¸¥ó¥²¶·¦P·N¦bÃþ§O¤¤¥Î©ó¦^©Iªº¤èªkªº¦WºÙ¥H¤Î¤åªk¡C¥ô¦ó«È¤áºÝ©Î¬O¦øªA¾¹¤W©Òµo¥Íªº¤åªk¿ù»~¥u¯à¦b°õ¦æ®É¤~µo²{¡C¦p¦P±z©Òª¾ªº¡A±ß´Á³sµ²¸û¦´Á³sµ²¨S¦³®Ä²v¡A©Ò¥H¦pªG¦bVisual Basic 5¥H¤Î6¤¤±zÀ³¸ÓÁקK¡AImplements ÃöÁä¦r¤¹³\±z¹ê¦æ¤@Ó¦b«È¤áºÝ¥H¤Î¦øªA¾¹ÄY®æªº¨î¡C¤¸¥ó¥]§t¤@ÓPublicNot-CreatableÃþ§O¡A©w¸q¦^©Iªº¤¶±¡C¨Ã¥B¥ô¦ón±µ¦¬¦øªA¾¹ªº¦^©I³qª¾ªº«È¤áºÝ»Ýn´£¨Ñ¤@Ó¹ê§@¤¶±ªºPublicNotCreatableÃþ§O¡C¦]¦¹¤¸¥ó¥i¥HÀx¦s¤Þ¥Î¦b³o¼ËªºÅܼƤ¤¡A¥i¥H¨Ï¥Î¦´Á³sµ²¡C
½d¨Ò
¡@
¦bÀH®Ñ¥úºÐ¤¤¡A±z¥i¥H§ä¨ì¹ê§@¤@Ó¦^©I¤¶±»P¨ä¥L«È¤áºÝ·¾³qªº¦h°õ¦æºü¤¸¥óªº§¹¾ãµ{¦¡½X¡C³oÓ¤¸¥ó§¹¦¨¤@Ó(¼ÒÀÀ) ¦C¦L¤u§@¨Ã¥B§i¶D«È¤áºÝ¤u§@§¹¦¨ªº¶i«×¡C¤¸¥ó¥]§t©w¸q¦b¤¶±¤¤ªºCPrinterCBK PublicNotCreatableÃþ§O¡C
'The CPrinterCBK class module. Sub Complete(ErrCode As Long) ' End Sub Sub Progress(percent As Integer) ' End Sub
©³¤U¬OCprinterÃþ§Oªºì©l½X, ¥¦·|¼ÒÀÀ¹ê»Ú¤Wªº¦C¦L¡G
'The CPrinter class module. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Dim SaveCBK As CPrinterCBK Dim frmTimer As frmTimer Sub StartPrintJob(Filename As String, cbk As CPrinterCBK) 'Save the callback object for later. Set SaveCBK = cbk 'Activate the timer that will restart this thread. Set frmTimer = New frmTimer With frmTimer Set .Owner = Me .Timer1.Interval = 100 .Timer1.Enabled = True End With End Sub Friend Sub StartIt() Dim totalTime As Single, percent As Integer Dim t As Single, startTime As Single 'This code is executed when the timer fires. 'Unload the form, and destroy it completely. Unload frmTimer Set frmTimer = Nothing 'Simulate the printing process. totalTime = Rnd * 10 + 5 startTime = Timer Do 'Inform the client that something has happened. percent = ((Timer - startTime) / totalTime) * 100 SaveCBK.Progress percent ' In this demo, just go to sleep for one second. Sleep 1000 Loop Until Timer - startTime > totalTime ' Inform the client that the process has been completed. SaveCBK.Complete 0 ' IMPORTANT: destroy the reference to the client ' so that it won't be kept alive forever. Set SaveCBK = Nothing End Sub
¤¸¥ó¤]¥]§t¤@Ó§t¦³®É¶¡±±¨î¶µªºªí³æ¡A³oÓªí³æªº°ß¤@¥Øªº¬O¦b¤¸¥ó±qStartPrintJob ¤èªk¶Ç¦^±±¨îÅvµ¹«È¤áºÝ®É¡A¥s¿ô¤¸¥ó¼Æ·L¬í¡C
'The frmTimer form module. Public Owner As CPrinter Private Sub Timer1_Timer() ' This procedure is executed only once. Timer1.Interval = 0 Timer1.Enabled = False ' Yield to the companion CPrinter instance. Owner.StartIt End Sub
¦bÀH®Ñ¥úºÐ¤¤¡A±z¤]¥i¥H§ä¨ì¤@ӨϥγoÓ¤¸¥ó¨Ã¥B¦bµ¥«Ý¼ÒÀÀªº¦C¦L¤u§@§¹¦¨®É§¹¦¨¤@ÓCPU±K¶°ªº¤u§@¡]§ä´M½è¼Æ¡^ªº«È¤áºÝÀ³¥Îµ{¦¡¡C¦pªG±z¨S¦³ºô¸ô¹q¸£¡A±z¥i¥H°õ¦æ¦hÓ¦¹À³¥Îµ{¦¡ªº°õ¦æÓÅé¡AµM«á¨£¨ì¥¦Ì¥i¥H¤£¤¬¬Û¼v·Q¤zÂZªº¦h¤u°õ¦æ¡A¦p¹Ï16-29¡C
¡@
¹Ï16-29 ¦h««È¤áºÝ³z¹L¦^©I»P½d¨Ò¤¤ªº¤¸¥ó·¾³q¡C |
³oӫȤáºÝÀ³¥Îµ{¦¡¥]§t¤@ÓPublicNotCreatable ¦^©IÃþ§O¼Ò²Õ¡A¥¦·|¶Ç¦^¨ì¦øªA¾¹¤¸¥ó¡G
' The CallbackCls class module. Implements PrintServer.CPrinterCBK ' This class directly references controls on the main form. Private Sub CPrinterCBK_Complete(ErrCode As Long) frmClient.lblStatus = "Completed" frmClient.cmdStart.Enabled = True End Sub Private Sub CPrinterCBK_Progress(percent As Integer) frmClient.lblStatus = "Printing"& percent & "%" End Sub
¦b«È¤áºÝÀ³¥Îµ{¦¡¥Dªí³æ°ß¤@ªº³¡¤À¡A«ü¥X²£¥Í¤¸¥óÓÅé¨Ã¶Ç°e¥¦ªº¤Þ¥Î¨ìCallbackClsª«¥ó¤¤¡G
Private Sub cmdStart_Click() Dim prn As PrintServer.CPrinter ' Ask the CPrinter server to spool a fictitious file. Set prn = New PrintServer.CPrinter prn.StartPrintJob "a dummy filename", New CallbackCls End Sub
½Ðª`·N¨ì«È¤áºÝ¤£»ÝnÀx¦sCallbackClsª«¥óªº¤Þ¥Î¦b¤@Ó°Ï°ìÅܼƤ¤¡A¦]¬°³oÓÅܼƦøªA¾¹·|«O«ù¨ä¦s¬¡¡C¶i¤@¨B¦a¡ACallbackClsÃþ§O¼Ò²Õ¥i¥H±q¦h«¦øªA¾¹¹ê§@¤@Ó¦^©I§Þ¥©¤U¤u§@¡A¨CÓ©w¸q¥»¨ªº¤¶±¡C¦b³oÓ¨Ò¤l¤¤¡AÃþ§O»Ýn¥]§t¦h«ªº Implements ±Ôz¡A¨CӤ䴩¤@Ó¦^©I¤¶±¡C
¤ñ¸û¦^©I»P¨Æ¥ó
¡@
¦^©I§Þ¥©¨Ã¨S¦³¤ñ¨Æ¥ó³qª¾½ÆÂø¦h¤Ö¡C¥u¦³¤@¥ó¨Æ¡A«È¤áºÝ¥²¶·¬O¤@Ó¥»¨´£¨Ñ¤@ÓpublicCOMª«¥óªºActiveX EXE ¡A¨Ã¥B¤¸¥ó¥²¶·¦³¨¬°÷ªºÅv§Q©I¥s³oÓCOMª«¥ó¤¤ªº¤èªk¡C´«¥y¸Ü»¡¡A¦^©I¦³³\¦h¤ñ¨Æ¥ó¦nªº¯S¦â¡G
ª`·N³o¸Ì©Ò»¡ªº¦^©I§Þ¥©¨Ã¤£©ó¥Î¦b»·ºÝ¤¸¥ó¡A¤]¥i¥H¦³®Äªº¨Ï¥Î¦b¥»¾÷¤¸¥ó¤W¡C
²{¦b±z¤F¸Ñ«Ø¥ß¤@Ó¦nªº¦P³B²zºü¡B¥»¾÷¥H¤Î»·ºÝ¤¸¥óªº©Ò¦³¨Æ±¡¡C¦ý¬OVisual Basic 6¤]Åý±z«Ø¥ß¨ä¥LÃþ«¬ªº¤¸¥ó¡AºÙ°µActiveX controls¡C¥¦Ì¥]§t¦b¤U¤@³¹¡C