📄 simpletest.bas
字号:
Attribute VB_Name = "SimpleTest"Option ExplicitOption Compare TextDeclare Function GetStdHandle Lib "kernel32" _ (ByVal nStdHandle As Long) As LongDeclare Function WriteFile Lib "kernel32" _ (ByVal hFile As Long, ByVal lpBuffer As String, _ ByVal nNumberOfBytesToWrite As Long, _ lpNumberOfBytesWritten As Long, lpOverlapped As Any) As LongDeclare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (pDst As Any, pSrc As Any, ByVal ByteLen As Long)Private Declare Function lstrlenW Lib "kernel32" _ (lpString As Any) As LongPublic Const STD_OUTPUT_HANDLE = -11&Public Const ERROR_SUCCESS = 0Public hStdOut As Long ' handle of Standard OutputPrivate Sub Main()On Error GoTo Main_ErrDim iArgCount As IntegerDim iArgIter As Integer' Early binding - img is an interface indentifier (IID)Dim img As MagickImage' Late binding - img is accessed via Dispatch interface' Dim img As ObjectDim msgs As VariantDim strMsgs As StringDim elem As VarianthStdOut = GetStdHandle(STD_OUTPUT_HANDLE)'SendConsoleMessage "Got: " & Command$iArgCount = GetParamCount()' If no arguments are supplied then the exe has been called for the purpose' of setting values, not automation'If iArgCount < 1 Then' Exit Sub'End If'For iArgIter = 1 To iArgCount' SendConsoleMessage GetParam(iArgIter)'Next iArgIter' Create the object using the ProgId of the class' Set img = CreateObject("ImageMagickObject.MagickImage.1")' Create the object using a class identifier (The class CLSID)Set img = New MagickImagemsgs = img.Convert("logo:", "logo.jpg")'If Err.Number <> ERROR_SUCCESS Then GoTo Main_Err Main_Exit: Set img = Nothing Exit SubMain_Err: strMsgs = "" ' All ImageMagickObject errors will be above 5000 If BasicError(Err.Number) > 5000 Then msgs = img.Messages If IsArray(msgs) Then For Each elem In msgs strMsgs = strMsgs & elem & vbCrLf Next End If End If SendConsoleMessage "ERROR: " & BasicError(Err.Number) & ": " & Err.Description & vbCrLf & strMsgs 'Resume Main_Exit Resume NextEnd SubPrivate Sub SendConsoleMessage(sMessage As String) Dim rc As Long Dim lBytesWritten As Long MsgBox sMessage Exit Sub sMessage = sMessage & vbCrLf rc = WriteFile(hStdOut, sMessage, Len(sMessage), lBytesWritten, ByVal 0&)End SubFunction BasicError(ByVal e As Long) As Long BasicError = e And &HFFFF&End FunctionFunction COMError(e As Long) As Long COMError = e Or vbObjectErrorEnd Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -