导航:首页 > 文件目录 > 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文件路径句柄相关的资料

热点内容
sitemap代码 浏览:108
数据库的使用过程 浏览:761
excel怎么用高级筛选数据 浏览:438
js中怎么设置css样式 浏览:724
商业网站模板下载 浏览:548
c怎么调用数据库 浏览:438
vue封装js方法 浏览:705
电脑文件夹蓝色的 浏览:713
tp无线网设置管理密码忘记了怎么办 浏览:386
ipa里资源文件 浏览:110
苹果的文件管理在那里 浏览:633
qq浏览器文件如何发到qq 浏览:736
百度地图加载多个点代码 浏览:146
数据横向复制如何纵向粘贴 浏览:433
2020cab画图数据怎么调 浏览:534
teamview12linux 浏览:175
java编辑word文件 浏览:149
类似scihub的网站有哪些 浏览:398
ios哪里找小众app 浏览:377
毒霸新闻弹窗是哪个文件 浏览:331

友情链接