REM i: (Argument Type)
REM 'a', sizeof(IDispatch*), VT_DISPATCH} // a IDispatch*
REM 'c', sizeof(unsigned char), VT_I4} // c signed char
REM 'd', sizeof(double), VT_R8} // d 8 byte real
REM 'f', sizeof(float), VT_R4} // f 4 byte real
REM 'k', sizeof(IUnknown*), VT_UNKNOWN} // k IUnknown*
REM 'h', sizeof(long), VT_I4} // h HANDLE
REM 'l', sizeof(long), VT_I4} // l long
REM 'p', sizeof(void*), VT_PTR} // p pointer
REM 's', sizeof(BSTR), VT_LPSTR} // s string
REM 't', sizeof(short), VT_I2} // t short
REM 'u', sizeof(UINT), VT_UINT} // u unsigned int
REM 'w', sizeof(BSTR), VT_LPWSTR} // w wide string
REM f: (Call Method)
REM 'm' - DC_MICROSOFT 0x0000, Default
REM 'b' - DC_BORLAND 0x0001, Borland compat
REM 's' - DC_CALL_STD 0x0020, __stdcall
REM 'c' - DC_CALL_CDECL 0x0010, __cdecl
REM '4' - DC_RETVAL_MATH4 0x0100, Return value in ST
REM '8' - DC_RETVAL_MATH8 0x0200, Return value in ST
REM r: (Return Type)
REM Same as i
上面是"I=ss", "f=s", "R=l"参数
I是输入,s代表一个String类型的参数,
f=s不用管,照抄
R是输出
但是这种调用办法有很多局限,比如指针类型的参数就不行,自定义类型的参数也不行
用excel调用,格式方面比较简单
下面是个例子- Option Explicit
- Dim WshShell, oExcel, strRegKey, strCode, x, y
-
- Set oExcel = CreateObject("Excel.Application")
- set WshShell = CreateObject("wscript.Shell")
-
- strRegKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\$\Excel\Security\AccessVBOM"
- strRegKey = Replace(strRegKey, "$", oExcel.Version)
- '生成注册表路径,oExcel.Version 是当前版本号
- WshShell.RegWrite strRegKey, 1, "REG_DWORD"
- '写如注册表,1表示设置安全级别为低,这样添加宏就不会有安全提示了
-
- strCode = _
- "Private Declare Function SetCursorPos Lib ""user32"" (ByVal x As Long, ByVal y As Long) As Long" & vbCrLf & _
- vbCrLf & _
- "Private Type POINTAPI" & vbCrLf & _
- "X As Long" & vbCrLf & _
- "Y As Long" & vbCrLf & _
- "End Type" & vbCrLf & _
- vbCrLf & _
- "Private Declare Function GetCursorPos Lib ""user32"" (lpPoint As POINTAPI) As Long" & vbCrLf & _
- vbCrLf & _
- "Sub SetCursor(x as Long, y as Long)" & vbCrLf & _
- "SetCursorPos x, y" & vbCrLf & _
- "End Sub" & vbCrLf & _
- vbCrLf & _
- "Public Function GetXCursorPos() As Long" & vbCrLf & _
- "Dim pt As POINTAPI" & vbCrLf & _
- "GetCursorPos pt" & vbCrLf & _
- "GetXCursorPos = pt.X" & vbCrLf & _
- "End Function" & vbCrLf & _
- vbCrLf & _
- "Public Function GetYCursorPos() As Long" & vbCrLf & _
- "Dim pt As POINTAPI" & vbCrLf & _
- "GetCursorPos pt" & vbCrLf & _
- "GetYCursorPos = pt.Y" & vbCrLf & _
- "End Function"
-
- oExcel.Workbooks.Add.VBProject.VBComponents.Add(1).CodeModule.AddFromString strCode
-
- x = oExcel.Run("GetXCursorPos")
- y = oExcel.Run("GetYCursorPos")
- WScript.Echo x, y
-
- oExcel.Run "SetCursor", 1024, 768
-
- oExcel.DisplayAlerts = False
- oExcel.Workbooks.Add.Close
- oExcel.Quit
复制代码
|