Special NOTE: My understanding from MSDN, it will validate public structure only, not private. Also, it will attempt to repair.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
[DllImport("winspool.Drv", EntryPoint = "IsValidDevmodeA", SetLastError = true,
ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
static extern bool IsValidDevmodeA(IntPtr pDevmode, int DevmodeSize);
public static bool CheckIsValidDevmodeA(IntPtr ptrDevModeA, int totalByteSize)
{
try
{
// Calls extern IsValidDevmodeA.
// totalByteSize could be made optional.
if (IsValidDevmodeA(ptrDevModeA, totalByteSize))
{
return true;
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
catch (Exception e)
{
throw e;
}
}
}
Structure IsValidDevmodeA
Public TODO
End Structure
BOOL IsValidDevmodeA(
[in, optional] PDEVMODEA pDevmode,
size_t DevmodeSize
);
None.
My code is from VS 2022 and using .NET Framework 4.8.1 (newer framework shouldn't change much if at all.)
https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/winspool/nf-winspool-isvaliddevmodea