; ml.exe -coff hello.asm -link -subsystem:console
.386
.model flat
option casemap:none
exit PROTO C :DWORD
printf PROTO C :PTR,:VARARG
INCLUDELIB msvcrt
EnumDisplaySettingsA PROTO STDCALL :PTR, :DWORD, :PTR
INCLUDELIB user32.lib
POINTL struct
x DWORD ?
y DWORD ?
POINTL ends
DEVMODEX struct
dmDeviceName BYTE 32 dup (?)
dmSpecVersion WORD ?
dmDriverVersion WORD ?
dmSize WORD ?
dmDriverExtra WORD ?
dmFields DWORD ?
union
struct
dmOrientation SWORD ?
dmPaperSize SWORD ?
dmPaperLength SWORD ?
dmPaperWidth SWORD ?
ends
dmPosition POINTL <?>
ends
dmScale SWORD ?
dmCopies SWORD ?
dmDefaultSource SWORD ?
dmPrintQuality SWORD ?
dmColor SWORD ?
dmDuplex SWORD ?
dmYResolution SWORD ?
dmTTOption SWORD ?
dmCollate SWORD ?
dmFormName BYTE 32 dup (?)
dmLogPixels WORD ?
dmBitsPerPel DWORD ?
dmPelsWidth DWORD ?
dmPelsHeight DWORD ?
union
dmDisplayFlags DWORD ?
dmNup DWORD ?
ends
dmDisplayFrequency DWORD ?
dmICMMethod DWORD ?
dmICMIntent DWORD ?
dmMediaType DWORD ?
dmDitherType DWORD ?
dmReserved1 DWORD ?
dmReserved2 DWORD ?
dmPanningWidth DWORD ?
dmPanningHeight DWORD ?
DEVMODEX ends
.data
msg db "%d x %d",10,0
dev db "\\.\DISPLAY1",0
dm DEVMODEX <<?>>
.code
mainCRTStartup PROC C
;invoke EnumDisplaySettingsA, ADDR dev, -1, ADDR dm
invoke EnumDisplaySettingsA, 0, -1, ADDR dm
invoke printf, ADDR msg, dm.dmPelsWidth, dm.dmPelsHeight
invoke exit,0
mainCRTStartup ENDP
END mainCRTStartup
EDIT: fix for default monitor without device name
Hi Timo,
Many thanks, attached is the project built with Poasm. There are some minor modifications in the code, I hope you don't mind.
Running the executable, I get :
0 x 0
Thanks
In my system it gave 1920 x 1080
EDIT:
libs are useful for this testbed
https://forum.pellesc.de/index.php?topic=11474.msg40487#msg40487
Hi Timo,
Thanks, I tested your 32-bit version of msvcrt.lib. The result is the same on my Windows 7 Sp1 64-bit system :
0 x 0
EDIT : Here is the fixed version following Timo's recommendation to set the driver name to NULL.
1366 x 768
My system is also Windows 7 SP1 x64.
Those msvcrt.libs was for common usage for those, who don't have them currently.
Hi Timo,
Compiling the code here with Pelles C :
https://masm32.com/board/index.php?topic=12507.0
the result is :
2130567168 x 5211864
Other test code for device name, to see if it differ#define WINVER 0x0500
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")
BOOL WINAPI EnumMon(HMONITOR unnamedParam1, HDC unnamedParam2, LPRECT unnamedParam3, LPARAM unnamedParam4)
{
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(unnamedParam1, &mi);
printf("%d x %d\n", mi.rcMonitor.right, mi.rcMonitor.bottom);
return 0;
}
int __cdecl main(void)
{
DISPLAY_DEVICE dd;
DEVMODE dm;
TCHAR szDeviceName[33];
dd.cb = sizeof(dd);
EnumDisplayDevices(NULL, 0, &dd, 0);
lstrcpyn(szDeviceName, dd.DeviceName, 33);
printf("%s\n", szDeviceName);
EnumDisplayDevices(szDeviceName, 0, &dd, 0);
printf("%s\n", dd.DeviceString);
dm.dmSize = sizeof(dm);
EnumDisplaySettings(szDeviceName, ENUM_CURRENT_SETTINGS, &dm);
printf("%d x %d\n", dm.dmPelsWidth, dm.dmPelsHeight);
EnumDisplayMonitors(NULL, NULL, &EnumMon, 0);
return 0;
}
shame, that examples didn't work out of box and needs fixings.
EDIT: perhaps this is better ?
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")
int __cdecl printf(const char * restrict, ...);
int __cdecl main(void)
{
DISPLAY_DEVICE dd;
DEVMODE dm;
dd.cb = sizeof(dd);
EnumDisplayDevices(NULL, 0, &dd, 0);
printf("%s\n", dd.DeviceName);
dm.dmSize = sizeof(dm);
//EnumDisplaySettings(dd.DeviceName, ENUM_CURRENT_SETTINGS, &dm);
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
printf("%d x %d\n", dm.dmPelsWidth, dm.dmPelsHeight);
return 0;
}
This worked in my Windows 7 with empty DISPLAY_DEVICE struct or 0 for default monitor
; ml.exe -coff EnumDisplaySetting.asm -link -subsystem:console
.386
.model flat
option casemap:none
exit PROTO C :DWORD
printf PROTO C :PTR,:VARARG
INCLUDELIB msvcrt
EnumDisplaySettingsA PROTO STDCALL :PTR, :DWORD, :PTR
INCLUDELIB user32.lib
DISPLAY_DEVICEX struct
cb DWORD ?
DeviceName BYTE 32 dup (?)
DeviceString BYTE 128 dup (?)
DeviceID BYTE 128 dup (?)
DeviceKey BYTE 128 dup (?)
DISPLAY_DEVICEX ends
POINTL struct
x DWORD ?
y DWORD ?
POINTL ends
DEVMODEX struct
dmDeviceName BYTE 32 dup (?)
dmSpecVersion WORD ?
dmDriverVersion WORD ?
dmSize WORD ?
dmDriverExtra WORD ?
dmFields DWORD ?
union
struct
dmOrientation SWORD ?
dmPaperSize SWORD ?
dmPaperLength SWORD ?
dmPaperWidth SWORD ?
ends
dmPosition POINTL <?>
ends
dmScale SWORD ?
dmCopies SWORD ?
dmDefaultSource SWORD ?
dmPrintQuality SWORD ?
dmColor SWORD ?
dmDuplex SWORD ?
dmYResolution SWORD ?
dmTTOption SWORD ?
dmCollate SWORD ?
dmFormName BYTE 32 dup (?)
dmLogPixels WORD ?
dmBitsPerPel DWORD ?
dmPelsWidth DWORD ?
dmPelsHeight DWORD ?
union
dmDisplayFlags DWORD ?
dmNup DWORD ?
ends
dmDisplayFrequency DWORD ?
dmICMMethod DWORD ?
dmICMIntent DWORD ?
dmMediaType DWORD ?
dmDitherType DWORD ?
dmReserved1 DWORD ?
dmReserved2 DWORD ?
dmPanningWidth DWORD ?
dmPanningHeight DWORD ?
DEVMODEX ends
.data
msg db "%d x %d",10,0
ddx DISPLAY_DEVICEX <?>
dm DEVMODEX <<?>>
.code
mainCRTStartup PROC C
invoke EnumDisplaySettingsA, 0, -1, ADDR dm
;invoke EnumDisplaySettingsA, ddx.DeviceName, -1, ADDR dm
invoke printf, ADDR msg, dm.dmPelsWidth, dm.dmPelsHeight
invoke exit,0
mainCRTStartup ENDP
END mainCRTStartup
Hi Timo,
When the driver name is set to NULL, I get the correct result. Many thanks.
1366 x 768