using System;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class User32
{
///
///
/// Indicates the state of screen auto-rotation for the system. For example, whether auto-rotation is supported, and whether it is
/// enabled by the user. This enum is a bitwise OR of one or more of the following values.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ne-winuser-ar_state typedef enum tagAR_STATE { AR_ENABLED,
// AR_DISABLED, AR_SUPPRESSED, AR_REMOTESESSION, AR_MULTIMON, AR_NOSENSOR, AR_NOT_SUPPORTED, AR_DOCKED, AR_LAPTOP } AR_STATE, *PAR_STATE;
[PInvokeData("winuser.h", MSDNShortId = "55BCB2EB-524D-478A-8DCE-53E59DD0822D")]
[Flags]
public enum AR_STATE
{
/// Auto-rotation is enabled by the user.
AR_ENABLED = 0x00,
/// Auto-rotation is disabled by the user.
AR_DISABLED = 0x01,
/// Auto-rotation is currently suppressed by one or more process auto-rotation preferences.
AR_SUPPRESSED = 0x02,
/// The session is remote, and auto-rotation is temporarily disabled as a result.
AR_REMOTESESSION = 0x04,
/// The system has multiple monitors attached, and auto-rotation is temporarily disabled as a result.
AR_MULTIMON = 0x08,
/// The system does not have an auto-rotation sensor.
AR_NOSENSOR = 0x10,
/// Auto-rotation is not supported with the current system configuration.
AR_NOT_SUPPORTED = 0x20,
/// The device is docked, and auto-rotation is temporarily disabled as a result.
AR_DOCKED = 0x40,
/// The device is in laptop mode, and auto-rotation is temporarily disabled as a result.
AR_LAPTOP = 0x80,
}
///
/// Translates a string into the OEM-defined character set.
/// Warning Do not use. See Security Considerations.
///
///
/// Type: LPCTSTR
/// The null-terminated string to be translated.
///
///
/// Type: LPSTR
///
/// The destination buffer, which receives the translated string. If the CharToOem function is being used as an ANSI function,
/// the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter. This cannot
/// be done if CharToOem is being used as a wide-character function.
///
///
///
/// Type: BOOL
///
/// The return value is always nonzero except when you pass the same address to lpszSrc and lpszDst in the wide-character version of
/// the function. In this case the function returns zero and GetLastError returns ERROR_INVALID_ADDRESS.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-chartooema BOOL CharToOemA( LPCSTR pSrc, LPSTR pDst );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CharToOem(string pSrc, StringBuilder pDst);
/// Translates a specified number of characters in a string into the OEM-defined character set.
///
/// Type: LPCTSTR
/// The null-terminated string to be translated.
///
///
/// Type: LPSTR
///
/// The buffer for the translated string. If the CharToOemBuff function is being used as an ANSI function, the string can be
/// translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter. This cannot be done if
/// CharToOemBuff is being used as a wide-character function.
///
///
///
/// Type: DWORD
/// The number of characters to translate in the string identified by the lpszSrc parameter.
///
///
/// Type: BOOL
///
/// The return value is always nonzero except when you pass the same address to lpszSrc and lpszDst in the wide-character version of
/// the function. In this case the function returns zero and GetLastError returns ERROR_INVALID_ADDRESS.
///
///
///
/// Unlike the CharToOem function, the CharToOemBuff function does not stop converting characters when it encounters a null
/// character in the buffer pointed to by lpszSrc. The CharToOemBuff function converts all cchDstLength characters.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-chartooembuffa BOOL CharToOemBuffA( LPCSTR lpszSrc, LPSTR
// lpszDst, DWORD cchDstLength );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CharToOemBuff(string lpszSrc, StringBuilder lpszDst, uint cchDstLength);
///
/// Retrieves an AR_STATE value containing the state of screen auto-rotation for the system, for example whether auto-rotation is
/// supported, and whether it is enabled by the user. GetAutoRotationState provides a robust and diverse way of querying for
/// auto-rotation state, and more. For example, if you want your app to behave differently when multiple monitors are attached then
/// you can determine that from the AR_STATE returned.
///
/// Pointer to a location in memory that will receive the current state of auto-rotation for the system.
///
/// TRUE if the method succeeds, otherwise FALSE.
/// See GetDisplayAutoRotationPreferences for an example of using this function.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getautorotationstate BOOL GetAutoRotationState( PAR_STATE
// pState );
[DllImport(Lib.User32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "E041717B-920E-44F8-AC7F-B30CB82F1476")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetAutoRotationState(out AR_STATE pState);
///
/// Translates a string from the OEM-defined character set into either an ANSI or a wide-character string.
/// Warning Do not use. See Security Considerations.
///
///
/// Type: LPCSTR
/// A null-terminated string of characters from the OEM-defined character set.
///
///
/// Type: LPTSTR
///
/// The destination buffer, which receives the translated string. If the OemToChar function is being used as an ANSI function,
/// the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter. This cannot
/// be done if OemToChar is being used as a wide-character function.
///
///
///
/// Type: BOOL
///
/// The return value is always nonzero except when you pass the same address to lpszSrc and lpszDst in the wide-character version of
/// the function. In this case the function returns zero and GetLastError returns ERROR_INVALID_ADDRESS.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-oemtochara BOOL OemToCharA( LPCSTR pSrc, LPSTR pDst );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OemToChar(string pSrc, StringBuilder pDst);
///
/// Translates a specified number of characters in a string from the OEM-defined character set into either an ANSI or a
/// wide-character string.
///
///
/// Type: LPCSTR
/// One or more characters from the OEM-defined character set.
///
///
/// Type: LPTSTR
///
/// The destination buffer, which receives the translated string. If the OemToCharBuff function is being used as an ANSI
/// function, the string can be translated in place by setting the lpszDst parameter to the same address as the lpszSrc parameter.
/// This cannot be done if the OemToCharBuff function is being used as a wide-character function.
///
///
///
/// Type: DWORD
/// The number of characters to be translated in the buffer identified by the lpszSrc parameter.
///
///
/// Type: BOOL
///
/// The return value is always nonzero except when you pass the same address to lpszSrc and lpszDst in the wide-character version of
/// the function. In this case the function returns zero and GetLastError returns ERROR_INVALID_ADDRESS.
///
///
///
/// Unlike the OemToChar function, the OemToCharBuff function does not stop converting characters when it encounters a null
/// character in the buffer pointed to by lpszSrc. The OemToCharBuff function converts all cchDstLength characters.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-oemtocharbuffa BOOL OemToCharBuffA( LPCSTR lpszSrc, LPSTR
// lpszDst, DWORD cchDstLength );
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool OemToCharBuff(string lpszSrc, StringBuilder lpszDst, uint cchDstLength);
///
/// Sets the last-error code.
/// Currently, this function is identical to the SetLastError function. The second parameter is ignored.
///
/// The last-error code for the thread.
/// This parameter is ignored.
///
/// The last-error code is kept in thread local storage so that multiple threads do not overwrite each other's values.
///
/// Most functions call SetLastError or SetLastErrorEx only when they fail. However, some system functions call
/// SetLastError or SetLastErrorEx under conditions of success; those cases are noted in each function's documentation.
///
///
/// Applications can optionally retrieve the value set by this function by using the GetLastError function immediately after a
/// function fails.
///
///
/// Error codes are 32-bit values (bit 31 is the most significant bit). Bit 29 is reserved for application-defined error codes; no
/// system error code has this bit set. If you are defining an error code for your application, set this bit to indicate that the
/// error code has been defined by the application and to ensure that your error code does not conflict with any system-defined error codes.
///
///
// https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setlasterrorex void SetLastErrorEx( DWORD dwErrCode, DWORD
// dwType );
[DllImport(Lib.User32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("winuser.h", MSDNShortId = "d97494db-868a-49d4-a613-e8beba86d4e6")]
public static extern void SetLastErrorEx(uint dwErrCode, uint dwType = 0);
}
}