How do I resolve the error message "Unable to load module... because the file couldn't be loaded by the OS"?

I’m trying to test SmartFoxServer2X C++ Client API with UE4.

I created blank project, added Actor class and used for testing. I successfully linked SFS Library following this guide

I built my VS2013 solution without any error. But when I tried to load Editor it failed to load showing message about being “Unable to load module…” Here’s my sfs connector .cpp file:

#include "SFSClient.h"
#include "SFSConnector.h"


void* ASFSConnector::m_ptrMyself = NULL;

ASFSConnector::ASFSConnector(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
    m_ptrSmartFox = boost::shared_ptr<Sfs2X::SmartFox>();
    m_ptrMyself = this;
}

void ASFSConnector::InitializeSmartFox()
{
    m_ptrSmartFox = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
}

The editor fails to load when this string presents, but works fine without it:

m_ptrSmartFox = boost::shared_ptr(new Sfs2X::SmartFox(true));

The log says:

[2014.05.15-20.43.46:967][ 0]LogModuleManager:Warning: ModuleManager: Unable to load module '../../../../../../../uproj/SFSClient/Binaries/Win64/UE4Editor-SFSClient.dll' because the file couldn't be loaded by the OS.

It might be that it can’t find a third party dll. Similar to this: https://answers.unrealengine.com/questions/317606/c-module-plugin-project-builds-but-fails-to-load.html
Were you ever able to solve this?

So when you get the error:
“The game module ‘MyGame’ could not be loaded. There may be an operating system error or the module may not be properly set up.”
Means that there is a Windows DLL load error. (If you are not at windows, it is OS specific, but you need to figure it out yourself).

When you open your project in visual studio, you can pause the the debugger when the dialog appears. Unfortunately, this code is in core-Unreal, but luckily you can download the debug symbols as described here: https://answers.unrealengine.com/questions/77315/can-epic-release-the-pdb-files-for-each-official-e.html . In the main thread you see that the problem occurs (before the dialog) in the code:
LoadModulesForProject()->LoadLibraryW(Filename); in WindowsPlatformProcess.cpp. Unfortunately they don’t call GetLastError() to find out the exact problem. see suggestion here c++ - LoadLibraryW() failing to load DLL in System32 - Stack Overflow

Now to find out the which DLL is missing you must use the Windows Debugging tool GFLAGS GFlags - Windows drivers | Microsoft Docs. GFlags is included in Debugging Tools for Windows.
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. (I don’t know where to get windows debugging tools from. Maybe try Windows SDK archive - Windows app development)

  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 unreal project .sln file.

  8. Run it in debug mode (Developer Editor) (Win64)

  9. When the error dialog comes click OK.

  10. The application closes

  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.

The depends.exe tool is useful in tracking the dependencies of DLLs. The mentioned error is usually a swallowed error from the LoadLibrary() call. Usually a dependent DLL can’t be loaded. If you’re missing one of your own .DLLs, depends will show you the missing symbols.

I don’t have an option for the desktop app, and the command line version just opens and closes.

Well I don’t know. I only did this once and just wrote it down, because it might help other people.

Did you figure out how to fix the desktop app? I have the same issue.

There seems to be a bug with the win10 debug tools SDK. Try using the 8.1 one instead.

The instructions are a little unclear, they suggest there is some kind of way you can launch the UE4 editor in visual studio.

They way I managed to get the dll error message was, I opened my UE4 project in the epic games launcher and before the project hit the error I quickly went to “Debug” menu option in visual studio and selected attach to process. I then found the new UE4 editor process I had just started and attached the debugger to it. Once I go the error I clicked OK and then the stream of information appeared in the Output window.

My specific error was:
2708:0c8c @ 01375218 - LdrpProcessWork - ERROR: Unable to load DLL: “UE4Editor-FPSTemplate-7465.dll”, Parent Module: “C:\Users\Documents\Unreal Projects\hostage_rescue\Binaries\Win64\UE4Editor-hostage_rescue-9629.dll”, Status: 0xc0000135
‘UE4Editor.exe’ (Win32): Unloaded ‘C:\Users\Documents\Unreal Projects\hostage_rescue\Binaries\Win64\UE4Editor-hostage_rescue-9629.dll’

Actually that is what I did: I launched the editor from Visual Studio. It’s been a while, but I believe you can select a target like: “Development Editor” and when you launch it, you get into the editor.

In my case was missing DLL (zlib.dll) which was not present in the PATH and system coudn’t find it. The way I found it out was simply to open the dll in notepad, and search inside for .dll. I know its a rough method :slight_smile: But it worked, notepad showed 2 dlls I was missing, one of which was zlib.dll, I copied that in the binaries directory of my UE project and it worked. Depends.exe was not working for me.

for me the problem came down to having some plugin dll’s which were out of date with my main project dll. Once I recompiled these, it worked. If you are using source control be sure to checkin ALL needed DLLs!