Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

IsValidDevmodeA (Structures)
 
.
Summary
IsValidDevmodeA function - The print spooler's IsValidDevmode function verifies that the contents of a DEVMODE structure are valid.

Special NOTE: My understanding from MSDN, it will validate public structure only, not private. Also, it will attempt to repair.

C# Definition:

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;
      }
    }

}

VB Definition:

Structure IsValidDevmodeA
   Public TODO
End Structure

User-Defined Field Types:

C++

BOOL IsValidDevmodeA(

  [in, optional] PDEVMODEA pDevmode,
         size_t    DevmodeSize

);

None.

Notes:

My code is from VS 2022 and using .NET Framework 4.8.1 (newer framework shouldn't change much if at all.)

Documentation

https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/winspool/nf-winspool-isvaliddevmodea

Note
DevmodeSize can be optional, my code does not show that.
Note
pass in the pointer to the created devMode, I accidentally used the pointer to allocated memory and that failed.

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions