一直很困惑下面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
若import为nil
,则看成是没有参数。若export为nil
,则看做是没有返回值(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
'
=>
'
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
WORD
'
=>
'
I
'
}
如MSDN上的函数原型为:
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')