在Excel中从VBScript调用ImageMagick COM [英] Calling ImageMagick COM from VBScript in Excel
问题描述
我正在使用Windows 7 64位和Excel 2013。
I'm using Windows 7 64 bit and Excel 2013.
我添加了参考ImageMagickObject 1.0类型库,并确保我没有提前绑定。我还安装了Dynamic 64 bit 16Q ImageMagick。
I added the reference ImageMagickObject 1.0 Type Library and also made sure that I am not binding early. I also installed Dynamic 64 bit 16Q ImageMagick.
运行以下代码时,我仍然遇到错误编号为-2147215503的错误。
I still have an error with error number '-2147215503' when I run the following code.
Private Sub CommandButton1_Click()
On Error GoTo ErrorHandler
Dim img
Set img = New ImageMagickObject.MagickImage
MsgBox (img.Convert("C:\test1.jpg", "-format", "%c", "histogram:info:C:\out.txt"))
Exit Sub
ErrorHandler:
MsgBox (Err.Number & ":" & Err.Description)
End Sub
请告诉我这段代码有什么问题。
如果有人能指出VBA ImageMagick文档,我也将不胜感激。我在Imagemagick.org上搜索过但找不到任何东西。
Please let me know what is wrong with this code. I would also be grateful if anybody can point for VBA ImageMagick Documentation. I've searched on Imagemagick.org but couldn't find anything.
非常感谢。
推荐答案
解码0x8004nnnn错误
设施代码为4的HResults表示HResult包含OLE错误(0x0到0x1ff),而范围的其余部分(0x200以后)是组件特定的错误所以来自一个组件的20e与另一个组件的20e具有不同的含义。
HResults with facility code 4 means the HResult contains OLE errors (0x0 to 0x1ff) while the rest of the range (0x200 onwards) is component specific errors so 20e from one component will have a different meaning to 20e from another component.
-2147215503 = FFFFFFFF80041771 = 1771 =组件特有的错误(只有imagemagick知道什么它意味着)
解码错误
-2147220978样式编号是32位有符号整数,用计算器转换为十六进制。
-2147220978 style numbers are 32 bit signed integers, convert to hex with calculator.
Windows错误(小数字)和COM HResults(通常,但有例外情况,从0x80040154开始,如8) )在WinError.h中定义,除了8007nnnn,你在其中查找它包含的Window错误号。
Windows errors (smallish numbers) and COM HResults (typically, but with exceptions, start with an 8 as in 0x80040154) are defined in WinError.h, except 8007nnnn where you look up the Window error number that it contains.
作为一般规则,Windows错误小于65,535(0xFFFF) 。从0x80000001开始的错误是组件对象模型(COM)HResults。从0xc0000001开始的错误是NTStatus结果。
As a general rule Windows errors are less than 65,535 (0xFFFF). Errors starting 0x80000001 are Component Object Model (COM) HResults. Errors starting 0xc0000001 are NTStatus results.
NTStatus中定义了NTStatus错误(通常但不总是以C开头,如0xC0000022)。
NTStatus errors (typically but not always start with an C as in 0xC0000022) are defined in NTStatus.h.
.h文件是最好的来源,因为它包含错误的符号名称,可以提供错误来源等线索。 FormatMessage没有给出符号名称只有描述。
.h files are the best source because it includes the symbolic name of the error which can give clues such as the source of the error. FormatMessage doesn't give the symbolic name only the description.
你可以通过下载Platform SDK获得这些文件(它是千兆字节)
http:/ /www.microsoft.com/en-us/download/details.aspx%3Fid%3D8279&sa=U&ei=w2IrULDDLsHFmAWbmIHoBg&ved=0CBwQFjAA&usg=AFQjCNHZn9-4f2NnuN9o3UWUsOF3wL7HBQ
You get these files by downloading the Platform SDK (it's gigabytes) http://www.microsoft.com/en-us/download/details.aspx%3Fid%3D8279&sa=U&ei=w2IrULDDLsHFmAWbmIHoBg&ved=0CBwQFjAA&usg=AFQjCNHZn9-4f2NnuN9o3UWUsOF3wL7HBQ
如果你只想要我在skydrive上的两个文件,那么我可以在任何地方引用它们。
https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121
If you just want the two files I have them on my skydrive so I can reference them anywhere I go. https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121
注意互联网错误(12,000 - 12,999)是Windows错误,但在上面提供的wininet.h中指定。
Note internet errors (12,000 - 12,999) are windows errors but are specified in wininet.h also available above.
其他.h文件中定义了错误。但99%属于上述三种。
There are errors defined in other .h files. But 99% are in the three above.
HResults和NTStatus代码的结构
HResults中最重要的位,并且NTStatus中的两个最高有效位设置为出错。因此,Hresults在出错时启动8,NTStatus在出错时启动C.接下来的14或15位是保留的,有些指定了工具 - 错误所在的区域。这是读取十六进制时的第三个和第四个数字。 EG 0xnn07nnnn - HResult工具代码7是正常的Windows'错误(从COM程序返回 - 因此它作为HResult返回)。设施代码在Winerror.h中为HResults定义,NTStatus.h为NTStatus代码定义。它们是不同的。
The most significant bit in HResults, and the two most significant bits in NTStatus are set on error. Hence Hresults start 8 on error and NTStatus starts C on Error. The next 14 or 15 bits are reserved and some specify the facility - what area the error is in. This is the third and fourth number when reading hex. EG 0xnn07nnnn - An HResult facility code 7 is a normal Windows' error (returned from a COM program - hence it's returned as a HResult). Facility codes are defined in Winerror.h for HResults and NTStatus.h for NTStatus codes. They are different.
要解码0x8003nnnn错误
设施代码为3的HResults表示HResult包含OLE结构化存储错误(0x0到0xff)。这些与Dos错误代码相同。这些似乎不在Windows的头文件中,代码列表在这篇文章的末尾。
HResults with facility code 3 means the HResult contains OLE Structured Storage errors (0x0 to 0xff). These are the same as Dos error codes. These don't seem to be in Windows' header files and the list of codes is at the end of this post.
解码0x8004nnnn错误
设施代码为4的HResults表示HResult包含OLE错误(0x0到0x1ff),而范围的其余部分(0x200以后)是组件特定的错误,所以20e来自一个组件与另一个组件的20e具有不同的含义。
HResults with facility code 4 means the HResult contains OLE errors (0x0 to 0x1ff) while the rest of the range (0x200 onwards) is component specific errors so 20e from one component will have a different meaning to 20e from another component.
这就是为什么错误源对0x80040200以上的错误非常重要。
This is why the source of the error is extra important for errors above 0x80040200.
解码0x8007nnnn错误
设施代码为7的HResults表示HResult包含Windows'错误代码。你必须查找Windows的错误代码而不是HResult。
HResults with facility code 7 means the HResult contains a Windows' error code. You have to look up the Windows' error code not the HResult.
解码0x80070002。 0x表示它是十六进制数字,8表示错误,前7表示窗口错误,其余数字2表示实际Windows错误。
To decode 0x80070002. The 0x means it's a hexadecimal number, the 8 means error, the first 7 means it a windows error, and the rest of the number, 2, is the actual Windows error.
要查找错误,我们需要十进制格式。启动计算器(开始 - 所有程序 - 附件 - 计算器)并选择查看菜单 - 科学,然后选择查看菜单 - 十六进制。输入2.然后查看菜单 - 十进制。它会说2。
To look up the error we need it in decimal format. Start Calculator (Start - All Programs - Accessories - Calculator) and choose View menu - Scientific, then View menu - Hex. Enter 2. Then View menu - Decimal. It will say 2.
启动命令提示符(开始 - 所有程序 - 附件 - 命令提示符)并输入
Start a Command Prompt (Start - All Programs - Accessories - Command Prompt) and type
net helpmsg 2
它会说
The system cannot find the file specified.
或在winerror.h中查找。
or look it up in winerror.h
//
// MessageId: ERROR_FILE_NOT_FOUND
//
// MessageText:
//
// The system cannot find the file specified.
//
#define ERROR_FILE_NOT_FOUND 2L
解码0x8019nnnn错误
设施0x19的HResults是HTTP错误。 16,384(0x4000)下的代码与HTTP错误相同,例如HTTP状态404:服务器上不存在请求的URL是0x80190194(0x194 = 404)。代码16,384及更高版本是特定于BITS的。
HResults with facility 0x19 are HTTP errors. Codes under 16,384 (0x4000) are the same as HTTP errors, eg HTTP status 404: The requested URL does not exist on the server is 0x80190194 (0x194 = 404). Codes 16,384 and higher are BITS specific.
Dos错误代码(对于0x8003nnnn错误)
Code Message
01 Invalid function number
02 File not found
03 Path not found
04 Too many open files (no handles left)
05 Access denied
06 Invalid handle
07 Memory control blocks destroyed
08 Insufficient memory
09 Invalid memory block address
0A Invalid environment
0B Invalid format
0C Invalid access mode (open mode is invalid)
0D Invalid data
0E Reserved
0F Invalid drive specified
10 Attempt to remove current directory
11 Not same device
12 No more files
13 Attempt to write on a write-protected diskette
14 Unknown unit
15 Drive not ready
16 Unknown command
17 CRC error
18 Bad request structure length
19 Seek error
1A Unknown media type
1B Sector not found
1C Printer out of paper
1D Write fault
1E Read fault
1F General failure
20 Sharing violation
21 Lock violation
22 Invalid disk change
23 FCB unavailable
24 Sharing buffer overflow
25 Reserved
26 Unable to complete file operation (DOS 4.x)
27-31 Reserved
32 Network request not supported
33 Remote computer not listening
34 Duplicate name on network
35 Network name not found
36 Network busy
37 Network device no longer exists
38 NetBIOS command limit exceeded
39 Network adapter error
3A Incorrect network response
3B Unexpected network error
3C Incompatible remote adapter
3D Print queue full
3E No space for print file
3F Print file deleted
40 Network name deleted
41 Access denied
42 Network device type incorrect
43 Network name not found
44 Network name limit exceeded
45 NetBIOS session limit exceeded
46 Temporarily paused
47 Network request not accepted
48 Print or disk redirection is paused
49-4F Reserved
50 File already exists
51 Reserved
52 Cannot make directory entry
53 Fail on INT 24
54 Too many redirections
55 Duplicate redirection
56 Invalid password
57 Invalid parameter
58 Network device fault
59 Function not supported by network (DOS 4.x)
5A Required system component not installed (DOS 4.x)
设施代码
NTStatus设施人力资源设施
Common status values 0x0 Null 0x0
Debugger 0x1 Rpc 0x1
Rpc_runtime 0x2 Dispatch 0x2
Rpc_stubs 0x3 Storage 0x3
Io_error_code 0x4 Itf 0x4
Various drivers 0x5-0xf Win32 0x7
Ntwin32 0x7 Windows 0x8
Ntsspi 0x9 Sspi 0x9
Terminal_server 0xa Security 0x9
Faciltiy_mui_error_code 0xb Control 0xa
Usb_error_code 0x10 Cert 0xb
Hid_error_code 0x11 Internet 0xc
Firewire_error_code 0x12 Mediaserver 0xd
Cluster_error_code 0x13 Msmq 0xe
Acpi_error_code 0x14 Setupapi 0xf
Sxs_error_code 0x15 Scard 0x10
Transaction 0x19 Complus 0x11
Commonlog 0x1a Aaf 0x12
Video 0x1b Urt 0x13
Filter_manager 0x1c Acs 0x14
Monitor 0x1d Dplay 0x15
Graphics_kernel 0x1e Umi 0x16
Driver_framework 0x20 Sxs 0x17
Fve_error_code 0x21 Windows_ce 0x18
Fwp_error_code 0x22 Http 0x19
Ndis_error_code 0x23 Usermode_commonlog 0x1a
Hypervisor 0x35 Usermode_filter_manager 0x1f
Ipsec 0x36 Backgroundcopy 0x20
Maximum_value 0x37 Configuration 0x21
State_management 0x22
Metadirectory 0x23
Windowsupdate 0x24
Directoryservice 0x25
Graphics 0x26
Shell 0x27
Tpm_services 0x28
Tpm_software 0x29
Pla 0x30
Fve 0x31
Fwp 0x32
Winrm 0x33
Ndis 0x34
Usermode_hypervisor 0x35
Cmi 0x36
Windows_defender 0x50
这篇关于在Excel中从VBScript调用ImageMagick COM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!