标题: [问题求助] [已解决]注册dynwrap.dll成功但仍旧无法创建对象:dynamicwrapper [打印本页]
作者: tonyabbs 时间: 2017-10-7 22:02 标题: [已解决]注册dynwrap.dll成功但仍旧无法创建对象:dynamicwrapper
本帖最后由 tonyabbs 于 2017-10-8 20:27 编辑
下面这段代码,试图通过dynwrap.dll去调用windows api,但regsvr32 dynwrap.dll 注册成功后,仍旧出现 无法创建对象:dynamicwrapper- '取前景窗体标题
- GetForeWindowCaption
- Sub GetForeWindowCaption()
- Const WM_GETTEXT = &HD
- Set Wrap = CreateObject("DynamicWrapper")
- Wrap.Register "USER32.DLL", "GetForegroundWindow", "f=s", "r=l"
- Wrap.Register "USER32.DLL", "SendMessage", "i=lllr", "f=s", "r=l"
- Title = Space(100)
- res = Wrap.SendMessage(Wrap.GetForegroundWindow(), WM_GETTEXT , 100, Title)
- GetForeWindowCaption = Title
- End Sub
- 'MsgBox GetForeWindowCaption
复制代码
作者: yu2n 时间: 2017-10-7 23:29
FYI
VBS无法创建object
http://www.bathome.net/thread-33272-1-2.html#pid158900
作者: yu2n 时间: 2017-10-8 00:00
- CommandModeX64("VBS 取前景窗体标题")
- WScript.Sleep(2000)
- WScript.Echo("前景窗体标题为:" & vbCrLf & GetForeWindowCaption())
-
- '************************************************************************
- '取前景窗体标题
- '************************************************************************
- Function GetForeWindowCaption()
- Const WM_GETTEXT = &HD
- Set Wrap = CreateObject("DynamicWrapper")
- Wrap.Register "USER32.DLL", "GetForegroundWindow", "f=s", "r=l"
- Wrap.Register "USER32.DLL", "SendMessage", "i=lllr", "f=s", "r=l"
- Title = Space(100)
- res = Wrap.SendMessage(Wrap.GetForegroundWindow(), WM_GETTEXT , 100, Title)
- GetForeWindowCaption = Title
- End Function
-
- '************************************************************************
- '以命令提示符环境运行(保留参数X64)
- '************************************************************************
- Sub CommandModeX64(ByVal sTitle)
- Dim objFSO, objWSO, strApp, strCommand, objItem, strArgs
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objWSO = CreateObject("WScript.Shell")
- strApp = objWSO.ExpandenVironmentStrings("%windir%\SysWOW64\cscript.exe")
- If Not objFSO.FileExists(strApp) Then strApp = objWSO.ExpandenVironmentStrings("%windir%\System32\cscript.exe")
- If InStr(1, WScript.FullName, strApp, vbTextCompare) > 0 Then Exit Sub
- strCommand = "%Comspec% /c title " & sTitle & " & " & strApp & " //NoLogo """ & WScript.ScriptFullName & """"
- For Each objItem In WScript.Arguments
- strArgs = strArgs & " " & """" & objItem & """"
- Next
- objWSO.Run strCommand & strArgs & " & pause", 1, False
- WScript.Quit
- End Sub
复制代码
Win10 x64 测试结果如下:- 前景窗体标题为:
- C:\Users\Yu2n\Desktop\0.vbs - Notepad++
- 请按任意键继续. . .
复制代码
作者: tonyabbs 时间: 2017-10-8 20:27
"改用 C:\Windows\SysWOW64\wscript.exe 来运行 vbs 就好了" 谢谢!
作者: tonyabbs 时间: 2017-10-8 20:34
@yu2n 3楼代码在我这里win10 X64 运行的结果是
前景窗体标题为:
VBS取前景窗口标题
请按任意键继续...
作者: 老刘1号 时间: 2017-10-8 20:38
换DWX呗,别就抱着DW不放啊
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |