Board logo

标题: [问题求助] [已解决]注册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
  1. '取前景窗体标题
  2. GetForeWindowCaption
  3. Sub GetForeWindowCaption()
  4. Const WM_GETTEXT = &HD
  5. Set Wrap = CreateObject("DynamicWrapper")
  6. Wrap.Register "USER32.DLL", "GetForegroundWindow", "f=s", "r=l"
  7. Wrap.Register "USER32.DLL", "SendMessage", "i=lllr", "f=s", "r=l"
  8. Title = Space(100)
  9. res = Wrap.SendMessage(Wrap.GetForegroundWindow(), WM_GETTEXT , 100, Title)
  10. GetForeWindowCaption = Title
  11. End Sub
  12. '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

  1. CommandModeX64("VBS 取前景窗体标题")
  2. WScript.Sleep(2000)
  3. WScript.Echo("前景窗体标题为:" & vbCrLf & GetForeWindowCaption())
  4. '************************************************************************
  5. '取前景窗体标题
  6. '************************************************************************
  7. Function GetForeWindowCaption()
  8. Const WM_GETTEXT = &HD
  9. Set Wrap = CreateObject("DynamicWrapper")
  10. Wrap.Register "USER32.DLL", "GetForegroundWindow", "f=s", "r=l"
  11. Wrap.Register "USER32.DLL", "SendMessage", "i=lllr", "f=s", "r=l"
  12. Title = Space(100)
  13. res = Wrap.SendMessage(Wrap.GetForegroundWindow(), WM_GETTEXT , 100, Title)
  14. GetForeWindowCaption = Title
  15. End Function
  16. '************************************************************************
  17. '以命令提示符环境运行(保留参数X64)
  18. '************************************************************************
  19. Sub CommandModeX64(ByVal sTitle)
  20. Dim objFSO, objWSO, strApp, strCommand, objItem, strArgs
  21. Set objFSO = CreateObject("Scripting.FileSystemObject")
  22. Set objWSO = CreateObject("WScript.Shell")
  23. strApp = objWSO.ExpandenVironmentStrings("%windir%\SysWOW64\cscript.exe")
  24. If Not objFSO.FileExists(strApp) Then strApp = objWSO.ExpandenVironmentStrings("%windir%\System32\cscript.exe")
  25. If InStr(1, WScript.FullName, strApp, vbTextCompare) > 0 Then Exit Sub
  26. strCommand = "%Comspec% /c title " & sTitle & " & " & strApp & " //NoLogo """ & WScript.ScriptFullName & """"
  27. For Each objItem In WScript.Arguments
  28. strArgs = strArgs & " " & """" & objItem & """"
  29. Next
  30. objWSO.Run strCommand & strArgs & " & pause", 1, False
  31. WScript.Quit
  32. End Sub
复制代码
Win10 x64 测试结果如下:
  1. 前景窗体标题为:
  2. C:\Users\Yu2n\Desktop\0.vbs - Notepad++
  3. 请按任意键继续. . .
复制代码

作者: 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