1

I am accessing a c++ dll library (I don't have the source code) from c++ code. I use this library to mount a usb device so I can access the files on the device. This code worked well in VS2010 but since we updated to VS2013 it no longer works. Here is my question. What differences between VS2010 and VS2013 might cause this to fail or what settings might cause this to fail?

Here is what I observe when running the code:

  1. The LoadLibary call returns a module handle
  2. The GetProcAddress seems to return a valid procedure address
  3. Invoking the dyn_Open_Device always returns false with VS2013 it almost always returned true in VS2010.
  4. After calling dyn_Open_Device, GetLastError returns 2 (ERROR_FILE_NOT_FOUND)

Here is the code:

typedef bool(*PFUNC_Open_Device)();

DWORD dwError = GetLastError();
BOOL bSuccess = SetDllDirectory(_T("C:\\Users\\steve epp\\Desktop\\EH16\\sdk1.1\\lib\\"));

// Step 2: Dynamically load the dll
HMODULE m_hModule = LoadLibrary("eeyelog_protocol_v1.0.dll");

dwError = GetLastError();

// Handle the case that the dll is not found
if (m_hModule == NULL)
{
    dwError = GetLastError();
    if (dwError == ERROR_MOD_NOT_FOUND)
    {
        CString msg = "Unable to load eeyelog_protocol_v1.0.dll.";
        AfxMessageBox(msg, MB_OK | MB_ICONEXCLAMATION);
    }
}

PFUNC_Open_Device dyn_Open_Device = (PFUNC_Open_Device)GetProcAddress(m_hModule, "Open_Device");
dwError = GetLastError();

bool ret = dyn_Open_Device();
dwError = GetLastError();

Here is the DUMPBIN results:

DUMPBIN /EXPORTS "C:\Users\steve epp\Desktop\EH16\sdk1.1\lib\eeyelog_protocol_v1.0.dll"
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file C:\Users\steve epp\Desktop\EH16\sdk1.1\lib\eeyelog_protocol_v1.0.dll

File Type: DLL

  Section contains the following exports for eeyelog_protocol_v1.0.dll

    00000000 characteristics
    59CC4F90 time date stamp Wed Sep 27 18:25:36 2017
        0.00 version
           1 ordinal base
          33 number of functions
          33 number of names

    ordinal hint RVA      name

          1    0 000010A0 Check_Device_state
          2    1 000011D0 Close_Device
          3    2 000012E0 Login
          4    3 000011A0 Open_Device
Steve E
  • 11
  • 3
  • all this absolute unrelated to visual-studio and getprocaddress. DUMPBIN results for what ?! `dyn_Open_Device();` return `ERROR_FILE_NOT_FOUND` which mean that device not found. all – RbMm Jan 17 '18 at 21:04

1 Answers1

0

I solved the problem with the help of Process Monitor. In the Process Monitor’s Event Properties dialog under the Process tab I could see that eeyelog_protocol_v1.0.dll was running and its dependency libusb0.dll was also running. However, the running libusb0.dll was the wrong version an older version. Once I ran the correct version then everything worked again. Running the code through the debugger it was picking up the wrong version of libusb0.dll from the directory containing the executable. So make sure you are loading and running the right version. I had the correct version in the path I set with SetDllDirectory but it was using the wrong version because it found that one first.

I had never used Process Monitor before. It is a very helpful Microsoft SysInternals tool. It can be found downloaded from https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

Steve E
  • 11
  • 3