Skip to content

Commit 079bba9

Browse files
committed
Load shcore at runtime and fallback if newer DPI funcs are unavailable
Fixes Windows 7 and 8.1 support
1 parent e467f44 commit 079bba9

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ffrunner.res: ffrunner.rc
2020
$(WINDRES) ffrunner.rc -O coff -o ffrunner.res
2121

2222
ffrunner.exe: ffrunner.res $(SRC) $(HDR)
23-
$(CC) -std=c99 -pedantic -mwindows -Wl,--large-address-aware -O0 -g $(SRC) -o ffrunner.exe ffrunner.res -lwindowscodecs -lwininet -ldxgi -lshcore
23+
$(CC) -std=c99 -pedantic -mwindows -Wl,--large-address-aware -O0 -g $(SRC) -o ffrunner.exe ffrunner.res -lwindowscodecs -lwininet -ldxgi
2424

2525
gdbs:
2626
wine /usr/share/win32/gdbserver.exe localhost:10000 ffrunner.exe

ffrunner.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,26 @@ print_args()
551551
printf("force-opengl: %s\n", args.forceOpenGl ? "true" : "false");
552552
}
553553

554+
void
555+
enable_dpi_awareness() {
556+
HMODULE shcore = LoadLibraryA("shcore.dll");
557+
if (shcore) {
558+
SetProcessDpiAwarenessFunc setDpiAwareness =
559+
(SetProcessDpiAwarenessFunc)GetProcAddress(shcore, "SetProcessDpiAwareness");
560+
if (setDpiAwareness) {
561+
if (setDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) == S_OK) {
562+
logmsg("Set DPI awareness to PROCESS_PER_MONITOR_DPI_AWARE\n");
563+
} else {
564+
logmsg("Failed to set DPI awareness: %d\n", GetLastError());
565+
}
566+
}
567+
FreeLibrary(shcore);
568+
} else {
569+
// Fallback for older systems
570+
SetProcessDPIAware();
571+
}
572+
}
573+
554574
int
555575
main(int argc, char **argv)
556576
{
@@ -565,18 +585,7 @@ main(int argc, char **argv)
565585
print_args();
566586
init_logging(args.logPath, args.verboseLogging);
567587

568-
PROCESS_DPI_AWARENESS dpi;
569-
if (GetProcessDpiAwareness(NULL, &dpi) == S_OK) {
570-
if (dpi == PROCESS_DPI_UNAWARE) {
571-
if (SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE) == S_OK) {
572-
logmsg("Set DPI awareness to PROCESS_PER_MONITOR_DPI_AWARE\n");
573-
} else {
574-
logmsg("Failed to set DPI awareness: %d\n", GetLastError());
575-
}
576-
}
577-
} else {
578-
logmsg("Failed to get DPI awareness: %d\n", GetLastError());
579-
}
588+
enable_dpi_awareness();
580589

581590
if (args.serverAddress == NULL) {
582591
logmsg("No server address provided.");

ffrunner.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#define ARRLEN(x) (sizeof(x)/sizeof(*x))
3636
#define MIN(a, b) (a > b ? b : a)
3737

38+
typedef HRESULT (WINAPI *SetProcessDpiAwarenessFunc)(PROCESS_DPI_AWARENESS awareness);
39+
3840
typedef NPError (OSCALL *NP_GetEntryPointsFuncOS)(NPPluginFuncs*);
3941
typedef NPError (OSCALL *NP_InitializeFuncOS)(NPNetscapeFuncs*);
4042
typedef NPError (OSCALL *NP_ShutdownFuncOS)(void);

0 commit comments

Comments
 (0)