如何确定为什么 Ruby-FFI 和 VB.net 无法加载 dll 文件?



我有一个文件,其中有四个函数需要使用。DLL函数文档在这里。我已经尝试在VB.net中用Lib加载DLL,在Ruby FFI中用ffi_lib加载DLL。两者都给了我加载DLL的错误,但我无法用任何东西来解释为什么它不能加载DLL。如何确定为什么FFI(我喜欢的访问方法,但我也接受VB.net)不能加载DLL?我在Windows和Mac上都试过了。

DLL文件可在此处获得,或通过在此处的支持页面上安装编号为5的文件获得http://www.mscashdrawer.com/techcashdrawerUSB.php.这将创建一个C:\Program Files\M-S Cash Drawer目录,该目录将包含DLL文件。

Ruby FFI在mac上说

/Users/brandoncc/dev/open_cash_drawer/MSPOS_USB.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00

更新:我想这可能是因为dll是32位的。以下是来自dumpbin 的标头

Dump of file .devopen_cash_drawerMSPOS_USB.dll
PE signature found
File Type: DLL
FILE HEADER VALUES
14C machine (x86)
4 number of sections
53978AFD time date stamp Tue Jun 10 14:47:25 2014
0 file pointer to symbol table
0 number of symbols
E0 size of optional header
2102 characteristics
Executable
32 bit word machine
DLL
OPTIONAL HEADER VALUES
10B magic # (PE32)
9.00 linker version
1800 size of code
1200 size of initialized data
0 size of uninitialized data
1AE4 entry point (10001AE4)
1000 base of code
3000 base of data
10000000 image base (10000000 to 10005FFF)
1000 section alignment
200 file alignment
6.01 operating system version
6.01 image version
5.01 subsystem version
0 Win32 version
6000 size of image
400 size of headers
7714 checksum
3 subsystem (Windows CUI)
140 DLL characteristics
Dynamic base
NX compatible
40000 size of stack reserve
1000 size of stack commit
100000 size of heap reserve
1000 size of heap commit
0 loader flags
10 number of directories
2710 [      9D] RVA [size] of Export Directory
232C [      64] RVA [size] of Import Directory
4000 [     3D0] RVA [size] of Resource Directory
0 [       0] RVA [size] of Exception Directory
0 [       0] RVA [size] of Certificates Directory
5000 [     1C8] RVA [size] of Base Relocation Directory
10B0 [      1C] RVA [size] of Debug Directory
0 [       0] RVA [size] of Architecture Directory
0 [       0] RVA [size] of Global Pointer Directory
0 [       0] RVA [size] of Thread Storage Directory
1138 [      40] RVA [size] of Load Configuration Directory
0 [       0] RVA [size] of Bound Import Directory
1000 [      9C] RVA [size] of Import Address Table Directory
0 [       0] RVA [size] of Delay Import Directory
0 [       0] RVA [size] of COM Descriptor Directory
0 [       0] RVA [size] of Reserved Directory

SECTION HEADER #1
.text name
17AD virtual size
1000 virtual address (10001000 to 100027AC)
1800 size of raw data
400 file pointer to raw data (00000400 to 00001BFF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60000020 flags
Code
Execute Read
Debug Directories
Time Type        Size      RVA  Pointer
-------- ------- -------- -------- --------
53978AFD cv            73 00001180      580    Format: RSDS, {6AFEFF09-4F33-4F1A-AE27-CA8FB3D57A60}, 1, d:currentmscashdrawermscashdrawercontrollermspos_dllobjfre_wxp_x86i386MSPOS_USB.pdb
SECTION HEADER #2
.data name
70C virtual size
3000 virtual address (10003000 to 1000370B)
400 size of raw data
1C00 file pointer to raw data (00001C00 to 00001FFF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0000040 flags
Initialized Data
Read Write
SECTION HEADER #3
.rsrc name
3D0 virtual size
4000 virtual address (10004000 to 100043CF)
400 size of raw data
2000 file pointer to raw data (00002000 to 000023FF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
40000040 flags
Initialized Data
Read Only
SECTION HEADER #4
.reloc name
47C virtual size
5000 virtual address (10005000 to 1000547B)
600 size of raw data
2400 file pointer to raw data (00002400 to 000029FF)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
42000040 flags
Initialized Data
Discardable
Read Only
Summary
1000 .data
1000 .reloc
1000 .rsrc
2000 .text

原来我试图在64位系统上使用32位dll。我希望这能帮助其他人!