導航:首頁 > 文件目錄 > vb文件路徑句柄

vb文件路徑句柄

發布時間:2024-09-05 23:58:59

⑴ 求VB取句柄對應全路徑文件名模塊

這個「句柄」指的是實例句柄hInstance吧...

用這個API:

Declare Function GetMoleFileName Lib "kernel32" Alias "GetMoleFileNameA" (ByVal hMole As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long

返回值Long,如執行成功,返回復制到lpFileName的實際字元數量;失敗時會返回0,並設置LastError
參數
hMole 一個模塊的句柄。可以是一個DLL模塊,或者是一個應用程序的實例句柄
lpFileName 指定一個字串緩沖區,要在其中容納文件的用NULL字元中止的路徑名,hMole模塊就是從這個文件裝載進來的
nSize 裝載到緩沖區lpFileName的最大字元數量

例如:

Dim msg As String * 1024
msg = ""
GetMoleFileName App.hInstance, msg, 1024
MsgBox msg

則得到當前運行的路徑+文件名.~
----------------------------------------------------------------------------------------

終於完成了- -```

用到這幾個API:

GetWindowThreadProcessId()
-- 根據hWnd獲取進程ID(PID)
OpenProcess()
--打開進程..返回值是進程句柄.
CloseHandle()
EnumProcessMoles()
--枚舉進程模塊(第一個模塊就是第一個模塊就是創建此進程的主exe程序
GetMoleFileNameExA()
取得模塊的文件名.~

API函數及常量聲明如下(去MSDN中找...API瀏覽器里好多都沒有的......):

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function EnumProcessMoles Lib "psapi.dll" (ByVal hProcess As Long, ByRef lphMole As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function GetMoleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long, ByVal hMole As Long, ByVal MoleName As String, ByVal nSize As Long) As Long
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED + SYNCHRONIZE + &HFFF

下面這個函數的返回值就是根據hWnd取得的文件名:

Private Function getName(ByVal hHWND As Long) As String
Dim pID As Long
Dim hProcess As Long
Dim Moles(200) As Long
Dim nSize As Integer
Dim lRet As Long
Dim MoleName As String
Dim cb As Long
GetWindowThreadProcessId hHWND, pID
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pID)
lRet = EnumProcessMoles(hProcess, Moles(1), 200, cb)
If lRet <> 0 Then
MoleName = Space(255)
nSize = 255
lRet = GetMoleFileNameExA(hProcess, Moles(1), MoleName, nSize)
End If
CloseHandle hProcess
End Function

..........Q:531623560

閱讀全文

與vb文件路徑句柄相關的資料

熱點內容
ae信號干擾教程 瀏覽:548
電腦之前刪掉的文件怎麼找 瀏覽:805
索尼z1刷什麼系統升級 瀏覽:466
自創字體怎麼編程序 瀏覽:381
成都的蘋果售後服務電話號碼 瀏覽:698
文件放筆記本哪個盤 瀏覽:745
starbound星球文件格式 瀏覽:137
javathis和super 瀏覽:782
iphone5左上角翹屏 瀏覽:863
自製音樂節奏燈教程 瀏覽:963
java獲取jar文件路徑 瀏覽:227
手機test文件可刪除么 瀏覽:719
升win10卡在34 瀏覽:962
sfc文件 瀏覽:262
公牛蘋果數據線2a什麼意思 瀏覽:489
勒索蠕蟲檢測工具 瀏覽:68
蘋果手錶固件描述文件下載 瀏覽:330
android獲取sd卡視頻文件 瀏覽:949
蘋果手機設置通用網路設置 瀏覽:83
md298zpa是什麼版本 瀏覽:317

友情鏈接