»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > VBÎĵµ > APIº¯Êý
ÇÉÓÃAPIº¯ÊýÔöÇ¿VBλ²Ù×÷¹¦ÄÜ
·¢±íÈÕÆÚ£º2005-09-15 16:15:13×÷ÕߣºÁ ³ö´¦£º  

ÕªÒª£ºVisual Basic µÄλ²Ù×÷¹¦ÄܽÏÈõ£¬ÉõÖÁÁ¬×î³£ÓõÄÒÆλÔËË㶼²»Ö§³Ö£¬Òò´ËÔÚʹÓã֣¿ª·¢ÖîÈçÊý¾Ý¼ÓÃÜ¡¢Ñ¹Ëõ¡¢Í¨ÐÅÖ®ÀàµÄ³ÌÐòʱÍùÍùÀ§ÄÑÖØÖØ¡£Õë¶ÔÕâÒ»ÎÊÌ⣬±¾ÎÄÏêϸµØ²ûÊÍÁËλ²Ù×÷µÄ±¾ÖÊ£¬²¢ÀûÓãףé£î32 £Á£Ð£Éº¯ÊýʵÏÖÁËÕûÐͱäÁ¿µÄ²ð·Ö¡¢ºÏ²¢¡¢ÒÆλµÈ£Ö£Â²»Ö§³ÖµÄλ²Ù×÷¹¦ÄÜ¡£

¹Ø¼ü´Ê£ºVisual Basic¡¢Î»²Ù×÷¡¢ÒÆλ

Ò» ÒýÑÔ

¡¡¡¡±ÊÕßÔÚ±à³Ìʵ¼ùÖз¢ÏÖ£¬£Ö£Â¶Ôλ²Ù×÷µÄÖ§³Ö½öÏÞÓÚAND¡¢OR¡¢XOR¼¸ÖÖλÔËË㣬ԶԶ²»ÈçÆäËûµÄ¿ª·¢¹¤¾ßÄÇÑùÈ«Ã棨ÈçVisual C++¡¢C++Builder¡¢DelphiµÈ¿ª·¢¹¤¾ß¶¼ÌṩÁËÕûÐαäÁ¿µÄÒÆλ¡¢²ð·Ö¡¢ºÏ²¢µÄÔËË㣩£¬Òò´ËÔÚʹÓã֣±àдÖîÈç¼ÓÃÜÖ®ÀàµÄͨÓÃÊý¾Ý´¦Àí³ÌÐòʱÍùÍùÀ§ÄÑÖØÖØ¡£ÎªÁËʹÒÔºóµÄ¿ª·¢¹¤×÷²»ÔÙÏÝÈ뽩¾Ö£¬ÎÒ¿ªÊ¼Ñ°ÇóÔöÇ¿VBλ²Ù×÷¹¦ÄܵÄͨÓ÷½·¨£¬ÒÔ´ïµ½Ò»ÀÍÓÀÒݵÄЧ¹û¡£

¡¡¡¡£Ö£ÂµÄÊý¾ÝÀàÐͲ»¹»·á¸»£¬ÕûÐÎÊýÖ»°üÀ¨Byte¡¢Integer¡¢LongÈýÖÖÀàÐÍ£¬·Ö±ð¶ÔÓ¦C++ÖÐµÄ unsigned char¡¢short ºÍ long ÀàÐÍ£¬¶øÎÒÃdz£ÓõĶþ×Ö½ÚÎÞ·ûºÅÕûÐÎunsigned short(Ò²½Ð¡°×Ö¡±¡¢Word)¡¢ËÄ×Ö½ÚÎÞ·ûºÅÕûÐÎunsigned long(Ò²½Ð¡°Ë«×Ö¡±¡¢DWord)ÔÚVBÖÐȴûÓб»Ö§³Ö¡£ µ«ºÃÔÚÎÞ·ûºÅÊýºÍÓзûºÅÊýÔÚ¶þ½øÖƵIJã´ÎÉÏûÓÐÈκβî±ð£¬²»Í¬Ö®´¦½öÔÚÓÚ±àÒëÆ÷¶Ô±äÁ¿µÄÀí½â¡£ÔÚ½øÐÐλ²Ù×÷ʱÎÒÃÇÖ»¹ØÐıäÁ¿µÄ¶þ½øÖÆ룬Òò´Ë£Ö£ÂÖеÄIntegerÀàÐÍ¿ÉÒÔµ±×÷WordÀàÐÍʹÓã¬LongÀàÐÍÔò¶ÔÓ¦DWord¡££¨´ËºóÎÄÖÐÌá¼°µÄIntegerÀàÐ;ùÖ¸VB IntegerÀàÐÍ£¬LongÀàÐ;ùÖ¸VB LongÀàÐÍ£¬Word ¡¢DWordÀàÐÍÔòÊDz»ÒÀÀµÓÚÌض¨±àÒëÆ÷µÄ¶Ô¶þ×Ö½Ú¡¢ËÄ×Ö½ÚÕûÐÎÖµµÄͨÓóƺô£©ÔÙÀ´¿´Î»ÔËËã·½Ã棬¿ÉÒÔ¿´³öVB²»Ö§³ÖÕûÐͱäÁ¿µÄ×óÒÆ¡¢ÓÒÒÆ¡¢²ð·Ö¡¢ºÏ²¢µÈ²Ù×÷¡£

¡¡¡¡¾­¹ýÉÏÊöµÄ·ÖÎöÖ®ºó£¬ÒѾ­È·¶¨Á˹¤×÷µÄ¿ÉÐÐÐԺ͹¤×÷Ä¿±ê£¬ÓÚÊDZÊÕß¾ö¶¨¿ª·¢Ò»¸öͨÓÃÄ£¿éÀ´ÔöÇ¿VBµÄλ²Ù×÷¹¦ÄÜ£¬Õâ¸öÄ£¿éÊÇ¿ÉÖØÓõģ¬Ö»Òª°ÑÕâ¸öÄ£¿é¼ÓÈ빤³ÌÖУ¬¾Í¿ÉÒÔÏóʹÓÃVBµÄÄÚÖú¯ÊýÒ»Ñù͸Ã÷µÄʹÓÃÄ£¿éÖеĺ¯Êý£¬·Ç³£·½±ã¡£Èç¹ûʹÓôóÁ¿µÄ¿ÉÖØÓÃÄ£¿éÀ´¿ª·¢³ÌÐò£¬Ôò¿ª·¢ÖÜÆڶ̣¬´úÂë¿É¶ÁÐԺã¬Ò×ÓÚά»¤£¬²»ÈÝÒ׳ö´í¡£

¶þÉè¼Æ˼·

1. ʵÏÖÕûÐαäÁ¿µÄ²ð·Ö¡¢ºÏ²¢

¡¡¡¡ÕûÐͱäÁ¿µÄ²ð·Ö¡¢ºÏ²¢ÊǾ­³£ÒªÓõ½µÄ²Ù×÷£¬±ÈÈçIPµØÖ·¾ÍÊÇÒ»¸öËÄ×Ö½ÚµÄË«×Ö£¬ÓÐʱºòΪÁËÒÔµã·ÖÊ®½øÖƵķ½Ê½ÏÔʾIPµØÖ·£¬¾ÍÐèÒªµ¥¶ÀÈ¡³öÿ¸ö×Ö½ÚµÄÖµ£¬¶øÓÐʱºòΪÁ˰ѵã·ÖÊ®½øÖƵÄIPµØַת»»Îª¼ÆËã»úÄÚ²¿µÄË«×Ö£¬ÓÖÐèÒª°ÑËĸö×Ö½Ú×éºÏ³ÉÒ»¸öË«×Ö¡£VBûÓÐÌṩÕâÑùµÄ¹¦ÄÜ£¬ËùÒÔÕûÐͱäÁ¿µÄ²ð·Ö¡¢ºÏ²¢Ò²ÊÇÎÒÃÇÕâ´ÎҪʵÏֵŦÄÜ¡£ÁíÍâÕûÐͱäÁ¿µÄ²ð·Ö¡¢ºÏ²¢Ò²ÊÇʵÏÖInteger¡¢LongÀàÐͱäÁ¿ÒÆλµÄÇ°ÌáÌõ¼þ(ºóÃæ¡°·Ö¶øÖÎÖ®²ßÂÔ¡±½«»áÌáµ½)£¬Ö»ÒªÊµÏÖÁËÕûÐͱäÁ¿µÄ²ð·ÖºÏ²¢£¬ÒÆλÎÊÌâ¾ÍÍêÈ«½â¾öÁË¡£

·½·¨1£ºÀûÓÃAPIº¯ÊýCopymemoryʵÏÖ

¡¡¡¡ÔÚÕâÀï±ÊÕßÀûÓÃWin32 API º¯ÊýCopyMemoryʵÏÖÁËÕûÐαäÁ¿µÄ²ð·Ö¡¢ºÏ²¢²Ù×÷¡£ÔÚVBÖÐʹÓÃAPIº¯Êý±ØÐëÒªÉùÃ÷£¬CopyMemoryº¯ÊýµÄÉùÃ÷´úÂëÈçÏ£º


Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _

(Destination As Any£¬ Source As Any£¬ ByVal Length As Long)

¡¡¡¡ÆäÖеIJÎÊýDestinationÊÇÄ¿±êÄÚ´æµÄµÚÒ»¸ö×Ö½ÚµØÖ·£¬²ÎÊýSourceÊDZ»¸´ÖÆÄÚ´æµÄµÚÒ»¸ö×Ö½ÚµØÖ·£¬²ÎÊýLengthÊÇÐèÒª¸´ÖƵÄ×Ö½ÚÊý¡£

¡¡¡¡ÊµÏÖÔ­ÀíºÜ¼òµ¥£ºÒªÊµÏÖ²ð·Ö£¬¾ÍÓÃCopyMemoryº¯Êý°ÑÒ»¸öÕûÐαäÁ¿µÄÒ»²¿·Ö¿½±´µ½ÁíÒ»¸ö¸üСµÄÕûÐαäÁ¿µÄµØÖ·¿Õ¼äÖУ»¶øʵÏֺϲ¢£¬ÔòÀûÓÃCopyMemoryº¯Êý°ÑÁ½¸ö´ýºÏ²¢µÄС±äÁ¿¿½±´µ½ÁíÒ»¸ö´óÕûÐαäÁ¿µÄµØÖ·¿Õ¼äÖС£¼ûʾÀý´úÂ룺
Public Function Hi(ByVal Word As Integer) As Byte

'È¡Ò»¸ö×Ö£¨Word£©µÄ¸ß×Ö½Ú£¨Byte£©

'INPUT-------------------------------------------

'Word ×Ö£¨Word£©

'OUTPUT------------------------------------------

'·µ»ØÖµ Word²ÎÊýµÄ¸ß×Ö½Ú

'Last updated by Liu Qi 2004-3-20¡£

Dim bytRet As Byte

CopyMemory bytRet£¬ ByVal VarPtr(Word) + 1£¬ 1¡¯°ÑWordµÄ¸ß×Ö½ÚµÄÄÚÈÝ¿¾ÈëbytRetµÄµØÖ·´¦

Hi = bytRet¡¯·µ»Ø½á¹û

End Function

¡¡¡¡¸ù¾ÝÊý¾ÝÀàÐ͵IJ»Í¬ÐèÒª£¬±ÊÕß¹²Éè¼ÆÁË6¸öº¯Êý£¬HI£¨£©º¯ÊýÓÃÀ´»ñµÃÒ»¸öµ¥×ֵĸß×Ö½Ú£¬LO£¨£©º¯Êý»ñµÃµ¥×ֵĵÍ×Ö½Ú£¬HIWORD£¨£©º¯Êý»ñµÃË«×ֵĸßλ×Ö£¬LOWORD£¨£©º¯ÊýË«×ֵĵÍλ×Ö¡££Ã£Ï£Î£¨£©º¯Êý°ÑÁ½¸ö×Ö½Ú×éºÏ³É×Ö£¬CONWORD£¨£©º¯Êý°ÑÁ½¸ö×Ö×éºÏ³ÉË«×Ö¡£Ö»Òª°ÑÕ⣶¸öº¯Êý×éºÏÓ¦ÓþͿÉÒÔËæÒâµÄ²ð·Ö¡¢×éºÏ¸÷ÖÖÕûÐͱäÁ¿¡£ÀýÈçÇ°ÃæÌáµ½µÄ£É£ÐµØÖ·£¬£É£ÐµØÖ·ÊÇÓÃÒ»¸ö£Ä£×£Ï£Ò£ÄÀàÐͱäÁ¿´æ´¢µÄ£¬ÔÚ£Ö£ÂÖÐÔò¶ÔÓ¦LongÀàÐͱäÁ¿£¬¼ÙÉèÒ»¸ö£É£ÐµØÖ·´æ´¢ÔÚ³¤ÕûÐͱäÁ¿ÖУ¬¾Í¿ÉÒÔÕâÑùÌáÈ¡Ò»¸ö£É£ÐµØÖ·µÄ×î¸ß×Ö½Ú£º£È£É£¨£È£É£×£Ï£Ò£Ä£¨lng£É£Ð£©£©¡£

¡¡¡¡ÓÉÓÚ´úÂë½Ï³¤£¬¹ÊûÓÐÔÚÎÄÕÂÖÐд³öÈ«²¿´úÂë¡£

·½·¨2£ºÀûÓð²È«Êý×é½èÓÃÄÚ´æµÄ·½·¨ÊµÏÖ

¡¡¡¡·½·¨1ËäÈ»ÓÃÆðÀ´¼òµ¥·½±ã£¬µ«ÊÇÒªÖ´ÐÐAPIº¯Êýµ÷Ó㬺¯Êýµ÷ÓÃʱҪ±£´æÏÖ³¡¡¢»Ö¸´ÏÖ³¡£¬Ê±¼ä¿ªÏúºÜ´ó£¬Ð§ÂÊÌ«µÍ£¬Òò´Ë²»ÊʺϴóÊý¾ÝÁ¿Ãܼ¯ÔËËãµÄ³¡ºÏ¡£±ÊÕßÔÚ¿ª·¢¼ÓÃÜÈí¼þʱÔøʹÓ÷½·¨1À´´¦ÀíÎļþÊý¾Ý£¬Ð§¹ûºÜ²»ÀíÏ룬ËÙ¶ÈÆæÂý¡£ÆäʵÓÐÒ»ÖÖ·½·¨¿ÉÒÔÇÉÃîµÄÆ­¹ýVB£¬ÈÃÒ»¸öÊý×éÖ±½Ó·ÃÎÊÆäËû±äÁ¿µÄÄÚ´æ¿Õ¼ä£¬´Ó¶ø´ïµ½²ð·Ö¡¢ºÏ²¢ÕûÐαäÁ¿µÄÄ¿µÄ¡£ÓÉÓÚÕâÖÖ·½·¨Ê¡È¥ÁËAPIº¯Êýµ÷Óã¬Òò´ËЧÂʷdz£¸ß¡£ÏÂÃæ¾ÍÈÃÎÒÃÇÈÏʶһÏÂVBÖеݲȫÊý×é¡£VBÖеݲȫÊý×éÓëCÓïÑÔÖеÄÊý×éÓкܴóµÄ²î±ð£¬ËäÈ»ÔÚVBºÍCÓïÑÔÖÐÊý×é±äÁ¿¶¼ÊÇÖ¸Õ룬µ«CÓïÑÔÖеÄÊý×é±äÁ¿Ö±½ÓÖ¸ÏòÊý×éÔªËØ£¬¶ø VBÖеÄÊý×é±äÁ¿È´ÊÇÖ¸ÏòÒ»¸öSafeArray½á¹¹£¬Õâ¸öSafeArray½á¹¹ÖеÄpvDataÓò²ÅÖ¸ÏòÊý×éÔªËØ¡£

¡¡¡¡ÄÇôÕâ¸öSafeArray½á¹¹ÊÇ×öʲôÓõÄÄØ£¿Ëü´æ´¢×ÅÊý×éµÄÉϽ硢Ͻ硢άÊý¡¢ÔªËØ´óСµÈһϵÁеÄÐÅÏ¢£¬ÕýÊÇSafeArray½á¹¹µÄ´æÔÚ£¬Ê¹µÃVB³ÌÐòÄܹ»¶ÔÊý×éµÄ·ÃÎÊ×öÔ½½ç¼ì²é£¬Õâ¾ÍÊÇΪʲôVBÖеÄÊý×é½Ð×ö°²È«Êý×éµÄÔ­Òò£¬¶øCÓïÑÔÖеÄÊý×éÏÔÈ»²»¾ß±¸Ô½½ç¼ì²éµÄÄÜÁ¦¡£µ±È»°²È«Êý×éµÄȱµã¾ÍÊÇûÓÐCÓïÑÔµÄÊý×éÁé»î£¬µ«¾¡¹ÜÈç´Ë£¬ÎÒÃÇ»¹ÊÇÓа취²Ù×ÝËü£¬Í¨¹ý¶Ô°²È«Êý×éµÄ²Ù×Ý£¬¿ÉÒÔÈÃËü·ÃÎÊÈÎÒâµÄÄÚ´æλÖã¬ÉõÖÁ°üÀ¨ÆäËû±äÁ¿µÄÄÚ´æ¿Õ¼ä¡£¶ÔÓÚһάÊý×éÀ´Ëµ£¬ËüµÄSafeArray½á¹¹ÈçÏ£º
Type SafeArray1d '1άÊý×éµÄ SafeArray ¶¨Òå

cDims As Integer 'άÊý

fFeatures As Integer '±êÖ¾

cbElements As Long 'µ¥¸öÔªËصÄ×Ö½ÚÊý

clocks As Long 'Ëø¶¨¼ÆÊý

pvData As Long 'Ö¸ÏòÊý×éÔªËصÄÖ¸Õë

cElements As Long 'ά¶¨Ò壬¸ÃάµÄÔªËظöÊý

Lbound As Long '¸ÃάµÄϽç

End Type

¡¡¡¡Èç¹ûÏÔʽµÄ¸øÒ»¸öÊý×é±äÁ¿¸³Öµ£¬ÈÃËüÖ¸ÏòÎÒÃÇ×Ô¼º´´½¨µÄSafeArray½á¹¹£¬¾Í¿ÉÒÔͨ¹ýÉèÖÃSafeArray½á¹¹µÄpvDataÓòÀ´·ÃÎÊÈÎÒâÄÚ´æλÖá£Ç뿴ʾÀý´úÂ룺
Public Declare Function VarPtrArray Lib "msvbvm60.dll" _Alias "VarPtr" (ptr() As Any) As Long

Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any£¬ Source As Any£¬ ByVal Length As Long)

Private Sub Command2_Click()

Dim pBytesInLong() As Byte

Dim SA1D As SafeArray1d

Dim i As Long

With SA1D

.cDims = 1

.fFeatures = 17

.cbElements = 1

.clocks = 0

.pvData = VarPtr(i) 'ʹÊý×éµÄÊý¾ÝÖ¸ÕëÖ¸Ïò³¤ÕûÐαäÁ¿ i

.cElements = 4

.Lbound = 0

End With


'ʹÊý×é±äÁ¿£¨Æäʵ¾ÍÊǸöÖ¸Õ룩ָÏòÎÒÃÇ×Ô¼º´´½¨µÄ SafeArray1d ½á¹¹

CopyMemory ByVal VarPtrArray(pBytesInLong)£¬ VarPtr(SA1D)£¬ 4

i = &HFFFFFFFF

MsgBox pBytesInLong(1) '·ÃÎʳ¤ÕûÐαäÁ¿µÄµÚ2¸ö×Ö½Ú£¨´ÓµÍ´¦¿ªÊ¼Êý£©

pBytesInLong(3) = 0 '°ÑÈ«²¿Êý×éÔªËØÉèΪ0

pBytesInLong(2) = 0

pBytesInLong(1) = 0

pBytesInLong(0) = 0

MsgBox i 'Äã»á·¢ÏÖ i Ò²±ä³ÉÁË 0

'°ÑÊý×é±äÁ¿£¨Æäʵ¾ÍÊǸöÖ¸Õ룩ָÏò 0£¬¼È C ÓïÑÔÖÐµÄ NULL

CopyMemory ByVal VarPtrArray(pBytesInLong)£¬ 0&£¬ 4

End Sub

¡¡¡¡´Ó´úÂëÖпÉÒÔ¿´µ½ÎÒÃÇÓÃÒ»¸ö×Ö½ÚÊý×é½èÓÃÁ˳¤ÕûÐαäÁ¿iµÄµØÖ·¿Õ¼ä£¬´Ó¶ø¿ÉÒÔͨ¹ýÊý×éÔªËØ·ÃÎʱäÁ¿iµÄ¸÷¸ö×Ö½Ú¡£ÕâÑùҲʵÏÖÁ˲ð·Ö¡¢×éºÏÕûÐαäÁ¿µÄÄ¿µÄ£¬ºÍ·½·¨1Êâ;ͬ¹é£¬µ«ºÜÏÔÈ»·½·¨2²»ÐèÒªº¯Êýµ÷Ó㬲»ÐèÒªÊý¾Ý¸´ÖÆ£¬Òò´ËЧÂʷdz£¸ß¡£ÓÃÕâÖÖ·½·¨£¬ÎÒרÃŹ¹ÖþÁËÒ»¸öÄ£¿é£ºFastBitExÄ£¿é£¬ÊµÏÖÁË·½·¨1ÖÐÌá¼°µÄ6¸öº¯ÊýµÄFast°æ±¾£¬´úÂëºÜ³¤£¬²»ÔÚÕâÀï¸ø³ö£¬Çë¶ÁÕß²ÎÔÄ´úÂë¡£

2£®ÒÆλÔËËãµÄÉè¼ÆʵÏÖ

¡¡¡¡ÔںܶàVBµÄ×ÊÁϺʹúÂëÖж¼ÓóËÒÔ2µÄ·½·¨ÊµÏÖ×óÒÆ£¬³ýÒÔ2µÄ·½·¨ÊµÏÖÓÒÒÆ¡£ÕâÊÇ¿ÉÐеģ¬Ò²ÊÇÓÐÀíÂÛÒÀ¾ÝµÄ¡£ÏÂͼÊÇÒ»¸öBYTEÀàÐ͵ÄȨֵ±í£º

λÐòºÅ

7 6 5 4 3 2 1 0

Ȩֵ

27

26

25

24

23

22

21

20

¡¡¡¡¿ÉÒÔ¿´³öÿһλµÄȨֵ¶¼ÊDZÈËüµÍһλµÄÄÇһλµÄȨֵµÄ2±¶£¬¶ÔÒ»¸öBYTE±äÁ¿×óÒÆһλÏ൱ÓÚÿһ¸ö¶þ½øÖÆλ¶¼Ïò¸ßλÒƶ¯£¬ÔòÿһλµÄȨֵ±äΪԭÀ´µÄÁ½±¶£¨×î¸ßλ³ýÍ⣩£¬ÓÉÓÚBYTE±äÁ¿µÄÊ®½øÖÆÖµµÈÓÚËüµÄÿ¸ö¶þ½øÖÆλµÄÖµºÍ¸ÃλȨֵµÄ³Ë»ýµÄ×ܺͣ¬ËùÒÔ°ÑÒ»¸öBYTE±äÁ¿×óÒƺͰÑËüµÄÊ®½øÖÆÖµ³ËÒÔ2ÊǵÈЧµÄ£¬Î¨Ò»µÄÇø±ð¾ÍÊÇÈç¹ûBYTE±äÁ¿µÄ×î¸ßλΪ 1£¬³ËÒÔ2»áÒç³ö£¬ÎÒÃÇҪʹÓÃÒ»¸öС¼¼ÇÉ·ÀÖ¹Òç³ö£ºÏÈ°Ñ×î¸ßλÆÁ±ÎΪ0£¬ÔÙ³ËÒÔ2¾Í²»»áÒç³öÁË¡£¾Ý´ËÎÒÃÇ¿ÉÒÔд³ö°ÑBYTEÀàÐͱäÁ¿×óÒÆ1λµÄº¯Êý£º
Private Function ShLB_By1Bit(ByVal Byt As Byte) As Byte

¡®°ÑBYTEÀàÐͱäÁ¿×óÒÆ1λµÄº¯Êý£¬²ÎÊýBytÊÇ´ýÒÆλµÄ×Ö½Ú£¬º¯Êý·µ»ØÒÆλ½á¹û

¡®(Byt And &H7F)µÄ×÷ÓÃÊÇÆÁ±Î×î¸ßλ¡£ *2£º×óÒÆһλ

ShLB_By1Bit = (Byt And &H7F) * 2

End Function

¡¡¡¡ÀàËƵİÑBYTEÀàÐͱäÁ¿ÓÒÒÆ1λʱ²ÉÓóýÒÔ2µÄ·½·¨ £¬ÕâʱҪעÒâÉáȥСÊý룬ÒÔÃâVB°´ÕÕËÄÉáÎåÈëµÄ·½·¨´¦ÀíСÊýλ¶øÒýÆð½á¹û²»ÕýÈ·¡£¾Ý´ËÎÒÃÇ¿ÉÒÔд³ö°ÑBYTEÀàÐͱäÁ¿ÓÒÒÆ1λµÄº¯Êý£º
Private Function ShRB_By1Bit(ByVal Byt As Byte) As Byte

¡®°ÑBYTEÀàÐͱäÁ¿ÓÒÒÆ1λµÄº¯Êý£¬²ÎÊýBytÊÇ´ýÒÆλµÄ×Ö½Ú£¬º¯Êý·µ»ØÒÆλ½á¹û

¡®/2£ºÓÒÒÆһλ

ShRB_By1Bit = Fix(Byt / 2)

End Function

¡¡¡¡ÓÐÁËÒÆһλµÄº¯Êý£¬ÄÇôÒÆÈÎÒâλÊýµÄº¯Êý¾Í²»ÄÑд³öÁË£ºÖ»Òª·´¸´µÄµ÷ÓÃShLB_By1Bit()»òShRB_By1Bit()¾Í¿ÉÒÔÁË£¬²Î¼û´úÂëÖеĺ¯ÊýShLB() ºÍ ShRB()¡£

¡¡¡¡ÖÁ´Ë×Ö½Ú±äÁ¿µÄÒÆλÎÊÌâÒѾ­µÃµ½½â¾ö£¬ÏÖÔÚÔÙÀ´¿´µ¥×ÖºÍË«×ÖµÄÒÆ룬ËüÃÇ·Ö±ð¶ÔÓ¦VBÖеÄIntegerºÍLongÀàÐÍ¡£ÓóËÒÔ2ºÍ³ýÒÔ2µÄ·½·¨»¹ÐÐÂð£¿Óü¸¸öÊýÊÔÑéһϾͻᷢÏÖ£¬Õâ¸ö·½·¨Ê§ÁéÁË¡£Çë¿´¸÷ÖÖÔËËã½á¹ûµÄ¶Ô±È£º

¡¡¡¡A=1001¡¯0111¡¯1110¡¯1100

¡¡¡¡ÓÒÒÆһλ£º 0100¡¯1011¡¯1111¡¯0110

¡¡¡¡£¨A/2£©£º1100¡¯1011¡¯1111¡¯0110

¡¡¡¡ÎÊÌâºÃÏó±äµÄÓе㸴ÔÓÁË£¬Æäʵµ¼ÖÂÕâ¸ö·½·¨Ê§ÁéµÄ×î¸ù±¾µÄÔ­ÒòÊÇVB°ÑIntegerºÍLongÀàÐ͵±×öÓзûºÅÊýÀí½â£¬°ÑÒ»¸öÓзûºÅÊý³ËÒÔ2»ò³ýÒÔ2£¬×î¸ß루¼´·ûºÅ룩¸ù±¾¾ÍûÓвÎÓëÔËË㣬ÕâÒ»µã´ÓÉÏÃæµÄÔËËã½á¹û¶Ô±È¾Í¿ÉÒÔ¿´³öÀ´£º°ÑA³ýÒÔ2 ÒÔºó×î¸ßλ»¹ÊÇ1£¬¸ù±¾¾ÍûÓб䣬¶øÓÒÒÆһλºó×î¸ßλ²¹ÈëµÄÊÇ0£¬Á½ÖÖÔËËãµÄ½á¹û×ÔÈ»ÊÇÏàÈ¥ÉõÔ¶¡£²»Ö»ÊÇ·ûºÅλµÄÎÊÌ⣬Èç¹ûÑ¡ÓÃÆäËüµÄÊý¾ÝÀ´¶Ô±È»¹»á·¢ÏÖ¸ü¶àµÄÎÊÌ⣬ÕâÀï¾Í²»ÔÙ׸ÊöÁË¡£ÄѵÀ¾ÍÕæµÄûÓа취ÁËÂ𣿰취µ±È»ÊÇÓеģ¬¼ÈÈ»ÒѾ­ÊµÏÖÁË×Ö½ÚµÄÒÆλ²Ù×÷£¬ÄÇô¿ÉÒÔ Óá°·Ö¶øÖÎÖ®¡±µÄ²ßÂÔ£¬°ÑInteger±äÁ¿Ò»·ÖΪ¶þ£¬²ð³ÉÁ½¸ö×Ö½Ú£¬°ÑÕâÁ½¸ö×Ö½Ú½»¸øShLB£¨£©»ò£Óh£Ò£Â£¨£©£¬°ÑËüÁ©¸÷ÒÆһ룬×îºó°ÑÒÆλºóµÄÁ½×Ö½ÚÖØÐÂ×éºÏ³ÉÒ»¸öInteger±äÁ¿¾ÍÊÇÒÆλºóµÄ½á¹ûÁË£¬Õâ²»¾ÍʵÏÖÁËIntegerÀàÐͱäÁ¿µÄÒÆλÁËÂð¡£ÕâÖÖ·½·¨ÍêÈ«ÈƹýÁËÓзûºÅÊýµÄ·ûºÅλ¸øÎÒÃÇ´øÀ´µÄÖÚ¶àÂé·³£¬Ë³ÀûµÄʵÏÖÁËÄ¿µÄ¡£ÓÃÕâÖÖ·½·¨ÐèҪעÒâÒ»µã£ºÈç¹ûÊÇ×óÒÆ£¬Òª±£Ö¤°ÑµÍ×Ö½ÚµÄ×î¸ßλÒÆÈë¸ß×Ö½ÚµÄ×îµÍ룬·´Ö®Èç¹ûÊÇÓÒÒÆ£¬Òª°Ñ¸ß×Ö½ÚµÄ×îµÍλÒÆÈëµÍ×Ö½ÚµÄ×î¸ßλ¡£´ÓÏÂÃæµÄ´úÂëÖпÉÒÔ¿´µ½ÊµÏֵĹý³Ì£º
Private Function ShLW_By1Bit(ByVal Word As Integer) As Integer

'°ÑÒ»¸ö×Ö×óÒÆһλµÄº¯Êý£¬ ²ÎÊýWordÊÇ´ýÒÆλµÄ×Ö£¬º¯Êý·µ»ØÒÆλ½á¹û

'INPUT-------------------------------

'Word Ô´²Ù×÷Êý

'OUTPUT------------------------------

'·µ»ØÖµ ÒÆλ½á¹û

'last updated by Liu Qi 2004-3-24


Dim HiByte As Byte£¬ LoByte As Byte

'°Ñ×Ö²ð·ÖΪ×Ö½Ú

HiByte = Hi(Word)£º LoByte = Lo(Word)

'°Ñ¸ß×Ö½Ú×óÒÆһ룬±£Ö¤°ÑµÍ×Ö½ÚµÄ×î¸ßλÒÆÈë¸ß×Ö½ÚµÄ×îµÍλ

HiByte = ShLB_By1Bit(HiByte) Or IIf((LoByte And &H80) = &H80£¬ &H1£¬ &H0)

LoByte = ShLB_By1Bit(LoByte) 'µÍ×Ö½Ú×óÒÆһλ

'°ÑÒÆλºóµÄ×Ö½ÚÔÙÖØÐÂ×éºÏ³É×Ö

ShLW_By1Bit = Con(HiByte£¬ LoByte)

End Function

¡¡¡¡ÖÁÓÚLongÀàÐÍ£¬ºÍIntegerÀàÐÍÒ»Ñù£¬ÊôÓÚÓзûºÅÊý£¬Ò²²»ÄÜÓóËÒÔ2ºÍ³ýÒÔ2µÄ·½·¨ÊµÏÖÒÆλ¡£ÎÒÃÇÖ»ºÃºÍ´¦ÀíIntegerÀàÐÍÒ»ÑùÈç·¨ÅÚÖÆ£¬Ó÷ֶøÖÎÖ®µÄ·½·¨ÊµÏÖÒÆλ¡£¾ßÌå¹ý³Ì²»ÔÙ׸Êö£¬Çë²Î¿´´úÂë¡£

3.ÒÆλÔËËãµÄÐÔÄÜÓÅ»¯

¡¡¡¡±¾ÎÄÖеÄÒÆλʵÏÖ·½·¨Æ«ÖØÓÚ´úÂëµÄ¿É¶ÁÐÔ£¬Ã»ÓÐÓÅ»¯´úÂëµÄÐÔÄÜ£¬Òò´Ë²»ÊÊÓÃÓÚ¶ÔÐÔÄÜÒªÇó¿Á¿ÌµÄ³¡ºÏ¡£ÎªÁËÓÅ»¯ÐÔÄÜ£¬¿ÉÒÔÓòé±í·¨À´ÓÅ»¯Ö´ÐÐËٶȣ¬ÕâÊÇÒ»ÖÖÄÿռ任ʱ¼äµÄ·½°¸£¬ÒÆλ½á¹û¿ÉÒÔÊÂÏȶ¼¼ÆËã³öÀ´£¬±£´æÔÚÒÆλ±íÖУ¬ÓõÄʱºò²é±í£¬±ÈÓÃ*2£¬/2¿ì¶àÁË¡£±ÈÈ磬×Ö½ÚÀàÐ͵ÄÒÆλ±íÊý×鶨ÒåÈçÏ£º¡¡
¡¡¡¡dim aSHLB(0 to 255,1 to 7) as byte'×Ö½Ú×óÒƱí

¡¡¡¡dim aSHRB(0 to 255,1 to 7) as byte'×Ö½ÚÓÒÒƱí

¡¡¡¡Ê¹Ó÷½·¨Ò²ºÜ¼òµ¥£¬±ÈÈçÏëÒªÇó×Ö½Ú±äÁ¿x×óÒÆһλµÄ½á¹û£¬Ö»ÐèʹÓÃaSHLB(x,1)¾Í¿ÉµÃµ½£¬ºÍº¯Êýµ÷ÓúÜÏàËÆ¡£µ±È»£¬Ó뺯Êýµ÷Óò»Í¬µÄÊÇ£¬Ê¹ÓÃÒÆλ±í֮ǰһ¶¨Òª³õʼ»¯ÒÆλ±íµÄËùÓÐÔªËØ£¬·ñÔò»áµÃµ½´íÎóµÄ½á¹û¡£

¡¡¡¡IntegerÀàÐ͵ÄÒÆλҲ¿ÉÒÔÓòé±í·¨£¬ÒÆλ±íÕ¼Óà 65535 * 15 * 2 * 2 ¸ö×Ö½ÚµÄÄÚ´æ¿Õ¼ä¡£

¡¡¡¡ÒÆλ±íÊý×鶨ÒåÈçÏ£º
¡¡¡¡aSHLW(0 to &Hffff&,1 to 15) as integer'µ¥×ÖµÄ×óÒƱí

¡¡¡¡aSHRW(0 to &Hffff&,1 to 15) as integer'µ¥×ÖµÄÓÒÒƱí

¡¡¡¡×¢Ò⣺IntegerÊÇÓзûºÅÀàÐÍ£¬Ôì±íµÄʱºòÒªÓÃËüµÄÎÞ·ûºÅÖµÀ´Ôì±í£¬Í¬Ñù²é±íµÄʱºòÒ²ÒªÓÃËüµÄÎÞ·ûºÅÖµÀ´²é±í¡££¨ÒòΪÊý×éϱêÊDz»ÔÊÐí¸ºÊýµÄ¡££©

¡¡¡¡ÇóIntegerÀàÐÍÎÞ·ûºÅÖµµÄ·½·¨ÊÇ£º(Int and &hFFFF&),×¢Ò⣬²»µÈͬÓÚCLng(Int)

¡¡¡¡Òź¶µÄÊÇ£¬LongÀàÐÍÎÞ·¨Ôì±í£¬ÒòΪLongÀàÐ͵ÄÖµµÄ·¶Î§ÊÇ 4 GB,Èç¹û¶ÔËüÔì±í£¬ÄÇô±íµÄ´óС¾Í»á³¬³ö×ܵÄÄÚ´æµØÖ·¿Õ¼ä¡£

¡¡¡¡²é±íÒÆλµÄ´úÂëÇë²Î¼û±¾Îĸ½´øµÄ´úÂ룬ÕâÀï¾Í²»¸ø³öÁË¡£

Èý ½áÓï

¡¡¡¡ÒªÏëʵÏÖ±¾ÎÄËùÊöµÄÄÇЩλ²Ù×÷º¯ÊýÆäʵÓкܶ෽·¨£¬±¾ÎÄËùÓõķ½Ê½Î´±ØÊÇ×îºÃµÄ£¬Ö÷ÒªÊÇΪÁËÌṩһÖÖ½â¾öÎÊÌâµÄ˼·£ºÔÚ±à³Ì¹ý³ÌÖÐÓöµ½ÄÑÒÔ½â¾öµÄÎÊÌâʱ£¬ÏëÒ»ÏëÄܲ»ÄÜ°Ñ´óÎÊÌâ·Ö½â³ÉÄܽâ¾ö»òÒѽâ¾öµÄСÎÊÌ⣬Õâ¾ÍÊÇ¡°·Ö¶øÖÎÖ®¡±µÄ²ßÂÔ¡£Òò±ÊÕßˮƽÓÐÏÞ£¬±¾ÎÄÄÑÃâ»áÓÐÊ詺Ͳ»×ãÖ®´¦£¬»¶Ó­ÅúÆÀÖ¸Õý£¬ÓÐÒâ¼û»ò½¨Òé¸øÎÒ·¢µç×ÓÓʼþliuqi5521@sina.com¡£

¡¡¡¡±¾³ÌÐòÔÚ Win2000+VB6.0ϵ÷ÊÔͨ¹ý¡£

------------------------------------------------------------

±¾ÎÄÏà¹Ø´úÂ룺

-----------------------BitEx.Bas----------------------------

Option Explicit

'˵Ã÷----------------------------------------
'ÕâÊÇÒ»¸öÔöÇ¿ vb µÄλ²Ù×÷¹¦ÄܵÄÄ£¿é£¬Ö÷Òª°üº¬
'ÓÐ×óÓÒÒÆλ£¬È¡×Ö½Ú£¬×Ö½ÚÁ¬½ÓµÈͨÓÃÀý³Ì
'¼æÈÝÐÔ£ºVB5.0 ,6.0
'--------------------------------------------

'×÷ÕߣºÁõçù £¬2005-1-11
'¸öÈËÖ÷Ò³£ºhttp://LQweb.crcoo.com
'e-Mail£ºliuqi5521@hotmail.com


'apiº¯Êý  ¿½±´ÄÚ´æ
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)

'-----------------------ÏÂÃæÕâЩÀý³ÌʵÏÖÕûÐͱäÁ¿µÄ²ð·Ö£¬ºÏ²¢²Ù×÷-------------
Public Function Con(ByVal HiByte As Byte, ByVal LoByte As Byte) As Integer
'°ÑÁ½¸ö×Ö½Ú (Byte) Á¬³ÉÒ»¸ö×Ö £¨word£©
'INPUT--------------------------------------------------------------------
    'HiByte      ²ÎÓëÁ¬½áµÄ¸ß×Ö½Ú
    'LoByte      ²ÎÓëÁ¬½áµÄµÍ×Ö½Ú
'OUTPUT-------------------------------------------------------------------
    '·µ»ØÖµ      Á¬½áµÄ½á¹û
'Last updated by Liu Qi 2004-3-20.
Dim iRet As Integer

'Óõ½µÄº¯Êý varptr() ˵Ã÷£ºÈ¡Ò»¸ö±äÁ¿µÄµØÖ·¡£

CopyMemory ByVal VarPtr(iRet), LoByte, 1
CopyMemory ByVal VarPtr(iRet) + 1, HiByte, 1

Con = iRet

End Function

Public Function ConWord(ByVal HiWord As Integer, ByVal LoWord As Integer) As Long
'°ÑÁ½¸ö×Ö£¨Word£©Á¬³ÉÒ»¸öË«×Ö£¨DWord£©
'INPUT--------------------------------------------------------------------
    'HiWord      ²ÎÓëÁ¬½áµÄ¸ßλ×Ö
    'LoWord      ²ÎÓëÁ¬½áµÄµÍλ×Ö
'OUTPUT-------------------------------------------------------------------
    '·µ»ØÖµ      Á¬½áµÄ½á¹û
'Last updated by Liu Qi 2004-3-20.
Dim lRet As Long

CopyMemory ByVal VarPtr(lRet), LoWord, 2
CopyMemory ByVal VarPtr(lRet) + 2, HiWord, 2

ConWord = lRet

End Function

Public Function Hi(ByVal Word As Integer) As Byte
'È¡Ò»¸ö×Ö£¨Word£©µÄ¸ß×Ö½Ú£¨Byte£©
'INPUT-------------------------------------------
    'Word      ×Ö£¨Word£©
'OUTPUT------------------------------------------
    '·µ»ØÖµ     Word²ÎÊýµÄ¸ß×Ö½Ú
'Last updated by Liu Qi 2004-3-20.
Dim bytRet As Byte

CopyMemory bytRet, ByVal VarPtr(Word) + 1, 1

Hi = bytRet

End Function

Public Function Lo(ByVal Word As Integer) As Byte
'È¡Ò»¸ö×Ö£¨Word£©µÄµÍ×Ö½Ú£¨Byte£©
'INPUT-------------------------------------------
    'Word      ×Ö£¨Word£©
'OUTPUT------------------------------------------
    '·µ»ØÖµ     Word²ÎÊýµÄµÍ×Ö½Ú
'Last updated by Liu Qi 2004-3-20.
Dim bytRet As Byte

CopyMemory bytRet, ByVal VarPtr(Word), 1

Lo = bytRet

End Function

Public Function HiWord(ByVal DWord As Long) As Integer
'È¡Ò»¸öË«×Ö£¨DWord£©µÄ¸ßλ×Ö
'INPUT-------------------------------------------
    'DWord      Ë«×Ö
'OUTPUT------------------------------------------
    '·µ»ØÖµ     DWord²ÎÊýµÄ¸ßλ×Ö
'Last updated by Liu Qi 2004-3-20.
Dim intRet As Integer

CopyMemory intRet, ByVal VarPtr(DWord) + 2, 2

HiWord = intRet

End Function

Public Function LoWord(ByVal DWord As Long) As Integer
'È¡Ò»¸öË«×Ö£¨DWord£©µÄµÍλ×Ö
'INPUT-------------------------------------------
    'DWord      Ë«×Ö
'OUTPUT------------------------------------------
    '·µ»ØÖµ     DWord²ÎÊýµÄµÍλ×Ö
'Last updated by Liu Qi 2004-3-20.
Dim intRet As Integer

CopyMemory intRet, ByVal VarPtr(DWord), 2

LoWord = intRet

End Function

'-------------------------ÏÂÃæÕâЩÀý³ÌʵÏÖÕûÐαäÁ¿µÄÒÆλ-------------------

Public Function ShLB(ByVal Byt As Byte, Optional ByVal BitsNum As Long = 1) As Byte
'×Ö½ÚµÄ×óÒƺ¯Êý
'INPUT-----------------------------
    'Byt Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT----------------------------
    '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-23
Dim i&

For i = 1 To BitsNum
    Byt = ShLB_By1Bit(Byt)
Next i

ShLB = Byt

End Function

Public Function ShRB(ByVal Byt As Byte, Optional ByVal BitsNum As Long = 1) As Byte
'×Ö½ÚµÄÓÒÒƺ¯Êý
'INPUT-----------------------------
    'Byt Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT----------------------------
    '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-23
Dim i&

For i = 1 To BitsNum
    Byt = ShRB_By1Bit(Byt)
Next i

ShRB = Byt

End Function

Private Function ShLB_By1Bit(ByVal Byt As Byte) As Byte
'°Ñ×Ö½Ú×óÒÆһλµÄº¯Êý,Ϊ ShlB ·þÎñ.
'INPUT-----------------------------
    'Byt Ô´²Ù×÷Êý
'OUTPUT----------------------------
    '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-23

'(Byt And &H7F): ÆÁ±Î×î¸ßλ.  *2:×óÒÆһλ
ShLB_By1Bit = (Byt And &H7F) * 2

'ShlB_By1Bit = Byt * 2'Òç³ö²âÊÔ

End Function
Private Function ShRB_By1Bit(ByVal Byt As Byte) As Byte
'°Ñ×Ö½ÚÓÒÒÆһλµÄº¯Êý,Ϊ ShrB ·þÎñ.
'INPUT-----------------------------
    'Byt Ô´²Ù×÷Êý
'OUTPUT----------------------------
    '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-24

'/2:ÓÒÒÆһλ
ShRB_By1Bit = Fix(Byt / 2)

End Function


Public Function ShLW(ByVal Word As Integer, Optional ByVal BitsNum As Long = 1) As Integer
'×ÖµÄ×óÒƺ¯Êý
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-24
Dim i&

For i = 1 To BitsNum
    Word = ShLW_By1Bit(Word)
Next i

ShLW = Word

End Function

Public Function ShRW(ByVal Word As Integer, Optional ByVal BitsNum As Long = 1) As Integer
'×ÖµÄÓÒÒƺ¯Êý
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-24
Dim i&

For i = 1 To BitsNum
    Word = ShRW_By1Bit(Word)
Next i

ShRW = Word
End Function
Private Function ShLW_By1Bit(ByVal Word As Integer) As Integer
'°ÑÒ»¸ö×Ö×óÒÆһλµÄº¯Êý
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
   
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-24
Dim HiByte As Byte, LoByte As Byte

'°Ñ×Ö²ð·ÖΪ×Ö½Ú
HiByte = Hi(Word): LoByte = Lo(Word)
'°Ñ¸ß×Ö½Ú×óÒÆһλ,±£Ö¤°ÑµÍ×Ö½ÚµÄ×î¸ßλÒÆÈë¸ß×Ö½ÚµÄ×îµÍλ
HiByte = ShLB_By1Bit(HiByte) Or IIf((LoByte And &H80) = &H80, &H1, &H0)
LoByte = ShLB_By1Bit(LoByte) 'µÍ×Ö½Ú×óÒÆһλ
'°ÑÒÆλºóµÄ×Ö½ÚÔÙÖØÐÂ×éºÏ³É×Ö
ShLW_By1Bit = Con(HiByte, LoByte)

End Function

Private Function ShRW_By1Bit(ByVal Word As Integer) As Integer
'°ÑÒ»¸ö×ÖÓÒÒÆһλµÄº¯Êý
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
   
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-27
Dim HiByte As Byte, LoByte As Byte

'°Ñ×Ö²ð·ÖΪ×Ö½Ú
HiByte = Hi(Word): LoByte = Lo(Word)

'µÍ×Ö½ÚÓÒÒÆһλ,±£Ö¤°Ñ¸ß×Ö½ÚµÄ×îµÍλÒÆÈëµÍ×Ö½ÚµÄ×î¸ßλ
LoByte = ShRB_By1Bit(LoByte) Or IIf((HiByte And &H1) = &H1, &H80, &H0)

'°Ñ¸ß×Ö½ÚÓÒÒÆһλ,
HiByte = ShRB_By1Bit(HiByte)

'°ÑÒÆλºóµÄ×Ö½ÚÔÙÖØÐÂ×éºÏ³É×Ö
ShRW_By1Bit = Con(HiByte, LoByte)


End Function


Public Function ShLD(ByVal DWord As Long, Optional ByVal BitsNum As Long = 1) As Long
'°ÑÒ»¸öË«×Ö×óÒƵĺ¯Êý
'INPUT-------------------------------
    'DWord Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-28
Dim i&

For i = 1 To BitsNum
    DWord = ShLD_By1Bit(DWord)
Next i

ShLD = DWord

End Function

Public Function ShRD(ByVal DWord As Long, Optional ByVal BitsNum As Long = 1) As Long
'°ÑÒ»¸öË«×ÖÓÒÒƵĺ¯Êý
'INPUT-------------------------------
    'DWord Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-28
Dim i&

For i = 1 To BitsNum
    DWord = ShRD_By1Bit(DWord)
Next i

ShRD = DWord
End Function
Public Function ShLD_By1Bit(ByVal DWord As Long) As Long
'°ÑÒ»¸öË«×Ö×óÒÆһλµÄº¯Êý£¬Îª ShlD() ·þÎñ
'INPUT-------------------------------
    'DWord Ô´²Ù×÷Êý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-29
Dim iHiWord%, iLoWord%

'°ÑË«×Ö²ð·ÖΪÁ½¸öµ¥×Ö
iHiWord = HiWord(DWord): iLoWord = LoWord(DWord)

'¸ßλ×Ö×óÒÆһλ,Òª°ÑµÍλ×ÖµÄ×î¸ßλÒƵ½¸ßλ×ÖµÄ×îµÍλ
iHiWord = ShLW_By1Bit(iHiWord) Or IIf((iLoWord And &H8000) = &H8000, &H1, &H0)

'µÍλ×Ö×óÒÆһλ
iLoWord = ShLW_By1Bit(iLoWord)

ShLD_By1Bit = ConWord(iHiWord, iLoWord) 'ÖØÐÂÁ¬½Ó³ÉË«×Ö·µ»Ø½á¹û

End Function

Public Function ShRD_By1Bit(ByVal DWord As Long) As Long
'°ÑÒ»¸öË«×ÖÓÒÒÆһλµÄº¯Êý,Ϊ ShrD() ·þÎñ
'INPUT-------------------------------
    'DWord Ô´²Ù×÷Êý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
'last updated by Liu Qi 2004-3-29
Dim iHiWord%, iLoWord%

'°ÑË«×Ö²ð·ÖΪÁ½¸öµ¥×Ö
iHiWord = HiWord(DWord): iLoWord = LoWord(DWord)

'°ÑµÍλ×ÖÓÒÒÆһ룬Ҫ°Ñ¸ßλ×ÖµÄ×îµÍλÒƵ½µÍλ×ÖµÄ×î¸ßλ
iLoWord = ShRW_By1Bit(iLoWord) Or IIf((iHiWord And &H1) = &H1, &H8000, &H0)

'°Ñ¸ßλ×ÖÓÒÒÆһλ
iHiWord = ShRW_By1Bit(iHiWord)

ShRD_By1Bit = ConWord(iHiWord, iLoWord) 'ÖØÐÂÁ¬½Ó³ÉË«×Ö·µ»Ø½á¹û

End Function

Public Function ShLB_C_By1Bit(ByVal Byt As Byte) As Byte
'°Ñ×Ö½Ú<<Ñ­»·>>×óÒÆһλµÄº¯Êý.C ±íʾ Cycle,Ñ­»·
'INPUT-----------------------------
    'Byt :Ô´²Ù×÷Êý
'OUTPUT----------------------------
    '·µ»ØÖµ : ÒÆλ½á¹û
'last updated by Liu Qi 2004-8-8

'(Byt And &H7F): ÆÁ±Î×î¸ßλ.  *2:×óÒÆһλ
ShLB_C_By1Bit = ((Byt And &H7F) * 2) Or IIf((Byt And &H80) = &H80, &H1, &H0)
End Function

Public Function ShRB_C_By1Bit(ByVal Byt As Byte) As Byte
'°Ñ×Ö½Ú<<Ñ­»·>>ÓÒÒÆһλµÄº¯Êý¡£
'INPUT-----------------------------
    'Byt :Ô´²Ù×÷Êý
'OUTPUT----------------------------
    '·µ»ØÖµ : ÒÆλ½á¹û
'last updated by Liu Qi 2004-8-8

'(Byt And &H7F): ÆÁ±Î×î¸ßλ.  *2:×óÒÆһλ
ShRB_C_By1Bit = Fix(Byt / 2) Or IIf((Byt And &H1) = &H1, &H80, &H0)
End Function

Public Function U2F(ByVal UnsignedLong As Long) As Double
'°ÑÒ»¸ö³¤ÕûÐΰ´ÕÕÎÞ·ûºÅÊýת»¯³ÉÒ»¸ö¸¡µãÊýÖµ
    If (UnsignedLong And &H80000000) = &H80000000 Then
        'Èç¹û×î¸ß루·ûºÅλ£©Îª1£¬
        'Ôò°ÑËüµÄÆÁ±Î·ûºÅλºóµÄÖµ¼ÓÉÏ×î¸ßλÎÞ·ûºÅ±íʾ·¨µÄȨֵ(ȨֵУÕý)
        U2F = (UnsignedLong And &H7FFFFFFF) + 2 ^ 31
    Else 'Èç¹û×î¸ßλΪ 0£¬Ôò²»ÐèÌØÊâ´¦Àí
        U2F = UnsignedLong
    End If
End Function

Public Function F2U(ByVal Float As Double) As Long
'°ÑÒ»¸ö¸¡µãÊýÖµ°´ÕÕÎÞ·ûºÅÊýת»¯³ÉÒ»¸ö³¤ÕûÐÎ
    If Float > 2 ^ 32 - 1 Or Float < 0 Then
        'ÎÞ·ûºÅÊý²»ÄÜÈÝÄɵÄÖµ
        Err.Raise 6 'Òý·¢Òç³ö´íÎó
    ElseIf Float > &H7FFFFFFF Then '×î¸ßλΪ1,ÔòÏÈÆÁ±Î×î¸ßλÒÔ˳ÀûÍê³ÉÏòÕûÐεÄת»¯£¬×îºóÔÙ°Ñ×î¸ßλµÄ1ÌíÉÏ
        F2U = CLng(Float - 2 ^ 31) Or &H80000000
    Else 'Èç¹û×î¸ßλΪ 0£¬Ôò²»ÐèÌØÊâ´¦Àí
        F2U = Float
    End If
End Function


Public Function UAdd(ByVal UnsignedLong1 As Long, ByVal UnsignedLong2 As Long) As Long
'°ÑVBÖеij¤ÕûÐΰ´ÕÕÎÞ·ûºÅ¼Ó·¨Ïà¼Ó
UAdd = F2U(U2F(UnsignedLong1) + U2F(UnsignedLong2))
End Function

Public Function UDif(ByVal UnsignedLong1 As Long, ByVal UnsignedLong2 As Long) As Long
'°ÑVBÖеij¤ÕûÐΰ´ÕÕÎÞ·ûºÅ¼õ·¨Ïà¼õ
UDif = F2U(U2F(UnsignedLong1) - U2F(UnsignedLong2))
End Function
-----------------------------------------------------------------

-------------------------------FastBit.Bas-----------------------

Option Explicit

'-----------------------------------------------------
'Õâ¸öÄ£¿éʹÓð²È«Êý×é¼¼ÊõʵÏÖÁËÒÔÏÂÁù¸öº¯ÊýµÄFast°æ±¾£º
'Hi(),Lo(),HiWord(),LoWord(),Con(),ConWord()
'¾­ÊÔÑ飬Fast°æ±¾µÄº¯ÊýÐÔÄÜÌá¸ß1±¶ÒÔÉÏ
'-----------------------------------------------------

'×÷ÕߣºÁõçù £¬2005-1-11
'¸öÈËÖ÷Ò³£ºhttp://LQweb.crcoo.com
'e-Mail£ºliuqi5521@hotmail.com


Private Type SafeArray1d '1άÊý×éµÄ SafeArray ¶¨Òå
    cDims As Integer 'άÊý
    fFeatures As Integer '±êÖ¾
    cbElements As Long 'µ¥¸öÔªËصÄ×Ö½ÚÊý
    clocks As Long 'Ëø¶¨¼ÆÊý
    pvData As Long 'Ö¸ÏòÊý×éÔªËصÄÖ¸Õë
    cElements As Long 'ά¶¨Ò壬¸ÃάµÄÔªËظöÊý
    Lbound As Long '¸ÃάµÄϽç
End Type
 
Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)

Private Declare Function VarPtrArray Lib "msvbvm60.dll" _
Alias "VarPtr" (ptr() As Any) As Long
 Const FADF_AUTO = &H1
 Const FADF_FIXEDSIZE = &H10

Private m_lSharedLong As Long 'Òª±»¹²ÏíµÄ³¤ÕûÐαäÁ¿
Private m_aiIntsInLong() As Integer 'Òª¹²Ïí³¤ÕûÐαäÁ¿µÄµØÖ·¿Õ¼äµÄÕûÐÎÊý×é
Private m_SA1D_IntArr As SafeArray1d 'ÕûÐÎÊý×éµÄSafeArray½á¹¹

Private m_iSharedInt As Integer 'Òª±»¹²ÏíµÄÕûÐαäÁ¿
Private m_aBytesInInt() As Byte 'Òª¹²ÏíÕûÐαäÁ¿µÄµØÖ·¿Õ¼äµÄ×Ö½ÚÊý×é
Private m_SA1D_ByteArr As SafeArray1d '×Ö½ÚÊý×éµÄSafeArray½á¹¹


'λ²Ù×÷Ç°³õʹ»¯¶¯×÷,Ö÷ÒªÊdzõʹ»¯£¬Èç¹û²»½øÐгõʹ»¯£¬½«»á³öÏÖ²»¿ÉÔ¤¼Æ´íÎó
Public Sub BitOperatorInit()

With m_SA1D_IntArr
    .cDims = 1 'άÊý£º1ά
    .fFeatures = 17 '±êÖ¾£ºAuto or FixedSize
    .cbElements = 2 'ÔªËØ´óС£º2¸ö×Ö½Ú
    .clocks = 0
    .pvData = VarPtr(m_lSharedLong) 'ʹÊý×éµÄÊý¾ÝÖ¸ÕëÖ¸Ïò³¤ÕûÐαäÁ¿m_lSharedLong
    .cElements = 2 'ÔªËظöÊý£º2¸ö
    .Lbound = 0 'Ͻ磺0
End With

'ʹÊý×é±äÁ¿m_aiIntsInLongÖ¸ÏòÎÒÃÇ×Ô¼º´´½¨µÄ SafeArray1d ½á¹¹
CopyMemory ByVal VarPtrArray(m_aiIntsInLong), VarPtr(m_SA1D_IntArr), 4

With m_SA1D_ByteArr
    .cDims = 1 'άÊý£º1ά
    .fFeatures = 17 '±êÖ¾£ºAuto or FixedSize
    .cbElements = 1 'ÔªËØ´óС£º1¸ö×Ö½Ú
    .clocks = 0
    .pvData = VarPtr(m_iSharedInt) 'ʹÊý×éµÄÊý¾ÝÖ¸ÕëÖ¸ÏòÕûÐαäÁ¿m_iSharedInt
    .cElements = 2 'ÔªËظöÊý£º2¸ö
    .Lbound = 0 'Ͻ磺0
End With

'ʹÊý×é±äÁ¿m_aBytesInIntÖ¸ÏòÎÒÃÇ×Ô¼º´´½¨µÄ SafeArray1d ½á¹¹
CopyMemory ByVal VarPtrArray(m_aBytesInInt), VarPtr(m_SA1D_ByteArr), 4

End Sub

Public Sub BitOperatorEnd()
'ÊÍ·Å×ÊÔ´£¬³ÌÐò½áÊøÇ°Ò»¶¨Òªµ÷ÓÃ

'°ÑÊý×é±äÁ¿m_aiIntsInLongÖ¸Ïò 0,¼È C ÓïÑÔÖÐµÄ NULL
CopyMemory ByVal VarPtrArray(m_aiIntsInLong), 0&, 4
'°ÑÊý×é±äÁ¿m_aBytesInIntÖ¸Ïò 0,¼È C ÓïÑÔÖÐµÄ NULL
CopyMemory ByVal VarPtrArray(m_aBytesInInt), 0&, 4

End Sub

'-----------------------ÏÂÃæÕâЩÀý³ÌʵÏÖÕûÐͱäÁ¿µÄ²ð·Ö£¬ºÏ²¢²Ù×÷,Fast°æ±¾-------------
Public Function fastCon(ByVal HiByte As Byte, ByVal LoByte As Byte) As Integer
'°ÑÁ½¸ö×Ö½Ú (Byte) Á¬³ÉÒ»¸ö×Ö £¨word£©
'INPUT--------------------------------------------------------------------
    'HiByte      ²ÎÓëÁ¬½áµÄ¸ß×Ö½Ú
    'LoByte      ²ÎÓëÁ¬½áµÄµÍ×Ö½Ú
'OUTPUT-------------------------------------------------------------------
    '·µ»ØÖµ      Á¬½áµÄ½á¹û
'Last updated by Liu Qi 2004-3-20.

m_aBytesInInt(1) = HiByte
m_aBytesInInt(0) = LoByte

fastCon = m_iSharedInt

End Function

Public Function fastConWord(ByVal HiWord As Integer, ByVal LoWord As Integer) As Long
'°ÑÁ½¸ö×Ö£¨Word£©Á¬³ÉÒ»¸öË«×Ö£¨DWord£©
'INPUT--------------------------------------------------------------------
    'HiWord      ²ÎÓëÁ¬½áµÄ¸ßλ×Ö
    'LoWord      ²ÎÓëÁ¬½áµÄµÍλ×Ö
'OUTPUT-------------------------------------------------------------------
    '·µ»ØÖµ      Á¬½áµÄ½á¹û
'Last updated by Liu Qi 2004-3-20.

m_aiIntsInLong(1) = HiWord
m_aiIntsInLong(0) = LoWord

fastConWord = m_lSharedLong

End Function

Public Function fastHi(ByVal Word As Integer) As Byte
'È¡Ò»¸ö×Ö£¨Word£©µÄ¸ß×Ö½Ú£¨Byte£©
'INPUT-------------------------------------------
    'Word      ×Ö£¨Word£©
'OUTPUT------------------------------------------
    '·µ»ØÖµ     Word²ÎÊýµÄ¸ß×Ö½Ú
'Last updated by Liu Qi 2004-3-20.
m_iSharedInt = Word
fastHi = m_aBytesInInt(1)

End Function

Public Function fastLo(ByVal Word As Integer) As Byte
'È¡Ò»¸ö×Ö£¨Word£©µÄµÍ×Ö½Ú£¨Byte£©
'INPUT-------------------------------------------
    'Word      ×Ö£¨Word£©
'OUTPUT------------------------------------------
    '·µ»ØÖµ     Word²ÎÊýµÄµÍ×Ö½Ú
'Last updated by Liu Qi 2004-3-20.

m_iSharedInt = Word
fastLo = m_aBytesInInt(0)

End Function

Public Function fastHiWord(ByVal DWord As Long) As Integer
'È¡Ò»¸öË«×Ö£¨DWord£©µÄ¸ßλ×Ö
'INPUT-------------------------------------------
    'DWord      Ë«×Ö
'OUTPUT------------------------------------------
    '·µ»ØÖµ     DWord²ÎÊýµÄ¸ßλ×Ö
'Last updated by Liu Qi 2004-3-20.
m_lSharedLong = DWord
fastHiWord = m_aiIntsInLong(1)

End Function

Public Function fastLoWord(ByVal DWord As Long) As Integer
'È¡Ò»¸öË«×Ö£¨DWord£©µÄµÍλ×Ö
'INPUT-------------------------------------------
    'DWord      Ë«×Ö
'OUTPUT------------------------------------------
    '·µ»ØÖµ     DWord²ÎÊýµÄµÍλ×Ö
'Last updated by Liu Qi 2004-3-20.
m_lSharedLong = DWord
fastLoWord = m_aiIntsInLong(0)

End Function

--------------------------------------------------------------

---------------------------modShiftBitByte.bas---------------]

Option Explicit

'ÕâÊÇΪ×Ö½ÚÀàÐͱäÁ¿Ìṩ¿ìËÙµÄÒÆλ²Ù×÷µÄÄ£¿é£¬¿ÉÒÔʹÓñ¾Ä£¿éÖеĿì±íʵÏÖ¸ßËÙµÄÒÆλÔËËã
'ÕâÊÇ´¿VBʵÏֵģ¬²»ÐèÒªÈκÎDLL

'ÐèÒª BitEx.Bas

'Áõçù£¬×÷ÓÚ2005-1-26

Const MAX_BYTE = &HFF&

'ÏÂÃæÊÇÒÆλ±í
Public g_aShLB() As Byte '×Ö½Ú×óÒƵĿì±í£¬µÚ1άÊÇ´ýÒÆλµÄ×Ö½Ú£¬µÚ2άÊÇÒÆλλÊý
Public g_aShRB() As Byte '×Ö½ÚÓÒÒƵĿì±í£¬µÚ1άÊÇ´ýÒÆλµÄ×Ö½Ú£¬µÚ2άÊÇÒÆλλÊý
'------------------------------------------------------------------------------------

Public Function IsInitialized() As Boolean
'ÅжÏÊÇ·ñÒѾ­³õʼ»¯¹ýÒÆλ±íµÄº¯Êý

On Error GoTo hanlder

g_aShLB(1, 1) = g_aShLB(1, 1)
IsInitialized = True 'û³ö´í£¬ËµÃ÷³õʼ»¯¹ýÁË
Exit Function

hanlder:
    IsInitialized = False '³ö´í˵Ã÷»¹Ã»Óгõʼ»¯
End Function

Public Sub ShiftBitByteInit()
'³õʼ»¯ÒÆλ±í

If IsInitialized Then Exit Sub ' Èç¹ûÒѾ­³õʼ»¯¹ýÁË£¬²»±ØÔÙ³õʼ»¯ÁË

'·ÖÅä¿Õ¼ä
ReDim g_aShLB(0 To MAX_BYTE, 1 To 7) As Byte '×óÒƱí
ReDim g_aShRB(0 To MAX_BYTE, 1 To 7) As Byte 'ÓÒÒƱí

Dim i As Long, j As Long

For i = 0 To MAX_BYTE
    For j = 1 To 7
        g_aShLB(i, j) = ShLB(i, j)
        g_aShRB(i, j) = ShRB(i, j)
    Next j
Next i
End Sub

Public Sub DestoryShiftBitByteTable()
'Ïú»Ù×Ö½ÚÀàÐ͵ÄÒÆλ±í£¬ÒÔÊÍ·ÅÄÚ´æ
ReDim g_aShLB(0)
Erase g_aShLB

ReDim g_aShRB(0)
Erase g_aShRB

End Sub
-------------------------------------------------------

---------------------------SafeArray.bas--------------------------

'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'
' You are entitled to license free distribution of any application
'   that uses this file if you own a copy of the book, or if you
'   have obtained the file from a source approved by the author. You
'   may redistribute this file only with express written permission
'   of the author.
'
' This file depends on:
'   References:£¨²»ÔÙÐèÒªVBoostTypes6.olb£¬¿ÉÖ±½ÓÔÚÈκεط½Ê¹Óã©
'     VBoostTypes6.olb (VBoost Object Types (6.0))'
'   Files:
'     None
'   Minimal VBoost conditionals:
'     None
'   Conditional Compilation Values:
'     None
'
' This file is discussed in Chapter 2.
'***************************************************************

'***************************************************************
'˵Ã÷£ºÕâ¸öÄ£¿éÊÇ Matthew J. Curland µÄ×÷Æ·£¬ÎÒ¸ù¾Ý×Ô¼ºµÄʵ¼ÊÐèÒª
'×÷ÁËһЩ΢СµÄ¸Ä¶¯£¨²»ÔÙÐèÒªVBoostTypes6.olb£¬¿ÉÖ±½ÓÔÚÈκεط½Ê¹Óã©
'£¬Ìí¼ÓÁËÖÐÎĵÄ×¢ÊÍ¡£
'
'ʹÓÃÕâ¸öÄ£¿é£¬¿ÉÒÔÏñ C ÓïÑÔÒ»ÑùÓÃÊý×é·ÃÎÊÈÎÒâµÄÄÚ´æλÖÃ

'×÷ÕߣºÁõçù £¬2005-1-11
'¸öÈËÖ÷Ò³£ºhttp://LQweb.crcoo.com
'e-Mail£ºliuqi5521@hotmail.com
'***************************************************************
Option Explicit

Public Type SafeArray1d '1άÊý×éµÄ SafeArray ¶¨Òå
    cDims As Integer 'άÊý
    fFeatures As Integer '±êÖ¾
    cbElements As Long 'µ¥¸öÔªËصÄ×Ö½ÚÊý
    clocks As Long 'Ëø¶¨¼ÆÊý
    pvData As Long 'Ö¸ÏòÊý×éÔªËصÄÖ¸Õë
    cElements As Long 'ά¶¨Ò壬¸ÃάµÄÔªËظöÊý
    Lbound As Long '¸ÃάµÄϽç
End Type

Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)

Public Declare Function VarPtrArray Lib "msvbvm60.dll" _
Alias "VarPtr" (ptr() As Any) As Long
Public Const FADF_AUTO = &H1
Public Const FADF_FIXEDSIZE = &H10

Public Sub ShareMemoryViaArray(ByVal ArrayPtr As Long, _
ByVal MemPtr As Long, SA1D As SafeArray1d, _
ByVal ElemByteLen As Long, ByVal ElemCount As Long)
'INPUT---------------------------------------------------------------------
'ByVal ArrayPtr As Long Ö¸ÏòÊý×é±äÁ¿µÄÖ¸Õ룬Óà VarPtrArray(Êý×éÃû)»ñÈ¡
'ByVal MemPtr As Long  Ö¸ÏòÒª½èÓõÄÄÚ´æ¿éµÄÖ¸Õë(¾ÍÊÇÆðʼµØÖ·)¡£
'SA1D As SafeArray1d  ͨ¹ýÒýÓô«µÝÀ´µÄSafeArray1d½á¹¹±äÁ¿
'ByVal ElemByteLen As Long Ö¸³öÊý×éҪʹÓõÄÔªËØ´óС
'ByVal ElemCount As Long Ö¸³öÊý×éҪʹÓõÄÔªËظöÊý
'
'OUTPUT--------------------------------------------------------------------
'N/A
'Ç°Ìõ¼þ--------------------------------------------------------------------
'ÒªÇóÊý×é±äÁ¿±ØÐëÊÇδ·ÖÅäµÄ
'ºóÌõ¼þ--------------------------------------------------------------------
'N/A
    With SA1D
        'cbElements is optional because this is a 1 element array,
        'so cbElements is not needed to walk the array.  If Erase
        'is called on an array with .cbElements = 0, VB will still
        'free all pointer types, but non-pointer types will not get
        'zeroed out.  Note that the compiler calculates the length
        'of a structure at compile time, so LenB(MyStruct(0)) is
        'valid regardless of whether or not MyStruct is actually allocated.
        .cbElements = ElemByteLen 'ÔªËØ´óС
        .cDims = 1 'άÊý
        'This means that if the
        'array goes out of scope, then the pointed
        'to memory will be cleaned, but no attempt
        'will be made to free the array pointer
        'or descriptor.
        .fFeatures = FADF_AUTO Or FADF_FIXEDSIZE 'ÌØÕ÷
        .pvData = MemPtr 'Ö¸ÏòÒª½èÓõÄÄÚ´æ¿é
        .cElements = ElemCount 'ÔªËظöÊý
        .Lbound = 0 ' Ͻç
    End With
    '°Ñ SafeArray ½á¹¹µÄÊ×µØÖ·¸³¸øÊý×é±äÁ¿
    CopyMemory ByVal ArrayPtr, VarPtr(SA1D), 4
End Sub

Public Sub UnshareMemory(ByVal ArrayPtr As Long)
'INPUT---------------------------------------------------------------------
'ByVal ArrayPtr As Long Ö¸ÏòÊý×é±äÁ¿µÄÖ¸Õ룬Óà VarPtrArray(Êý×éÃû)»ñÈ¡
'
'OUTPUT--------------------------------------------------------------------
'N/A
'Ç°Ìõ¼þ--------------------------------------------------------------------
'ÒªÇóÊý×é±äÁ¿±ØÐëÊÇÓÃShareMemoryViaArray·ÖÅäµÄ£¬²»ÄÜÓÃÓÚVB·ÖÅäµÄÊý×é
'ºóÌõ¼þ--------------------------------------------------------------------
'N/A
    ''°ÑÊý×é±äÁ¿µÄÖµÖÃΪ0
    ZeroMemory ByVal ArrayPtr, 4
End Sub


------------------------------------------------------------------


------------------------------ ShiftBitInt16.bas -----------------

Option Explicit

'ÕâÊÇΪIntegerÀàÐͱäÁ¿Ìṩ³¬¸ßËÙÒÆλÔËËãµÄÄ£¿é£¬ÓÉÓÚIntegerÀàÐ͵ķ¶Î§½Ï´ó£¬±È½ÏÕ¼Äڴ棬ËùÒÔ
'ÓõÄÊǶ¯Ì¬±í£¬ÓÃʱ·ÖÅ䣬ÓÃÍê¿ÉÒÔ¾¡¿ìÏú»Ù¡££¨»¹ÓиöºÃ´¦£¬¿ÉÒÔ±ÜÃâÍü¼Ç³õʼ»¯Êý×飩

'ÕâÊÇ´¿VB°æµÄ£¬ÓëÔ­À´ÄǸöÐèÒªDLLµÄ°æ±¾Ïà±È£¬Ê¹Óøü·½±ã¡£

'Áõçù£¬×÷ÓÚ2005-1-26

'ÐèÒª£ºBitEx10.Bas SafeArray.Bas modShiftBitByte.Bas

'ÁíÍ⣺ʹÓÃÕâÁ½¸ö¿ì±íÒ»¶¨Òª×¢ÒâÒ»µã£¬Òª×öÒ»¸ö³¤ÕûÐÎÎÞ·ûºÅÀ©Õ¹Ö®ºóÔÙ²é±í£¬²»È»»á³ö´í£¬ÏñÕâÑù£º
'g_aShL16(SomeInt and &HFFFF&,1)
'Ϊʲô£¿¶Ô×î¸ßλΪ1µÄInteger,VB»á°ÑËü½âÊÍΪһ¸ö¸ºÖµ,×öÁ˳¤ÕûÐÎÀ©Õ¹£¬VB²Å»á°ÑËüÀí½âΪһ¸öÕýÖµ,
'ÓÉÓÚÊý×éÎÞ·¨½ÓÊܸºÖµË÷Òý£¬ËùÒÔÎÒÃÇÊÇÓÃIntegerµÄÎÞ·ûºÅÖµÀ´Ôì±í
'ËùÒÔ˵£¬²é±íµÄʱºòµ±È»ÒªÓÃIntegerµÄÎÞ·ûºÅÖµÀ´²é±í

'ÕûÐαäÁ¿µÄÒÆλ±í----------------------------------------------------------------------------------------
Public g_aShL16() As Integer
Public g_aShR16() As Integer
'--------------------------------------------------------------------------------------------------------

Public Const MAX_UINT16 = &HFFFF& 'max unsigned int16,×¢Ò⣺ÕâÊÇÒ»¸öÓÃLong´æ´¢µÄ65535,ÎÞ·ûºÅ×ÖµÄ×î´óÖµ

Private m_iSharedInt As Integer 'µØÖ·¿Õ¼äÒª±»¹²ÏíµÄ³¤ÕûÐÎ
Private m_aBytesInInt() As Byte 'Òª¹²Ïí³¤ÕûÐεØÖ·¿Õ¼äµÄ×Ö½ÚÊý×é
Private m_SA1D As SafeArray1d '°²È«Êý×é½á¹¹


Public Sub InitShL16Table() '³õʼ»¯×óÒÆ±í£¬£¨ÎªÉ¶ºÍÓÒÒƱí·Ö¿ªÄØ£¿°´Ðè·ÖÅ䣬ʡÄڴ棬ÐèÒªÄĸö·ÖÅäÄĸö¡££©
Dim i As Long, j As Long

If ShiftLeftTableIsInitialized Then Exit Sub 'Èç¹û×óÒƱíÒѾ­³õʼ»¯¹ýÁË£¬¾ÍÍ˳ö

ShiftBitByteInit '³õʼ»¯×Ö½ÚÀàÐ͵ÄÒÆλ±í
modSafeArray.ShareMemoryViaArray VarPtrArray(m_aBytesInInt), VarPtr(m_iSharedInt), m_SA1D, _
1, 2 '¹²ÏíÄÚ´æ
If VarPtr(m_iSharedInt) <> VarPtr(m_aBytesInInt(0)) Then MsgBox "¹²ÏíÄÚ´æʧ°Ü!"

ReDim g_aShL16(0 To MAX_UINT16, 1 To 15) 'ΪÒÆλ±í·ÖÅä¿Õ¼ä£¬0-ffff,1-15
For i = 0 To MAX_UINT16
    For j = 1 To 15
        g_aShL16(i, j) = ShL16_Internal(LoWord(i), j)
    Next j
Next i

UnshareMemory VarPtrArray(m_aBytesInInt) 'È¡Ïû¹²ÏíµÄÄÚ´æ
End Sub

Public Sub DestroyShL16Table() 'Ïú»Ù×óÒÆ±í£¬ÊÍ·ÅÄÚ´æ
ReDim g_aShL16(0)
Erase g_aShL16
End Sub


Public Sub InitShR16Table() '³õʼ»¯ÓÒÒƱí
Dim i As Long, j As Long

If ShiftRightTableIsInitialized Then Exit Sub 'Èç¹ûÓÒÒƱíÒѾ­³õʼ»¯¹ýÁË£¬ÄÇôÍ˳ö

ShiftBitByteInit '³õʼ»¯×Ö½ÚÀàÐ͵ÄÒÆλ±í
modSafeArray.ShareMemoryViaArray VarPtrArray(m_aBytesInInt), VarPtr(m_iSharedInt), m_SA1D, _
1, 2 '¹²ÏíÄÚ´æ
If VarPtr(m_iSharedInt) <> VarPtr(m_aBytesInInt(0)) Then MsgBox "¹²ÏíÄÚ´æʧ°Ü!"


ReDim g_aShR16(0 To MAX_UINT16, 1 To 15) 'ΪÒÆλ±í·ÖÅä¿Õ¼ä£¬0-ffff,1-15
For i = 0 To MAX_UINT16
    For j = 1 To 15
        g_aShR16(i, j) = ShR16_Internal(LoWord(i), j)
    Next j
Next i

UnshareMemory VarPtrArray(m_aBytesInInt) 'È¡Ïû¹²ÏíµÄÄÚ´æ
End Sub

Public Sub DestroyShR16Table() 'Ïú»ÙÓÒÒÆ±í£¬ÊÍ·ÅÄÚ´æ
ReDim g_aShR16(0)
Erase g_aShR16
End Sub


Public Function ShL16_Internal(ByVal Word As Integer, Optional ByVal BitNum As Long = 1) As Integer
'×ÖµÄ×óÒƺ¯Êý£¬ËÙ¶ÈÒ»°ã,½ö¹©ÄÚ²¿Ê¹ÓÃ,ÓÃÀ´³õʼ»¯ÒÆλ±í»¹¿ÉÒÔ£¬ÓÃÔÚʵ¼ÊÔËËãÖоͺÁÎÞÓÅÊÆ¿ÉÑÔÁË¡£
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û

m_iSharedInt = Word '°Ñ´ýÒÆλµÄÖµ¸³¸ø±»¹²ÏíµÄÕûÐÎ

If BitNum = 8 Then 'Èç¹ûµÈÓÚ8£¬Ö±½Ó°ÑµÍ×Ö½Ú°áµ½¸ß×Ö½ÚÈ¥¾ÍOKÁË
    m_aBytesInInt(1) = m_aBytesInInt(0)
    m_aBytesInInt(0) = 0
ElseIf BitNum > 8 Then 'Èç¹û´óÓÚ8£¬ÄÇô¾ÍÏÈÒÆ8룬ÔÙÒÆʣϵÄ
    m_aBytesInInt(1) = m_aBytesInInt(0)
    m_aBytesInInt(0) = 0
    m_aBytesInInt(1) = g_aShLB(m_aBytesInInt(1), BitNum - 8)
Else 'СÓÚ8

    '°Ñ¸ß×Ö½Ú×óÒÆ£¬²¢°ÑµÍ×Ö½ÚÏàÓ¦µÄλÒƵ½¸ß×Ö½ÚÉÏ
    m_aBytesInInt(1) = g_aShLB(m_aBytesInInt(1), BitNum) Or g_aShRB(m_aBytesInInt(0), 8 - BitNum)
    'µÍ×Ö½Ú×óÒÆ
    m_aBytesInInt(0) = g_aShLB(m_aBytesInInt(0), BitNum)

End If

'·µ»Ø½á¹û
ShL16_Internal = m_iSharedInt

End Function
Private Function ShR16_Internal(ByVal Word As Integer, Optional ByVal BitNum As Long = 1) As Integer
'×ÖµÄÓÒÒƺ¯Êý,½ö¹©ÄÚ²¿Ê¹ÓÃ
'INPUT-------------------------------
    'Word Ô´²Ù×÷Êý
    'BitsNum ÒÆλµÄλÊý
'OUTPUT------------------------------
     '·µ»ØÖµ  ÒÆλ½á¹û
    
m_iSharedInt = Word '°Ñ´ýÒÆλµÄÖµ¸³¸ø±»¹²ÏíµÄÕûÐÎ


If BitNum = 8 Then 'Èç¹ûÒÆλλÊýµÈÓÚ8£¬ÓÒÒÆ8λ¾ÍµÈ¼ÛÓÚÖ±½Ó°Ñ¸ß×Ö½Ú°áµ½µÍ×Ö½Ú,¸ß×Ö½ÚÇåÁã
    m_aBytesInInt(0) = m_aBytesInInt(1)
    m_aBytesInInt(1) = 0
ElseIf BitNum > 8 Then 'Èç¹ûÒÆλλÊý´óÓÚ8£¬ÄÇôÏÈÓÒÒÆ8룬ÔڰѵÍ×Ö½ÚÓÒÒÆʣϵÄλÊý
    m_aBytesInInt(0) = m_aBytesInInt(1)
    m_aBytesInInt(1) = 0
    m_aBytesInInt(0) = g_aShRB(m_aBytesInInt(0), BitNum - 8)
Else 'СÓÚ8
    'µÍ×Ö½ÚÓÒÒÆ£¬²¢°Ñ¸ß×Ö½ÚÏàÓ¦µÄλÒƶ¯µ½µÍ×Ö½Ú
    m_aBytesInInt(0) = g_aShRB(m_aBytesInInt(0), BitNum) Or g_aShLB(m_aBytesInInt(1), 8 - BitNum)
    '¸ß×Ö½ÚÓÒÒÆ
    m_aBytesInInt(1) = g_aShRB(m_aBytesInInt(1), BitNum)
   
End If

ShR16_Internal = m_iSharedInt
End Function


Private Function ShiftLeftTableIsInitialized() As Boolean
'ÅжÏ×óÒƱíÊÇ·ñÒѾ­³õʼ»¯¹ýµÄº¯Êý£¬³õʼ»¯¹ý·µ»ØÕ棬ûÓгõʼ»¯·µ»Ø¼Ù

On Error GoTo handler

g_aShL16(1, 1) = g_aShL16(1, 1)
ShiftLeftTableIsInitialized = True
Exit Function


handler:
    ShiftLeftTableIsInitialized = False

End Function

Private Function ShiftRightTableIsInitialized() As Boolean
'ÅжÏÓÒÒƱíÊÇ·ñÒѾ­³õʼ»¯¹ýµÄº¯Êý£¬³õʼ»¯¹ý·µ»ØÕ棬·ñÔò·µ»Ø¼Ù
On Error GoTo handler

g_aShR16(1, 1) = g_aShR16(1, 1)
ShiftRightTableIsInitialized = True
Exit Function

handler:
    ShiftRightTableIsInitialized = False

End Function
-----------------------------------------------------------------

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00188