文章編號: 242416 - 上次校閱: 2004年7月1日 - 版次: 2.1

如何列舉 NT] 視窗上的 16 位元工作使用 Visual Basic

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

結論

可能有時是列舉所有 Windows NT 系統執行的 16 位元工作所需的時間。如果要執行這項操作使用 VDMEnumProcessWOW] 和 [VDMEnumTaskWOWEx API 函式。[更多資訊資訊] 區段,請依照下列示範如何使用 Visual Basic 中的這些函式。請注意,它也需要使用列舉 16 位元的處理程序呼叫後函式。如果您熟悉的回呼函式從 Visual Basic 中使用請參閱文件本文中參考的部分中提到)。

其他相關資訊

建立範例的步驟

  1. 在 Visual Basic 中啟動新的標準 EXE 專案。預設會建立 Form1。
  2. 在表單上新增一個指令按鈕。
  3. 您可以將表單 AutoReDraw 屬性設為 True。
  4. 從功能表中選擇 專案,然後將新的模組新增至專案。依預設建立 Module1。
  5. 將下列程式碼複製到 Module1 中的 [程式碼] 視窗:
    Option Explicit
    
    Declare Function VDMEnumProcessWOW Lib "VDMDBG.dll" _ 
    (ByVal fp As Long, lparam As Long) As Integer 
    
    Declare Function VDMEnumTaskWOWEx Lib "VDMDBG.dll " _ 
    (dwProcessId As Long, ByVal fp As Long, lparam As Long) As Integer 
    
    Declare Function lstrcpy Lib "kernel32" _ 
    (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long 
    
    Public Function PROCESSENUMPROC _
    (ByVal dwProcessId As Long, ByVal dwAttributes As Long, _
    lpUserDefined As Long) As Boolean
      
        Form1.Cls
        Form1.Print "dwProcessId: " & dwProcessId
        Form1.Print "dwAttributes: " & dwAttributes & vbCrLf 
    ' Pass the Process ID to this next function to enumerate that Process.
        Call VDMEnumTaskWOWEx(ByVal dwProcessId, AddressOf TASKENUMPROCEX, 0)
    
    End Function
    
    Public Function TASKENUMPROCEX _ 
    (ByVal dwThreadId As Long, ByVal hMod16 As Long, _ 
    ByVal hTask16 As Long, ByVal pszModName As Long, _ 
    ByVal pszFileName As Long, lpUserDefined As Long) As Boolean 
    
    ' Print Enumerated task of the 16bit process
        Form1.Print "dwThreadId: " & dwThreadId & vbCrLf & _
        "hMod16: " & hMod16 & vbCrLf & "hTask16: " & hTask16 & vbCrLf & _
        "pszModName: " & PointerToString(pszModName) & vbCrLf & _
        "pszFileName: " & PointerToString(pszFileName) & vbCrLf & _
        "lpUserDefined: " & lpUserDefined & vbCrLf
    ' Return value is false until there are no more tasks to enumerate.  
    End Function
    
    Private Function PointerToString(lPtr As Long) As String
    Dim sTemp As String * 255, Retval As Long
    ' Parse String Values returned from function call. 
    
        Retval = lstrcpy(sTemp, lPtr)
        If (InStr(1, sTemp, Chr(0)) = 0) Then
             PointerToString = ""
        Else
             PointerToString = Left(sTemp, InStr(1, sTemp, Chr(0)) - 1)
        End If
        
    End Function
    					
  6. 將下列程式碼複製到 Form1 的程式碼視窗:
    Private Sub Command1_Click() 
    
    Dim Retval As Long 
    ' Call VDMEnumProcessWOW to beging the enumeration
       Retval = VDMEnumProcessWOW(AddressOf PROCESSENUMPROC, 0)
    
    End Sub 
    					
  7. 儲存 [專案],然後按下 F5 執行專案。列舉處理程序將會列出表單上。

?考

170570? (http://support.microsoft.com/kb/170570/EN-US/ ) 如何建置以傳址在 VB 中的 Windows 訊息處理常式
181578? (http://support.microsoft.com/kb/181578/EN-US/ ) 如何從 C 的 dll 回呼 Visual Basic 函式

這篇文章中的資訊適用於:
  • Microsoft Visual Basic 5.0 Learning Edition?應用於:
    • Microsoft Windows NT 4.0
  • Microsoft Visual Basic 6.0 Learning Edition?應用於:
    • Microsoft Windows NT 4.0
  • Microsoft Visual Basic 5.0 Professional Edition?應用於:
    • Microsoft Windows NT 4.0
  • Microsoft Visual Basic 6.0 Professional Edition?應用於:
    • Microsoft Windows NT 4.0
  • Microsoft Visual Basic 5.0 Enterprise Edition?應用於:
    • Microsoft Windows NT 4.0
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0?應用於:
    • Microsoft Windows NT 4.0
關鍵字:?
kbmt kbapi kbhowto KB242416 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:242416? (http://support.microsoft.com/kb/242416/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。