Skip to content

Commit

Permalink
Load overriden entry points if available
Browse files Browse the repository at this point in the history
  • Loading branch information
nalexandru committed Nov 13, 2022
1 parent 94c3fec commit 89d1171
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 38 deletions.
93 changes: 93 additions & 0 deletions bcompat7/bcompat7.c
Original file line number Diff line number Diff line change
@@ -1,32 +1,69 @@
#include <Windows.h>

enum MONITOR_DPI_TYPE {
MDT_EFFECTIVE_DPI,
MDT_ANGULAR_DPI,
MDT_RAW_DPI,
MDT_DEFAULT
};

enum PROCESS_DPI_AWARENESS {
PROCESS_DPI_UNAWARE,
PROCESS_SYSTEM_DPI_AWARE,
PROCESS_PER_MONITOR_DPI_AWARE
};

static HMODULE _kernel32, _shcore;

static BOOL(WINAPI *_GetPointerType)(_In_ UINT32, _Out_ POINTER_INPUT_TYPE *);
static BOOL(WINAPI *_GetPointerInfo)(_In_ UINT32, _Out_writes_(1) POINTER_INFO *);
static BOOL(WINAPI *_GetPointerInfoHistory)(_In_ UINT32, _Inout_ UINT32 *, POINTER_INFO *);
static BOOL(WINAPI *_GetPointerPenInfoHistory)(_In_ UINT32, _Inout_ UINT32 *, POINTER_PEN_INFO *);

static HANDLE(WINAPI *_CreateFile2)(_In_ LPCWSTR, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCREATEFILE2_EXTENDED_PARAMETERS);

static HRESULT(WINAPI *_GetDpiForMonitor)(HMONITOR, enum MONITOR_DPI_TYPE, UINT *, UINT *);
static HRESULT(WINAPI *_SetProcessDpiAwareness)(enum PROCESS_DPI_AWARENESS);

// The pointer messages (WM_POINTER*) do not exist in Windows 7.
// Because of this, it's unlikely that the GetPointer* functions will be called.

__declspec(dllexport) BOOL WINAPI
GetPointerType(_In_ UINT32 pointerId, _Out_ POINTER_INPUT_TYPE *pointerType)
{
if (_GetPointerType)
return GetPointerType(pointerId, pointerType);

*pointerType = PT_MOUSE;
return TRUE;
}

__declspec(dllexport) BOOL WINAPI
GetPointerInfo(_In_ UINT32 pointerId, _Out_writes_(1) POINTER_INFO *pointerInfo)
{
if (_GetPointerInfo)
return _GetPointerInfo(pointerId, pointerInfo);

SetLastError(ERROR_NO_DATA);
return FALSE;
}

__declspec(dllexport) BOOL WINAPI
GetPointerInfoHistory(_In_ UINT32 pointerId, _Inout_ UINT32 *entriesCount, _Out_writes_opt_(*entriesCount) POINTER_INFO *pointerInfo)
{
if (_GetPointerInfoHistory)
return _GetPointerInfoHistory(pointerId, entriesCount, pointerInfo);

SetLastError(ERROR_NO_DATA);
return FALSE;
}

__declspec(dllexport) BOOL WINAPI
GetPointerPenInfoHistory(_In_ UINT32 pointerId, _Inout_ UINT32 *entriesCount, _Out_writes_opt_(*entriesCount) POINTER_PEN_INFO *penInfo)
{
if (_GetPointerPenInfoHistory)
return _GetPointerPenInfoHistory(pointerId, entriesCount, penInfo);

SetLastError(ERROR_NO_DATA);
return FALSE;
}
Expand All @@ -35,9 +72,65 @@ __declspec(dllexport) HANDLE WINAPI
CreateFile2(_In_ LPCWSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_ DWORD dwCreationDisposition,
_In_opt_ LPCREATEFILE2_EXTENDED_PARAMETERS pCreateExParams)
{
if (_CreateFile2)
return _CreateFile2(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, pCreateExParams);

if (pCreateExParams)
return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, pCreateExParams->lpSecurityAttributes, dwCreationDisposition,
pCreateExParams->dwFileAttributes | pCreateExParams->dwFileFlags | pCreateExParams->dwSecurityQosFlags, pCreateExParams->hTemplateFile);
else
return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, 0, NULL);
}

__declspec(dllexport) HRESULT WINAPI
GetDpiForMonitor(HMONITOR mon, enum MONITOR_DPI_TYPE dpiType, UINT *dpiX, UINT *dpiY)
{
if (_GetDpiForMonitor)
return _GetDpiForMonitor(mon, dpiType, dpiX, dpiY);

*dpiX = *dpiY = 96;
return S_OK;
}

__declspec(dllexport) HRESULT WINAPI
SetProcessDpiAwareness(enum PROCESS_DPI_AWARENESS value)
{
if (_SetProcessDpiAwareness)
return _SetProcessDpiAwareness(value);

if (value != PROCESS_DPI_UNAWARE)
SetProcessDPIAware();

return S_OK;
}

BOOL WINAPI
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
_kernel32 = LoadLibrary(L"kernel32");
_shcore = LoadLibrary(L"shcore");

if (_kernel32) {
_GetPointerType = GetProcAddress(_kernel32, "GetPointerType");
_GetPointerInfo = GetProcAddress(_kernel32, "GetPointerInfo");
_GetPointerInfoHistory = GetProcAddress(_kernel32, "GetPointerInfoHistory");
_GetPointerPenInfoHistory = GetProcAddress(_kernel32, "GetPointerPenInfoHistory");

_CreateFile2 = GetProcAddress(_kernel32, "CreateFile2");
}

if (_shcore) {
_GetDpiForMonitor = GetProcAddress(_shcore, "GetDpiForMonitor");
_SetProcessDpiAwareness = GetProcAddress(_shcore, "SetProcessDpiAwareness");
}
break;
case DLL_PROCESS_DETACH:
FreeLibrary(_shcore);
FreeLibrary(_kernel32);

break;
}
return TRUE;
}
8 changes: 4 additions & 4 deletions bcompat7/bcompat7.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,2,0,3
PRODUCTVERSION 1,2,0,3
FILEVERSION 1,3,0,4
PRODUCTVERSION 1,3,0,4
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Alexandru Naiman"
VALUE "FileDescription", "Windows 7 Shim DLL for Blender 3.x"
VALUE "FileVersion", "1.2.0.3"
VALUE "FileVersion", "1.3.0.4"
VALUE "InternalName", "bcompat7.dll"
VALUE "LegalCopyright", "Copyright (C) 2022 Alexandru Naiman"
VALUE "OriginalFilename", "bcompat7.dll"
VALUE "ProductName", "BlenderCompat"
VALUE "ProductVersion", "1.2.0.3"
VALUE "ProductVersion", "1.3.0.4"
END
END
BLOCK "VarFileInfo"
Expand Down
1 change: 0 additions & 1 deletion bcompat7/bcompat7.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bcompat7.c" />
<ClCompile Include="scaling.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
Expand Down
3 changes: 0 additions & 3 deletions bcompat7/bcompat7.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<ClCompile Include="bcompat7.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="scaling.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
Expand Down
30 changes: 0 additions & 30 deletions bcompat7/scaling.c

This file was deleted.

Binary file modified bin/bin/bcompat7.dll
Binary file not shown.
Binary file modified bin/lib/bcompat7.lib
Binary file not shown.

0 comments on commit 89d1171

Please sign in to comment.