使用ShellExW.dll中的ShellExecWait函数同步调用DOS命令

使用ShellExW.dll中的ShellExecWait函数同步调用DOS命令 


在很多项目中都需要调用外部命令,但是使用VFPRUN命令、VB中的Shell命令或者调用Win32ApiWinExec函数这些方法都是异步执行,不但有些命令难于控制执行窗口的外观,而且使用后不知道执行的结果,往往要采用其他检测的手段才能保证程序正确的运行。现在我们可以使用ShellExW.dll中的ShellExecWait函数来解决这个问题。

 

下面分别列举在VBVFP两种环境下的声明和调用该方法,使用RAR来压缩文件。

 

VB版:

声明:
Public Declare Function ShellExecWait Lib "ShellExW.dll" (ByVal lpProgName As String, ByVal lpParms As String, ByVal n_ShowWinMode As Long, ExitCode As Long) As Long

调用:
Dim a As Long, b As Long
b = 0
可能是声明有些错误,所以执行完成后会报错。请知道VB下声明方法的朋友补充。谢!但是这样可以不影响正常使用。
On Error Resume Next 
a = ShellExecWait("./rar.exe" & String(1, 0), " a test.rar test.doc" & String(1, 0), 0, b)
If a <> 0 Or b <> 0 Then
        Err.Raise 10001, , "
压缩失败"
End If

VFP版:

声明:
DECLARE INTEGER ShellExecWait IN ShellExW.DLL STRING lpProgName, STRING lpParms,  SHORT n_ShowWinMode, INTEGER @ExitCode

b = 0
a = ShellExecWait("./rar.exe"+CHR(0),"A test.rar test.doc"+CHR(0),0, b)
if a <> 0 .or. b <> 0 then
           messagebox(“
压缩失败”)
endif 


vfp9.0调用API制作照相软件实例 PUBLIC WM_CAP_DRIVER_DISCONNECT PUBLIC hwndc,WM_CAP_SAVEDIB,WM_CAP_FILE_SET_CAPTURE_FILEA,WM_CAP_SEQUENCE,WM_CAP_STOP DECLARE INTEGER capCreateCaptureWindowA IN "AVICAP32.DLL" STRING lpszWindowName ,INTEGER dwStyle , INTEGER x, INTEGER Y, INTEGER nWidth ,INTEGER nHeight,INTEGER ParentWin,INTEGER nId DECLARE INTEGER SendMessage IN "user32" INTEGER HWND, INTEGER wmsg,INTEGER wpar1, INTEGER wpar2 DECLARE INTEGER SendMessage IN "user32" AS SendMessageA INTEGER HWND, INTEGER wmsg,INTEGER wpar1, STRING wpar2 *!* 显示: WM_USER = 1024 WM_CAP_START = WM_USER WM_CAP_STOP = WM_CAP_START + 68 WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10 WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11 WM_CAP_SAVEDIB = WM_CAP_START + 25 WM_CAP_GRAB_FRAME = WM_CAP_START + 60 WM_CAP_SEQUENCE = WM_CAP_START + 62 WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20 WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63 WM_CAP_SET_OVERLAY =WM_CAP_START+ 51 WM_CAP_SET_PREVIEW =WM_CAP_START+ 50 WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6 WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2 WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3 WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5 WM_CAP_SET_SCALE=WM_CAP_START+ 53 WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52 hWndC = capCreateCaptureWindowA('My Own Capture Window',1342177280,0,0,200,150,THISFORM.HWND ,0) &&显示大小 IF hWndC 0 SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0) SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0) SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0) SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0) SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0) SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0) * THISFORM.ACTIVATE ENDIF
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值