Windows 10 and UTF8 << Back



Disclaimer: use this trick at your own peril.
There is a setting introduced in Windows 10 version 1803 (April 2018) that might cause data corruption in your VDF/DF programs. I highly recommend that you read this sticky post from the DataAccess forum. The only workaround so far is to tell the user to turn that setting off. We should abort of VDF programs when we detect that Windows setting is on. In order to do that, we can inject a piece of VDF code in every single one of our VDF apps, or we could deploy a fake runtime to help us detect the problem. Time to rip out that Visual C++ compiler.

#include <windows.h>
#include <shlwapi.h>

#pragma comment(linker,"/export:_Activate@4")
#pragma comment(linker,"/export:_FlexRunProgramEx@4")
#pragma comment(linker,"/export:FlexRunProgx=_FlexRunProgx@0")

typedef DWORD(WINAPI *OneParam) (DWORD);
typedef DWORD(WINAPI *ZeroParam) ();

OneParam FlexRunProgramEx_VDF, Activate_VDF;
ZeroParam FlexRunProgx_VDF;

HMODULE gh_RealDll;
HINSTANCE gh_FakeDll;

void LoadRealDll()
{
	TCHAR szPath[MAX_PATH];
	if (gh_RealDll == NULL)
	{
		if (GetOEMCP() == 65001)
		{
			MessageBox(NULL, TEXT("The Windows 10 Beta setting \"Use Unicode UTF - 8 for worldwide language support\" is enabled.  Please disable this setting before continuing.  The program will now abort."), 0, MB_ICONERROR);
			ExitProcess(0);
			return;
		}
		GetModuleFileName(gh_FakeDll, szPath, MAX_PATH);
		PathRenameExtension(szPath, TEXT(".real"));
		gh_RealDll = LoadLibrary(szPath);
		if (gh_RealDll)
		{
			Activate_VDF = (OneParam)GetProcAddress(gh_RealDll, "_Activate@4");
			FlexRunProgramEx_VDF = (OneParam)GetProcAddress(gh_RealDll, "_FlexRunProgramEx@4");
			FlexRunProgx_VDF = (ZeroParam)GetProcAddress(gh_RealDll, "FlexRunProgx");
		}
		else ExitProcess(0);
	}
}

EXTERN_C DWORD WINAPI Activate(DWORD p1)
{
	LoadRealDll();
	return Activate_VDF(p1);
}

EXTERN_C DWORD WINAPI FlexRunProgramEx(DWORD p1)
{
	LoadRealDll();
	return FlexRunProgramEx_VDF(p1);
}

EXTERN_C DWORD WINAPI FlexRunProgx()
{
	LoadRealDll();
	return FlexRunProgx_VDF();
}

EXTERN_C BOOL WINAPI _DllMainCRTStartup(HINSTANCE hInstDll,DWORD fdwReason, LPVOID lpvReserved)
{
	if (fdwReason == DLL_PROCESS_ATTACH) gh_FakeDll = hInstDll;
	return TRUE;
}

Here is the fun part
  1. Compile the above code and you shall get a dll called "VDFVM.DLL".
  2. Rename the VDFVM19.dll to VDFVM19.real (given that you are running DF 19. I am running VDF 16, therefore I would rename VDFVM16.dll)
  3. Rename the VDFVM.DLL to VDFVM19.dll
Now all your VDF/DF programs will abort if that Windows 10 UTF8 setting is on.

We are basically creating a middle man (the VDFVM.DLL) to stand between your VDF app and the actual VDF runtime. The middle man will detect whether that Windows 10 setting is on. If the setting is on, abort the program.

Free Web Hosting