Issue
Is it true that when an application is linked with an .exe (or .dll that depends on an .exe), this application will crash on windows 10 ?
Long story short
I ask this question because few days ago I had an application that had some unexpected crash on windows 10. After some investigations RbMm gives me some good explanations and reproductible examples Call of statically link function crash everytimes on windows 8/10 but not 7. It allows me to solve my issue but I couldn't believe there could be a so huge important breaking change and I couldn't find any article on this subject.
Details
The conclusion that RbMm found was :
however the root of crash on windows 10 - because windows 10 not resolve PE ("exe") import if this pe have no flag IMAGE_FILE_DLL. in other words it process this PE like LoadLibraryEx with flag DONT_RESOLVE_DLL_REFERENCES - does not load additional executable modules that are referenced by the specified module and nor resolve imports. as result this PE not initialized and will crash at first import function call (in your case this is strcmp).
Examples
And there is a simple way to reproduce the issue :
#include <windows.h>
#include <Netsh.h>
#pragma comment(lib, "Netsh.lib")
void main(int argc, char* argv[])
{
MatchToken(L"*", L"*");// crash here on win 10
}
I also have created a simple project in order to do the trick. It build a .exe with an exported function. And another .exe that use this exported function.
Conclusion
So should I conclude that many projects are now unstable on windows 10 or did I miss some points ? (I'm sure, I did).
Edit
- I never say it is a good practice, I am just using programs that already do this, including some Microsoft libraries (Netsh, wshelper, ...) and some useful projects (postgresql).
You can fall in this case with common call to a library like :
if (HMODULE hmod = LoadLibraryW(L"wshelper.dll"))
{
DWORD (WINAPI * InitHelperDll)(_In_ DWORD dwNetshVersion, PVOID pReserved);
if (*(void**)&InitHelperDll = GetProcAddress(hmod, "InitHelperDll"))
{
InitHelperDll(1, 0);// crash here, internally InitHelperDll call the RegisterHelper function from Netsh.exe.
//but again, because Netsh.exe not initialized (import not resolved) when it loads as DLL in win 10
}
FreeLibrary(hmod);
}
- On windows 7, When debugging the functions from the linked .exe are working fine. So I guess the IAT is initialized. It also use strcmp, so the CRT is initialized.
Is this behaviour against specification ? unspecified ? or just luck ? Should I open a ticket to microsoft helpdesk ? Should I open a ticket to each project that use this behavior. Or is it a proper way to programmatically initialize IAT and CRT on windows 10 (without any modification to the .exe that export the functions) ?