ruby中Win32API调用

一直很困惑下面ruby中使用Win32API调用时,参数中的类型和MSDN上的怎么对应的,今天终于找到对应关系表了

Win32API调用函数:

Win32API.new(dllname, proc, import, export)

加载名为dllname的DLL,生成API函数proc的对象。在import中指定proc的参数类型列表,在export中指定proc返回值的类型。

使用下列字符串或数组来指定类型。

  • "p" 指针
  • "n", "l" long
  • "i" int
  • "v" void

importnil,则看成是没有参数。若exportnil,则看做是没有返回值(void)。

 

数据类型的对应关系在下面文件中定义的

C:\ruby\lib\ruby\gems\1.8\gems\windows-api-0.4.0\lib\windows\api.rb

 

#  Verbose data types that can be used instead of single letters
      DATA_TYPES  =  {
         
' ATOM '           =>   ' I ' ,
         
' BOOL '           =>   ' B ' ,
         
' BOOLEAN '        =>   ' B ' ,
         
' BYTE '           =>   ' I ' ,
         
' CALLBACK '       =>   ' K ' ,
         
' CHAR '           =>   ' I ' ,
         
' COLORREF '       =>   ' L ' ,
         
' DWORD '          =>   ' L ' ,
         
' DWORDLONG '      =>   ' L ' ,
         
' DWORD_PTR '      =>   ' P ' ,
         
' DWORD32 '        =>   ' I ' ,
         
' DWORD64 '        =>   ' L ' ,
         
' HACCEL '         =>   ' L ' ,
         
' HANDLE '         =>   ' L ' ,
         
' HBITMAP '        =>   ' L ' ,
         
' HBRUSH '         =>   ' L ' ,
         
' HCOLORSPACE '    =>   ' L ' ,
         
' HCONV '          =>   ' L ' ,
         
' HDC '            =>   ' L ' ,
         
' HFILE '          =>   ' I ' ,
         
' HKEY '           =>   ' L ' ,
         
' HFONT '          =>   ' L ' ,
         
' HINSTANCE '      =>   ' L ' ,
         
' HKEY '           =>   ' L ' ,
         
' HLOCAL '         =>   ' L ' ,
         
' HMENU '          =>   ' L ' ,
         
' HMODULE '        =>   ' L ' ,
         
' HRESULT '        =>   ' L ' ,
         
' HWND '           =>   ' L ' ,
         
' INT '            =>   ' I ' ,
         
' INT_PTR '        =>   ' P ' ,
         
' INT32 '          =>   ' I ' ,
         
' INT64 '          =>   ' L ' ,
         
' LANGID '         =>   ' I ' ,
         
' LCID '           =>   ' L ' ,
         
' LCTYPE '         =>   ' L ' ,
         
' LONG '           =>   ' L ' ,
         
' LONGLONG '       =>   ' L ' ,
         
' LONG_PTR '       =>   ' P ' ,
         
' LONG32 '         =>   ' L ' ,
         
' LONG64 '         =>   ' L ' ,
         
' LPARAM '         =>   ' P ' ,
         
' LPBOOL '         =>   ' P ' ,
         
' LPBYTE '         =>   ' P ' ,
         
' LPCOLORREF '     =>   ' P ' ,
         
' LPCSTR '         =>   ' P ' ,
         
' LPCTSTR '        =>   ' P ' ,
         
' LPCVOID '        =>   ' L ' ,
         
' LPCWSTR '        =>   ' P ' ,
         
' LPDWORD '        =>   ' P ' ,
         
' LPHANDLE '       =>   ' P ' ,
         
' LPINT '          =>   ' P ' ,
         
' LPLONG '         =>   ' P ' ,
         
' LPSTR '          =>   ' P ' ,
         
' LPTSTR '         =>   ' P ' ,
         
' LPVOID '         =>   ' L ' ,
         
' LPWORD '         =>   ' P ' ,
         
' LPWSTR '         =>   ' P ' ,
         
' LRESULT '        =>   ' P ' ,
         
' PBOOL '          =>   ' P ' ,
         
' PBOOLEAN '       =>   ' P ' ,
         
' PBYTE '          =>   ' P ' ,
         
' PHKEY '          =>   ' P ' ,
         
' SC_HANDLE '      =>   ' L ' ,
         
' SC_LOCK '        =>   ' L ' ,
         
' SERVICE_STATUS_HANDLE '   =>   ' L ' ,
         
' SHORT '          =>   ' I ' ,
         
' SIZE_T '         =>   ' P ' ,
         
' TCHAR '          =>   ' L ' ,
         
' UINT '           =>   ' I ' ,
         
' UINT_PTR '       =>   ' P ' ,
         
' UINT32 '         =>   ' I ' ,
         
' UINT64 '         =>   ' L ' ,
         
' ULONG '          =>   ' L ' ,
         
' ULONGLONG '      =>   ' L ' ,
         
' ULONG_PTR '      =>   ' P ' ,
         
' ULONG32 '        =>   ' L ' ,
         
' ULONG64 '        =>   ' L ' ,
         
' USHORT '         =>   ' I ' ,
         
' USN '            =>   ' L ' ,
         
' WINAPI '         =>   ' L ' ,                            
         
' WORD '           =>   ' I '
      }      
      

 

如MSDN上的函数原型为:

 

ContractedBlock.gif ExpandedBlockStart.gif WinExec
UINT WINAPI WinExec(
  __in  LPCSTR lpCmdLine,
  __in  UINT uCmdShow
);

Parameters
lpCmdLine [
in
The command line (file name plus optional parameters) 
for the application to be executed. If the name of the executable file in the lpCmdLine parameter does not contain a directory path, the system searches for the executable file in this sequence: 

The directory from which the application loaded. 
The current directory. 
The Windows system directory. The GetSystemDirectory function retrieves the path of 
this directory. 
The Windows directory. The GetWindowsDirectory function retrieves the path of 
this directory. 
The directories listed 
in the PATH environment variable. 
uCmdShow [
in
The display options. For a list of the acceptable values, see the description of the nCmdShow parameter of the ShowWindow function.

Return Value
If the function succeeds, the 
return value is greater than 31.

If the function fails, the 
return value is one of the following error values.

 

ruby调用时方法为:Win32API.new("kernel32", "WinExec", ['P','L'], 'L')

转载于:https://www.cnblogs.com/sky_online/archive/2009/11/13/1602515.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值