Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, May 18, 2018 1:24 PM
When running 64 bit .net application from VS 2017 community with c# and managed c++ dlls, several Microsoft dlls are missing.
API-MS-WIN-CORE-HEAP-L2-1-0.DLL
API-MS-WIN-CORE-LibraryLOADER-L1-2-0.DLL
and possibly some more.
How to fix it?
I used the dependency walker, when i added C:\Windows\system32\downlevel
to this tool, some of these errors are no longer there, but at least the above mentioned dlls
are still missing.
Regards
Bernd Schleifenbaum
All replies (3)
Friday, May 18, 2018 3:18 PM
But the question is, are they missing or are the tools that report them missing actually doing something wrong. For example, what happens when you actually try to load the library into a program? What do you expect this C++ program:
#include <Windows.h>
#include <cstdio>
int wmain()
{
HMODULE h = LoadLibraryExW(L"API-MS-WIN-CORE-HEAP-L2-1-0.DLL", nullptr, 0);
HANDLE h_file;
h_file = CreateFile(L"C:\\Windows\\System32\\API-MS-WIN-CORE-HEAP-L2-1-0.DLL", GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
if (h_file == INVALID_HANDLE_VALUE)
{
DWORD err = GetLastError();
wprintf(L"File failed to open, error: %d\n", err);
}
if (h == nullptr)
{
wprintf(L"Failed to load library\n");
return GetLastError();
}
wchar_t mf[MAX_PATH + 1];
GetModuleFileNameW(h, mf, MAX_PATH);
wprintf(L"Loaded %s\n", mf);
return 0;
}
To output? Well, the output that I get is:
File failed to open, error: 2
Loaded C:\Windows\System32\KERNELBASE.dll
Where error 2 is ERROR_FILE_NOT_FOUND. Now you might be asking, "but I asked for API-MS-WIN-CORE-HEAP-L2-1-0.dll, so where did kernelbase.dll come from?" The answer is easy, the DLLs named in the way API-MS-WIN-xxx.dll are called API sets. They are used to decouple the functions in the API set from the library that the function is actually implemented. When the idea first started they were actual files in the Windows directory under System32 and SysWow64, but they were just forwarders. But with Windows 8 onwards they became virtual DLLs, you couldn't find them on disk but if it was a dependency for an EXE or DLL, or you used LoadLibrary to load it then it would work.
You see, the Windows library loader is in on this, it looks for requests to load certain names, and if it finds them, like API-MS-WIN-CORE-HEAP-L2-1-0.dll or API-MS-WIN-CORE-LIBRARYLOADER-L1-2-0.dll then it will quietly substitute it with the name of the DLL that the functions are really implemented, like kernelbase.dll.
This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.
Friday, May 18, 2018 5:00 PM
The problem is as follows:
I ported an application from vs 2005 to vs 2017 community, all necessary source files compiled (debug).
When I start the application in debug mode (on Windows 10, x64) one of my dll's or at least one dependency dll was not found.
When I load this dll in the dependency wallker, then mentioned api dll's are not found.
It is a .NET application with additional managed c++ , native c++ and native c static lib.
My dll which failed is a managed c++ dll.
How can I fix this problem? Is the kernelbase.dll missing ?
Friday, May 18, 2018 11:28 PM
If your computer is actually running Windows, then no, kernelbase.dll isn't missing. You see, all user programs that run will have kernel32.dll loaded in by default, it is a forced thing. Kernel32.dll depends upon kernelbase.dll, so all applications will load kernelbase.dll. So basically, if your computer runs any application then kernelbase.dll can't be missing.
Dependency walker is also notoriously bad because it was never updated to handle API sets. All it does is search the file paths for the libraries, but these libraries don't exist on disk on Windows 8 or newer. To give you a taste of this, run dependency walker (depends.exe) on itself. On Windows 10, dependency walker will report that dependency walker will not be able to run because these API-MS-WIN-xxx.dll files are missing. (If you don't understand what this means, ask yourself, how can dependency walker state these dependencies are missing if it can't run due to missing dependencies).
The API set DLLs will always be resolved by Windows, Windows treats these names as an alias to the real DLL on disk, so there is no problem that these DLLs are missing. To reiterate, dependency walker is bad and shouldn't be used unless you know what you are doing.
What you need to do is give more information on what the DLL that is failing to load depends on. You need to make sure that the dependencies are properly placed in a place that is accessible, and that it isn't trying to load the 32 bit versions of these libraries by mistake.
This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.