2

My application written in VS2005 is a 32 bit software. It runs fine on Windows server 2008, windows 7 (64 bit) but does not run on Windows server 2012. I tried to find out which DLL is missing because I get an error from LoadLibrary "A dynamic link library (DLL) initialization routine failed". The code giving error is as under

m_plugin = LoadLibrary( pluginPath.c_str() );
if ( !m_plugin )
{
    const string error( "Failed to load Library \"" + pluginPath + "\" " +  GetLastErrorStdStr() );
    CBLogger::log( error, HIGH_IMPORTANCE );
    return false;
}

To fix the problem I have tried installing C++ redistributable version 8.0.61001 but it did not help.

I even looked at dependency walker (I am really new to it) and did find some windows dlls (eg msvcr80.dll) which were shown in yellow. I copied those into my application folder but that did not work either.

Could some one please give any ideas as to how should I resolve this? What version of redistributable should I install or some tips on how to use dependency walker. Please help

user2837961
  • 1,505
  • 3
  • 27
  • 67
  • 3
    That error does *not* hint at a missing DLL as the cause. One of the DLLs used by your program has a DllMain() entrypoint that returns FALSE. There are no breadcrumbs in your question that give any hint why this might be the case, you need a debugger. – Hans Passant Oct 27 '14 at 08:48
  • I have edited my question with code. The error given is in LoadLibrary and that is where I return false. The dll definitely exists - I have checked that. – user2837961 Oct 27 '14 at 09:00
  • Well, then you ought to be able to narrow down which DLL is the troublemaker. The one you load is the first candidate, it might be a DLL that it uses. If you don't have the source of it then call the programmer for help. – Hans Passant Oct 27 '14 at 09:06
  • Still struggling. The control does not reach the constructor of the DLL it uses. The fact that the same set of code works in windows 2008 server, is it not possible that some windows dll might be missing? – user2837961 Oct 27 '14 at 10:22
  • No, this error cannot be caused by a missing DLL. LoadLibrary calls the new DLL's DllMain function, and that's where the problem is occurring. I'm not sure how best to go about debugging a DllMain function, because you can't set a checkpoint until the DLL is loaded, and by then it's too late. If you can change the code in the DLL you can use the DebugBreak function, otherwise you might have to step into LoadLibrary. – Harry Johnston Oct 27 '14 at 19:30
  • To find the problem I created a blank DLL and slowly started putting my classes and functions in. I finally found the problem but do not know the solution. In project->properties->General, if I change 'Common Language Runtime Support' to 'No common Language Runtime support', my test dll worked fine on windows server 2012. I then changed my application to same but since I am using system namespace, my code gives errors. Any ideas how to resolve this? – user2837961 Oct 28 '14 at 08:42
  • 2
    CLR support means: you need to install .NET Framework. – Alex F Oct 28 '14 at 11:37

4 Answers4

1

Try to check windows events log. It is somewhere around Control Panel -> Administrative Tools -> Event Viewer -> Windows Logs -> Application. Usually you'll see there the exact DLL that was not found with expected version that should also match.

dewaffled
  • 2,850
  • 2
  • 17
  • 30
1

Yes Somehow the LoadLibrary fails, if the DLL does not have the DLLMain function, in Windows Server 2012. To solve this you can use:

LoadLibraryEx(libraryname, NULL, DONT_RESOLVE_DLL_REFERENCES).
danopz
  • 3,310
  • 5
  • 31
  • 42
Naveen
  • 23
  • 1
  • 9
0

Probably the dll can't be load because the error: "An attempt was made to load a program with an incorrect format.". A dll build with platform taget "x86" work fine in a Win 7 x86 or x64 but don't work in a Win 2012 Server x64. Compile the dll with platform target "Any CPU"

Fabian
  • 1
0

I read that dependency walker is no longer reliable since Windows 7 (it gives false negatives). When LoadLibrary fails either the dll that you try to load can't be loaded or a dependency dll.

When you open your project in visual studio, you can pause the the debugger at LoadLibraryW(Filename); Call GetLastError() to find out the exact problem as suggestion here LoadLibraryW() failing to load DLL in System32 if you can modify the source code and recompile.

Now to find out the which DLL is missing you must use the Windows Debugging tool GFLAGS https://msdn.microsoft.com/en-ca/library/windows/hardware/ff549557(v=vs.85).aspx. GFlags is included in Debugging Tools for Windows (I don't know where to get windows debugging tools from. Maybe try https://developer.microsoft.com/en-us/windows/downloads/windows-8-1-sdk). Again unfortunately nobody writes down a good manual how to use it. So these are the steps:

  1. Assuming windows 10 (64-bit), and Windows debugging tools are installed.
  2. After installing SDK, restart
  3. Then click on the windows icon and type 'GFLAGS'
  4. Open "Global Flags (X64) - Desktop App"
  5. Enable Show loader snaps in the "Global Flags" dialog in the "System Registry"-tab (second entry, topleft)
  6. restart (Yes you must restart!)
  7. Open visual studio with your solution file.
  8. Run it in debug mode (Win64)
  9. Let the application run through the error
  10. Stop the application and Close the debugger
  11. Now in the visual studio, Go to the Output pane. And select: Show output from: "Debug"
  12. Examine the last line of the output. Somewhere there will be an entry with ERROR in it. Mine read:

    14b0:15ec @ 00131328 - LdrpSearchPath - RETURN: Status: 0xc0000135 14b0:15ec @ 00131328 - LdrpProcessWork - ERROR: Unable to load DLL: "clAmdFft.Runtime.dll", Parent Module: "C:\Users\steven\Documents\Unreal Projects\Revaro 4.11\Binaries\Win64\UE4Editor-Revaro.dll", Status: 0xc0000135 14b0:15ec @ 00131328 - LdrpLoadDllInternal - RETURN: Status: 0xc0000135 14b0:15ec @ 00131328 - LdrLoadDll - RETURN: Status: 0xc0000135 'UE4Editor.exe' (Win32): Unloaded 'C:\Windows\System32\mfreadwrite.dll'

"clAmdFft.Runtime.dll" This is the DLL that is giving problems. Either install it, the filepath is valid and configured in the project, make sure it is not corrupt and the right version x86/x64.

In my case I added this library myself for the custom code I was using.

Now disable the GFLAGS again, because it will slow down your computer and restart.

Community
  • 1
  • 1
isgoed
  • 724
  • 6
  • 12