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

热点内容
excel如何合并两格数据 浏览:424
求一个好看的qq分组 浏览:850
intsum编程是什么意思 浏览:782
没有大数据如何贷款 浏览:29
衣服补丁是哪个文件 浏览:234
docker映射路径文件 浏览:280
多文件格式支持多级权限管控 浏览:907
什么网站能翻译中文 浏览:677
查看win10数字激活 浏览:324
车商悦怎么下载app 浏览:797
有人微信骚扰我老婆 浏览:47
dxe文件数据如何导入cad 浏览:988
vb字体标准还原代码 浏览:394
乐高机器人编程属于什么类 浏览:102
iphone4s固件怎么区分 浏览:953
win10用不了钉钉 浏览:202
xp系统硬盘安装win10系统安装教程 浏览:616
万象会员资料保存哪个文件 浏览:800
json文件的读取数据 浏览:463
js字符串中加法 浏览:685

友情链接