     6.     	141 

     6.        

          Visual Basic   ,  
        Windows,   
      Windows (API). 
     ,     , 
_ o6ecn^4ji.JVJsuaL.Basic,    
  Windows (DLL)  .  Windows API. 
    ,   DLL   ,   
     ,  j-fejiMeeT . 
       ,   DLL    
  Visual Basic,      
  DLL   . 

    6.1.  DLL 

     DLL     , 
  Visual Basic   .   
"" ^.'    ,   
  . DLL      ;  
           
.    ~~,   
        DLL. 

    6.1.1.   DLL 

      DLL : 
       3afla4i^j^o^iej4eBO3Mo>KHopeujHTb,cpeflCTBa^Visual Basic; 
        .   DLL   
,   Visual Basic.  ,     
 ,   DLL    DLL  Visual Basic; 
         . DLL    
-,_\\,   DLL.   
 . 

    6.1.2.  Windows API 

    Windows    DLL,     Visual 
Basic.  DLL     Windows (Windows API). 
    32-    Windows (Windows 95  Windows NT) 
    DLL: User32, GDI32  Kernel32.  DLL  
    Windows API: 
    User32	  User32.dll  ,    
, ,     . ,  
FlashWindow  User32.dll   . 
    GDI32	 GDI32.dll    . 


    142  DLL 

    Kernel32	 Kernel32.dll    . 
-1 ,  Kernel32.dll    GetWindowsDirectory, | 
     Windows. 
         DLL Windows 95  Windows NT    
      Visual Basic. 

    6.1.3.  API Viewer 

         Windows API   
  API Viewer (Apiload.exe),   Visual Basic. 
      ^ API, ,   Win32api.txt, API 
Viewer       ,    Declare  
  Windows API.  APi Viewer      
       Visual Basic. 

    <| Text API Viewei    C:\VBSWINAPI4Wm32api.tKl 
    File   Edit API Type: 
    Help 
    Line Hem 
    zJ 
    Available Items: 
    AbortDoc AbortPath AbortPrinter AbortSysternShutdown AccessCheck		?l 
    Add        | 
    iAccess	CheckAndAuditAlarm	^^ 
    1 f 
    ActivateKeyboardLayout AddAccessAllowedAce 
    Selected Items: 
    d 
    Declare Function AccessCheckAnd Audit Alarm Lib "advapi32.dll" Alias	*[ 
"AccessCheckAndAuditAlarmA" (ByVal SubsystemName As String, Handleld As Any, 
ByVal ObjectTypeName As String, ByVal ObjectName As String,                   
i SecurityDescriptor As SECURITY J)ESCRIPTOR,Bj/Val DesiredAccess As Long, 
GenericMapping As GENERIC_MAPPIWG, ByVal ObjectCreation As Long, GrantedAccess 
As Long, ByVal AccessStatus As Long, ByVal pfGenerateQnCloI As Long) As Long 
    Remove 
    Copy 
    d 
    Search by typing directly into the list box.,, 

    . 6.1.  API Viewer. 


    6.1.4.      

         DLL    
    (.mdb),       
(.txt). API Vie/         API, 
  .      Jet.   
  .mdb  ;:~      API Viewer. 


     6.      143 

    6.1.5.  DLL  Visual Basic 

       DLL    : 
    1.    Declare  Visual Basic,   
 . 
    2.   DLL      .  
  . 

    6.2.   DLL 

     DLL        Visual 
Basic , ,      ,  
 .    Visual Basic 
,      .   
 DLL  Declare    _0!1 , 
    . 
     DLL    ,  DLL  Public  
        Visual Basic.  
    DLL    ,  
     Private. 
      Declare: 

    [Public|Private] Declare Sub  Lib "_" [Alias 
"_"] [(_)] 

     
    
    [Public|Private] Declare Function  Lib "_" [Alias 
"_"] [(_)] [As ] 

      Declare: 

    	 

    	 ,   . 

    Lib " "	 ,    .  
  DLL,   . : Function 
Declare AddNum Lib "c:\add.dll" (ByVal a as long) As long.     
DLL  , DLL       PATH. 
    _	,  .    
    ,   
.         . 
    Alias "_"	 DLL  ,   
   Visual Basic,     
     Alias.           
Alias                 . 
         API AccessCheckAndAuditAlarm: 
    '          General   Declarations        

. Declare   Function  AccessCheckAndAuditAlarm _ 

    Lib   "advapi32.dll"   Alias   "AccessCheckAndAuditAlarmA" 



    144   DLL 


    (ByVal SubsystemName As String, Handleld As Any, _ ByVal ObjectTypeName As 
String, ByVal ObjectName As String, _ SecurityDescriptor As SECURITY_DESCRIPTOR, _ 
    ByVal DesiredAccess As Long, GenericMapping As GENERIC_MAPPING, ByVal 
ObjectCreation As Long, GrantedAccess As Long, _ ByVal AccessStatus As Long, _ 
ByVal pfGenerateOnClose As Long) As Long 

    6.2.1.       Visual Basic 

      DLL     ,   , 
    "   .    Declare  DLL 
 VisBasic,         . 
              
  Visual Basic  32- : 

           Visual Basic                   

ByVal <> As String   String  Variant 1 (LPSTR) 1 NULL                                 
ByVal <> As String   VbNullString            | char
ByVal <> As Byte     ,      Byte | Integer
ByVal <> As Long     ,      Long |  Windows       
ByVal <> As Long    ,      Long (hWnd, hDC, hMenu)

    :  16-     int  
  Inte Visual Basic.  32-     int 
   Lo Visual Basic. 


    6.2.2.    

     DLL      ,  
, i 
     Visual Basic     ,   
  
      . 
      ,       
,   ^ Any;   Visual Basic   
  -j        
   . 

    :   Alias,   DLL    
 !    ,    
Any.    \  , ,   
   ,  I  ,   
_^. , , ,  DLL ! 
!1   .     
, -]   DLL      . 


    6.2.3.  ANSI  Unicode 

      Win32 API,      , 
]   :    ANSI  Unicode.  ANSI  
 ]  .  Unicode     
  . 


     6.     	145 

      ANSI  Unicode 

     Visual Basic  5.0      
  Unicode. ,_    Win32 API  
  ANSI  API.    DLL Visual Basic 
     ANSI.     DLL 
Visual Basic     Unicode. 
     Windows API     ''  'W  ANSI  Wide 
(Unicode) .    Declare  API Viewer  
    ANSI. 
    ,    Win32 API SetWindowText,  
 : 
    Declare   Function   SetWindowText   Lib   "user32"   Alias   
"SetWindowTextA"   _ (ByVal  hwnd As   Long,   ByVal   IpString  As   String)  
 as   Long 
      Visual Basic  SetWindowText,   
  ANSI , SetWindowTextA. 

    6.3.  DLL 

            ,     
  Visual Basic,     : 

    result  =  AccessCheckAndAuditAlarm(Subsysteml,,   Objectl) 


    :     ,     
     Object Browser. 

       DLL   ,    
.  : 
    	   DLL  ; 
    	           ; 
    	  Visual Basic ,     
  . 
             
   Visual Basic  Windows API. 

    6.3.1.    

      DLL     ,  ^ 
  (0)    (NULL).    
,  o napa ByVal As String    
vbString,     : 

    Declare   Function   FindWindow  Lib   "User32"  _ Alias   "FindWindowA"   
_ (ByVal   IpClassName  As   String,   _ ByVal   IpCaption  As   String)   As  
 Integer 
    re   =   FindWindow   (vbNullString,    "Microsoft  Word") 

    :  Visual Basic  3.0     
  ByVal 0&.   DLL,     
NULL,      As Any,   DLL ,  
   String       Long. 


    146__________________________________________ DLL I 

      Visual Basic 4.0,     String  
   Visual Basic vbNullString. 

    6.3.2.        

    Visual Basic     ,  
32-    ,   ,   
  . 
     , Visual Basic    .   
 DLL ,      .   
  (,     , 
  ),       . 

        

            
  .    ,  
     . 
        ,    Declare  
     ByVal,     : 
    Declare   Function   FlashWindow  Lib   "User32"   _ (ByVal   hwnd  as   
Long,   _ ByVal   blnvert   As   Long)   As   Long 

        

              
 .      , 
   . 
         ByVal  ByRef.  
   , Visual Basic   
  .   ByRef    ,   
  ,     ByRef,  ByVal. 

    6.3.3.    

        Visual Basic   ,   
    .  DLL     Windows 
API     .      Visual 
Basic    ,     
,          . 

         

      DLL      _, 
   Visual Basic  String,   
  ByVa        
   ,   . ,  DLL 
    Visual Basic,   . 

         

    DLL      Visual Basic     
 ,  " .    
    ,      : 


     6.     	147 

          : 

    Dim  FilePath  As   String FilePath  =   String   (255,    0) 

           : 

    Dim  FilePath  As   String   *   255 

    ,   DLL,      
.      "3  
.    ,    , 
  ,     Left,   
 ,    ,  Chr(O). 
    /' 

        

     GetWindowsDirectory      
Windows.      Windows     
 ,       . 
     GetWindowsDirectory   ,   
     .    
,1_^    . NULL  ,   
   Left,     : 

    Declare   Function   GetWindowsDirectory  Lib   "Kernel32"   _ Alias   
"GetWindowsDirectoryA"   _ (ByVal   f   as   String,   ByVal   fLen  as   
Long)   As   Long 
    Sub  Commandl_Click   () 
    Dim  sWinDir  As   String 
    Dim   ILen   As   Long 
    sWinDir   =   String(255,0) 
    ILen   =  GetWindowsDirectory(sWinDir,   Len (sWinDir)) 
    sWinDir   =   Left (sWinDir,    ILen) 
    sWinDir   =   sWinDir   +   "\" 
    MsgBox   "Windows        "   f   sWinDir End   Sub 


    6.4.    DLL 

           DLL,    
       DLL.    
   DLL      
 Visual Basic. 

    6.4.1.    

    DLL      ,  , 
- .       
 .     Windows API    
    . 
    -,     ,  
  DLL,       
 . 


    148    DLL 


       Visual Basic 

    Visual Basic     ,  
  . 
    ,     ,    
   ,     .  
     DLL. 
       ,      
 Visual Basic: 

        
    
        
       
        
    Function Callback'1 (...) End Function 
    Sub Routine! 0 
    /SetCallK..., AddressOf Callbackl) End Sub 
    SetCall1(..., IpCallbackl) 
    { 
    '   
    '  
    Callbackl =lpCallback1 
    } 
    //    //  
    Callbackl (...) 
     Visual Basic 
    DLL 

    . 6.2.    Visual Basic. 


         DLL 

          DLL Visual Basic  
 AddressOf.        
     .	 
             
  ,          
    DLL.    ,  
 Visual Basic         
 . 

    :       
          . 

         Visual Basic    
,     : 
              ; 
            DLL   
 AddressOf. 


     6.     	149 


      

    Windows API   EnumChildWindows,    
-  .   : 

    Declare   Function  EnumChildWindows   Lib   "user32"   Alias 
    "EnumChildWindows"    (ByVal   hWndParent  As   Long, 
    ByVal   IpEnumFunc  As   Long,   ByVal   IParam As   Long)   As   Boolean 

       hWndParent     . 
   IpEnumFunc      . 
    32- ,    . 
        . 

       

       ,     
  Visual Basic: 

    Public Function EnumProc(ByVal hWndChild as Long , _ 
    ByVal IParam As Long) As Boolean '    Snd Function 


     DLL 

       -    
  ,   AddressOf,    
 : 

    EnumChildWindows   forml.hWnd,   AddressOf  EnumProc,    0 


    6.4.2.  - 

         DLL,     
 ,     DLL.  
,   -,      
    .  
-   DLL  ,    
   DLL. 

     - 

        GetWinDir   API GetWindowsDirectory: 

    Public   Function   GetWinDir   ()   As   String 
    sWi-ndir  =   String (255, 0) 
    ILen  =  GetWindowsDirectory   (sWindir,   Len (sWinDir)) 
    sWinDir   =   Left    (sWinDir,    ILen) 
    GetWinDir  =   sWinDir End  Function 

     ,     Windows,   GetWinDir. 

      DLL 

       GetWinDir,     
 API,    Click (): 

    Sub  cmdGetWin_Click   () 
    Msgbox  GetWinDir End  Sub 


    150	   DLL 


    6.4.3.  DLL 

        Windows API,    
    Visual Basic.    
  Windows API SetWindowPos      
" ". 

       Windows API 

     Windows API      BitBIt                                

                
. Extractlcon, Drawlcon,             .         
                                      L Load Icon                              
                                                                               
                 I FindExecufab/e                          
 , -J     .        

                | GetSystemDirectory                  
 Windows.                  P 

GetSystemMetrics                   
      | Microsoft Windows. 

GetTempFileName                       , 
 -i   TEMP.                                        

              | GetWindowPlacement,               
 ,    SetWin dowPlacement             
(),    . SendMessage   
                        Windows   . 
,  LB_SETTABSTOPS     . 
LB_FINDSTRING     ,    
.      .        | 

BringWindowToTop,                    . 

SetActiveWindow DragAcceptFiles, DragFinish      
drag-and-rdrop.                

I FindWindow, ShowWindow    , 
      ^  . 

GetActiveWindow, IsWindow ,     
1  . 

GetWindowText                      
      ,   . 

      SetWindowsPos 

     SetWindowPos API   ( ),    
      . 
         SetWindowPos,   
 .   API Viewer    
Win32api.txt    HWND_TOPMOST, SWP_NOSIZE  SWP_NOMOVE. 
       SetWindowPos    " 
" . . 


     6.      151 


    6.4.4. :    Windows 

         ,    Microsoft 
Windows,   Windows API GetWindowsDirectory. 
    1.    Standard EXE. 
    2.     ,    . 6.3. 
    3.     . 
    4.   API Viewer   Declare  GetWindowsDirectory. 
    5.   Declare   . 

    '      DLL       
    Declare   Function   GetWindowsDirectory  Lib   "kerne!32"   _ Alias   
"GetWindowsDirectoryA"    (ByVal   IpBuffer  As   String,   _ ByVal   nSize  
As   Long)    As   Long 

    6.     Click   " Windows". 
    7.     ,      Windows 
  : 

    Private   Sub   cmdWinDir_Click() Dim  WinDir  As   String Dim  ReturnSize 
 As   Long 
    WinDir  =   String (255,    0)    '         
    '     API           Windows      
    '        
    ReturnSize   =  GetWindowsDirectory(IpBuffer:=WinDir,   _ nSize:=Len(WinDir)) 
    '              
    WinDir   =   Left(WinDir,    ReturnSize) 
    MsgBox   "  Windows:   "   &  WinDir End   Sub 
     Windows  ll 
     
    Pioject! 
     Windows: C:'\WINDOWS 
    OK 

    . 6..      Windows. 


    6.4.5. :   " " 

         Windows API SetWindowPos   
  ,         . 


    152    DLL 

    1.   . 
    2.     ,    . 6.4.      
    3.     .    /,   ' 
    4.  API Viewer    (HWND_TOPMOST, SWP_NOSIZE 
 SWP_NOMOVE)   Declare   SetWindowPos. 
    5.   Declare   . 

    Declare Function SetWindowPos Lib "user32" _ Alias "SetWindowPos" (ByVal 
hwnd As Long, _ ByVal hWndlnsertAfter As Long, ByVal x As Long, _ ByVal  As 
Long, ByVal ex As Long, ByVal cy As Long, _ ByVal wFlags As Long) As Long 
    Const HWND_TOPMOST = -1 Const HWNDJTOTTOPMOST = -2 Const SWP_NOSIZE = 1 
Const SWP_NOMOVE = 2 Dim flags As Integer 

    6.       " 
"  "  ". 

    Private Sub optNonTopmost_Click() 
    SetWindowPos frmTopmost.hwnd, _ '   - frmTopmost 
    HWND NOTOPMOST, 0, 0, 0, 0, FLAGS End Sub 
    Private Sub optTopmost_Click() SetWindowPos frmTopmost.hwnd, _ 
    HWND_TOPMOST, 0, 0, 0, 0, FLAGS End Sub 
       
    j   I*1 [ ! 
    i  
       "    
     

    . 6.4.  " "  "  ". 

