Question

I am building an existing MFC application with Visual Studio 2012. The application uses "RichEdit20A" controls and custom controls which inherit CRichEditCtrl.

During InitInstance() the application calls ::AfxInitRichEdit2(), which calls AtlLoadSystemLibraryUsingFullPath(L"RICHED20.DLL"), which callsLoadLibraryExW(pszLibrary, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32). The latter call fails and returns NULL. GetLastError() returns 87 (The parameter is incorrect.). This happens on both Win7 x64 and Win8 x64.

The failing call seems to have been introduced in the Visual Studio 2012 runtime (it is inside a conditional #if NTDDI_VERSION >= NTDDI_WIN8). The application worked just fine when built with Visual Studio 2008.

Does anyone know why this happens and how to fix (or work around) this issue? Alternatively, is there any way to "revert" the runtime to use the older load behavior?

Was it helpful?

Solution

Choosing the proper target Windows version can be very important. It is here, if you don't explicitly set it yourself then the Visual Studio assumes you'll target the latest and greatest. Which is Windows 8 for VS2012.

Which includes a new option for LoadLibraryEx(), the LOAD_LIBRARY_SEARCH_SYSTEM32 option. Available on Windows 8 but requires a security patch to be installed if you use it on Windows Vista, 7 or 2008. It is a pretty critical one, clearly you don't have it installed.

If you want your program to be compatible with old or unpatched Windows versions then you need to change the target. This is typically done by the targetver.h header file, assuming your MFC project was generated by a relatively recent wizard. Modify it like this:

#pragma once

// Including SDKDDKVer.h defines the highest available Windows platform.

// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.

#define _WIN32_WINNT _WIN32_WINNT_WINXP    // NOTE: added
#include <SDKDDKVer.h>

If you don't have targetver.h then put it anywhere before the #include for <windows.h>. Tweak the value as desired. Note that XP isn't currently supported by VS2012 but will be later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top