[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程批处理在线视频分享
返回列表 发帖

[问题求助] [已解决]注册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
复制代码

『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

  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. 请按任意键继续. . .
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

"改用 C:\Windows\SysWOW64\wscript.exe 来运行 vbs 就好了" 谢谢!

TOP

@yu2n 3楼代码在我这里win10 X64 运行的结果是
前景窗体标题为:
VBS取前景窗口标题
请按任意键继续...

TOP

换DWX呗,别就抱着DW不放啊
老刘的小站:http://lbcpc.3vcm.net

TOP

返回列表