我知道以下内容:
-
'L'
- 长
'P'
- 指针
'I'
- 整数
'V'
> - Void
我的问题是,当我执行 API 调用时,我无法传递空指针。例如:['L', 'P', 'L'] -> api.call(0, nil, 0) :: ArgumentError: 给定空指针
。我的问题是:是否还有更多我不知道的参数类型以及如何将空指针作为方法参数传递?
背景
我一直在互联网上搜索基于 WinForms 的应用程序的本机 Ruby 编程示例。为了简化编码,我考虑过将 .NET 添加到 Ruby,称为 IronRuby(试图避免使用 wxRuby,同时也是 .NET 的粉丝),但我首先希望能够首先使用纯 Ruby 进行显式编码。
现在,我已经成功地实现了我在 user32.dll 对象中测试过的大多数地址,例如:
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
# or
api = Win32API.new('user32', 'MessageBeep', ['L'], 'I')
..但是我无法在没有 null 的情况下执行 CreateWindow
或 CreateWindowEx
参数。
如果有任何帮助,我已经找到了如何在Python中执行此操作 此处(在 WinAPI 下)。
使用 Win32API:msdn.microsoft.com/en-us/library/ff381397(v=VS.85).aspx
[编辑]
好吧,我想我可能刚刚通过此链接解决了我自己的问题
(警告:可能包含不当内容):[link]
我更多地使用该论坛作为参考,并在我自己周围做了一些摆弄:
createwindow = Win32API.new("user32","CreateWindowEx",'lpplllllllll','l')
showwindow = Win32API.new('user32','ShowWindow',%w(ll),'l')
hWND = createwindow.call((0x00000100|0x00000200),"静态", “窗户标题",((0x4000000|0x80000000|0)|0x02000000),0,0,600,400,0,0,0,0)
showwindow(hWND, 1)
显示“窗口”后发生的唯一事情是崩溃......这可能是由于一些不正确的处理,但是,我很高兴我得到了它去工作(一点点)!只需要弄清楚剩下的...
I know the following:
'L'
- Long
'P'
- Pointer
'I'
- Integer
'V'
- Void
My problem is that I can't pass a null pointer when I perform an API call. E.g.: ['L', 'P', 'L'] -> api.call(0, nil, 0) :: ArgumentError: Null pointer given
. My question is: Are there more parameter types that I don't know about and what should I do to pass a null pointer as a method parameter?
Background
I have been searching the internet for native Ruby programming examples of WinForms-based applications. I have considered the .NET addition to Ruby known as IronRuby for simplicity in coding (trying to avoid wxRuby, and also a .NET fan), but I first want to be able to code explicitly in pure Ruby first.
Now, I have successfully been able to implement most addresses I've tested in the user32.dll object such as:
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
# or
api = Win32API.new('user32', 'MessageBeep', ['L'], 'I')
..but I cannot perform a CreateWindow
Or CreateWindowEx
without null parameters.
If it would be of any help, I have found how to do this in Python here (under WinAPI).
Using Win32API: msdn.microsoft.com/en-us/library/ff381397(v=VS.85).aspx
[EDIT]
Well, I think I may have just solved my own problem with this link
(warning: may contain inappropriate content): [link]
I more used that forum as reference and did a bit of fiddling around my self:
createwindow = Win32API.new("user32","CreateWindowEx",'lpplllllllll','l')
showwindow = Win32API.new('user32','ShowWindow',%w(l l),'l')
hWND = createwindow.call((0x00000100|0x00000200),"static", "Window Title",((0x4000000|0x80000000|0)|0x02000000),0,0,600,400,0,0,0,0)
showwindow(hWND, 1)
The only thing that happens after the 'window' is displayed is crash... and that may have been because of some incorrect handling, but, I am happy that I got it to work(for a little bit)! Just need to figure out the rest...
发布评论
评论(3)
您可能会发现使用新的和改进的 FFI 可以获得更好的效果,而不是使用
Win32API
(我相信它是建立在晦涩且很少使用的DL
模块之上)模块。操作方法如下:
(1) 获取 ffi:
gem install ffi
(2) 然后试试这个:
这似乎比您在编辑中发布的解决方案更容易。
注意:空指针而不是Hwnd使得消息框没有所有者窗口。
Here are some links that may help:
FFI
而不是 Win32APIInstead of using
Win32API
(which I believe is built on top of the obscure and little usedDL
module), you might find better mileage using the new and improvedFFI
module.Here's how:
(1) Get ffi:
gem install ffi
(2) Then try this:
This seems easier than the solution you posted in your edit.
Note: The null pointer instead of Hwnd makes the message box have no owner window.
Here are some links that may help:
FFI
instead of Win32API我没有对此进行测试,因为我不在 Windows 上,但我认为您打算使用常量
DL::NULL
。您可以在此处查看它的实际操作(倒数第二行),它看起来与您的用例类似。希望这有帮助!I haven't tested this since I'm not on Windows but I think you're intended to use the constant
DL::NULL
. You can see it in action here (second-to-last line) and it looks similar to your use case. Hope that's helpful!