vb.netffiruby-ffi

How do I identify why Ruby-FFI and VB.net can't load a dll file?


I have a file that has four functions I need to use. The DLL function documentation is here. I have tried loading the DLL with both Lib in VB.net and ffi_lib with Ruby-FFI. Both give me errors loading the DLL, but nothing I have been able to use to figure out why it can't load the DLL. How do identify why FFI (my preferred access method, but I will accept VB.net as well) can't load the DLL? I tried on both Windows and Mac.

The DLL file is available here or by installing the file at number 5 on the support page here http://www.mscashdrawer.com/techcashdrawerUSB.php. That will make a C:\Program Files\M-S Cash Drawer directory which will contain the DLL file.

Ruby-FFI on mac says

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

Update: I think it might be because the dll is 32 bit. The following is the headers from dumpbin

Dump of file .\dev\open_cash_drawer\MSPOS_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:\current\mscashdrawer\mscashdrawercontroller\mspos_dll\objfre_wxp_x86\i386\MSPOS_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

Solution

  • It turns out that I was trying to use a 32-bit dll on a 64-bit system. I hope this helps someone else!