using Microsoft.Win32.SafeHandles; using System; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Text; using Vanara.InteropServices; using static Vanara.PInvoke.Kernel32; using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME; namespace Vanara.PInvoke { /// Exposes interfaces, functions and structures defined in shlwapi.dll. public static partial class ShlwApi { /// /// Used by IQueryAssociations::GetData to define the type of data that is to be returned. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-assocdata [PInvokeData("shlwapi.h", MSDNShortId = "0ae5c8db-81fd-4d00-8e54-0c474f1bfd06")] public enum ASSOCDATA { /// The component descriptor to pass to the Windows Installer API. ASSOCDATA_MSIDESCRIPTOR = 1, /// Attempts to activate a window are restricted. There is no data associated with this value. ASSOCDATA_NOACTIVATEHANDLER, /// ASSOCDATA_UNUSED1, /// Defaults to user specified association. ASSOCDATA_HASPERUSERASSOC, /// /// Internet Explorer version 6 or later. Gets the data stored in the EditFlags value of a file association PROGID registry key. /// This value consists of one or more FILETYPEATTRIBUTEFLAGS. Compare against those values to determine which attributes have /// been set. /// ASSOCDATA_EDITFLAGS, /// /// Internet Explorer version 6 or later. Uses the parameter from the IQueryAssociations::GetData method as the value name. /// ASSOCDATA_VALUE, /// ASSOCDATA_MAX, } /// /// Used by IQueryAssociations::GetEnum to define the type of enum that is to be returned. /// public enum ASSOCENUM { /// Nothing. ASSOCENUM_NONE } /// Format flags for SHFormatDateTime. [PInvokeData("shlwapi.h", MSDNShortId = "2208ed29-6029-4051-bdcc-885c42fe5c1b")] [Flags] public enum FDTF { /// /// Formats the time of day as specified by the Regional and Language Options application in Control Panel, but without seconds. /// This flag cannot be combined with FDTF_LONGTIME. /// The short time was successfully formatted. /// FDTF_SHORTTIME = 0x00000001, /// /// Formats the date as specified by the short date format in the Regional and Language Options application in Control Panel. /// This flag cannot be combined with FDTF_LONGDATE. /// The short date was successfully formatted. /// FDTF_SHORTDATE = 0x00000002, /// Equivalent to FDTF_SHORTDATE | FDTF_SHORTTIME. FDTF_DEFAULT = FDTF_SHORTDATE | FDTF_SHORTTIME, /// /// Formats the date as specified by the long date format in the Regional and Language Options application in Control Panel. This /// flag cannot be combined with FDTF_SHORTDATE. /// The long date was successfully formatted. /// FDTF_LONGDATE = 0x00000004, /// /// Formats the time of day as specified by the Regional and Language Options application in Control Panel, including seconds. /// This flag cannot be combined with FDTF_SHORTTIME. /// The long time was successfully formatted. /// FDTF_LONGTIME = 0x00000008, /// /// If the FDTF_LONGDATE flag is set and the date in the FILETIME structure is the same date that SHFormatDateTime is called, /// then the day of the week (if present) is changed to "Today". If the date in the structure is the previous day, then the day /// of the week (if present) is changed to "Yesterday". /// Relative notation was used for the date. /// FDTF_RELATIVE = 0x00000010, /// Adds marks for left-to-right reading layout. This flag cannot be combined with FDTF_RTLDATE. FDTF_LTRDATE = 0x00000100, /// Adds marks for right-to-left reading layout. This flag cannot be combined with FDTF_LTRDATE. FDTF_RTLDATE = 0x00000200, /// /// No reading order marks are inserted. Normally, in the absence of the FDTF_LTRDATE or FDTF_RTLDATE flag, SHFormatDateTime /// determines the reading order from the user's default locale, inserts reading order marks, and updates the pdwFlags output /// value appropriately. This flag prevents that process from occurring. It is used most commonly by legacy callers of /// SHFormatDateTime. This flag cannot be combined with FDTF_RTLDATE or FDTF_LTRDATE. /// Windows Server 2003 and Windows XP: This value is not available. /// FDTF_NOAUTOREADINGORDER = 0x00000400, } /// /// /// Indicates FILETYPEATTRIBUTEFLAGS constants that are used in the EditFlags value of a file association PROGID registry key. /// /// /// /// /// These flags represent possible attributes stored in the EditFlags value of a ProgID registration. The EditFlags data is a single REG_DWORD. /// /// /// The following example shows the FTA_NoRemove (0x00000010) and FTA_NoNewVerb (0x00000020) attributes /// assigned to the .myp file type. /// /// .myp (Default) = MyProgram.1 MyProgram.1 (Default) = MyProgram Application EditFlags = 0x00000030 /// /// APIs such as IQueryAssociations::GetData can retrieve that EditFlags data. Compare the numerical equivalents of these /// FILETYPEATTRIBUTEFLAGS flags against that retrived value to determine which flags are set. /// /// The following example demonstrates the use of IQueryAssociations::GetData to determine if those values are set. /// /// To set an EditFlags attribute, you can use the RegSetValueEx or SHSetValue functions. First use IQueryAssociations::GetData to /// retrieve the current set of attributes as shown in the example above, add the desired FILETYPEATTRIBUTEFLAGS to that /// value, then write that value back to the registry using one of the two set functions. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-filetypeattributeflags typedef enum FILETYPEATTRIBUTEFLAGS // { FTA_None , FTA_Exclude , FTA_Show , FTA_HasExtension , FTA_NoEdit , FTA_NoRemove , FTA_NoNewVerb , FTA_NoEditVerb , // FTA_NoRemoveVerb , FTA_NoEditDesc , FTA_NoEditIcon , FTA_NoEditDflt , FTA_NoEditVerbCmd , FTA_NoEditVerbExe , FTA_NoDDE , // FTA_NoEditMIME , FTA_OpenIsSafe , FTA_AlwaysUnsafe , FTA_NoRecentDocs , FTA_SafeForElevation , FTA_AlwaysUseDirectInvoke } ; [PInvokeData("shlwapi.h", MSDNShortId = "63b58659-9c4c-4b39-98d1-743724523dcd")] public enum FILETYPEATTRIBUTEFLAGS : uint { /// No FILETYPEATTRIBUTEFLAGS options set. FTA_None = 0x00000000, /// Excludes the file type. FTA_Exclude = 0x00000001, /// Shows file types, such as folders, that are not associated with a file name extension. FTA_Show = 0x00000002, /// Indicates that the file type has a file name extension. FTA_HasExtension = 0x00000004, /// /// Prohibits editing of the registry entries associated with this file type, the addition of new entries, and the deletion or /// modification of existing entries. /// FTA_NoEdit = 0x00000008, /// Prohibits deletion of the registry entries associated with this file type. FTA_NoRemove = 0x00000010, /// Prohibits the addition of new verbs to the file type. FTA_NoNewVerb = 0x00000020, /// Prohibits the modification or deletion of canonical verbs such as open and print. FTA_NoEditVerb = 0x00000040, /// Prohibits the deletion of canonical verbs such as open and print. FTA_NoRemoveVerb = 0x00000080, /// Prohibits the modification or deletion of the description of the file type. FTA_NoEditDesc = 0x00000100, /// Prohibits the modification or deletion of the icon assigned to the file type. FTA_NoEditIcon = 0x00000200, /// Prohibits the modification of the default verb. FTA_NoEditDflt = 0x00000400, /// Prohibits the modification of the commands associated with verbs. FTA_NoEditVerbCmd = 0x00000800, /// Prohibits the modification or deletion of verbs. FTA_NoEditVerbExe = 0x00001000, /// Prohibits the modification or deletion of the entries related to DDE. FTA_NoDDE = 0x00002000, /// Prohibits the modification or deletion of the content type and default extension entries. FTA_NoEditMIME = 0x00008000, /// /// Indicates that the file type's open verb can be safely invoked for downloaded files. This flag applies only to safe file /// types, as identified by AssocIsDangerous. To improve the user experience and reduce unnecessary user prompts when downloading /// and activating items, file type owners should specify this flag and applications that download and activate files should /// respect this flag. /// FTA_OpenIsSafe = 0x00010000, /// /// Prevents the Never ask me check box from being enabled. Use of this flag means FTA_OpenIsSafe is not respected and /// AssocIsDangerous always returns TRUE. If your file type can execute code, you should always use this flag or ensure that the /// file type handlers mitigate risks, for example, by producing warning prompts before running the code. The user can override /// this attribute through the File Type dialog box. /// FTA_AlwaysUnsafe = 0x00020000, /// /// Prohibits the addition of members of this file type to the Recent Documents folder. Additionally, in Windows 7 and later, /// prohibits the addition of members of this file type to the automatic Recent or Frequent category of an application's Jump /// List. This flag does not restrict members of this file type from being added to a custom Jump List. It also places no /// restriction on the file type being added to the automatic Jump Lists of other applications in the case that other /// applications use this file type. /// FTA_NoRecentDocs = 0x00100000, /// /// Introduced in Windows 8. Marks the file as safe to be passed from a low trust application to a full trust application. Files /// that originate from the Internet or an app container are examples where the file is considered untrusted. Untrusted files /// that contain code are especially dangerous, and appropriate security mitigations must be applied if the file is to be opened /// by a full trust application. File type owners for file formats that have the ability to execute code should specify this flag /// only if their program mitigates elevation-of-privilege threats that are associated with running code at a higher integrity /// level. Mitigations include prompting the user before code is executed or executing the code with reduced privileges. By /// specifying this flag for an entire file type, an app running within an app container can pass files of this type to a program /// running at full trust. Some file types are recognized as inherently dangerous due to their ability to execute code and will /// be blocked if you don't specify this value. /// FTA_SafeForElevation = 0x00200000, /// /// Introduced in Windows 8. Ensures that the verbs for the file type are invoked with a URI instead of a downloaded version of /// the file. Use this flag only if you've registered the file type's verb to support DirectInvoke through the SupportedProtocols /// or UseUrl registration. /// FTA_AlwaysUseDirectInvoke = 0x00400000, } /// Return values for [PInvokeData("shlwapi.h", MSDNShortId = "838a255f-413e-424c-819e-47265224208d")] [Flags] public enum GCT : uint { /// The character is not valid in a path. GCT_INVALID = 0x0000, /// The character is valid in a long file name. GCT_LFNCHAR = 0x0001, /// The character is valid in a short (8.3) file name. GCT_SHORTCHAR = 0x0002, /// The character is a wildcard character. GCT_WILD = 0x0004, /// The character is a path separator. GCT_SEPARATOR = 0x0008, } /// Options for . [PInvokeData("shlwapi.h", MSDNShortId = "827a76bc-3581-4f1c-8095-8e2fd30dfdbc")] public enum OS { /// /// The program is running on one of the following versions of Windows: /// /// /// Windows 95 /// /// /// Windows 98 /// /// /// Windows Me /// /// /// /// Equivalent to VER_PLATFORM_WIN32_WINDOWS. Note that none of those systems are supported at this time. OS_WINDOWS returns /// FALSE on all supported systems. /// /// OS_WINDOWS = 0, /// Always returns TRUE. OS_NT = 1, /// Always returns FALSE. OS_WIN95ORGREATER = 2, /// Always returns FALSE. OS_NT4ORGREATER = 3, /// Always returns FALSE. OS_WIN98ORGREATER = 5, /// Always returns FALSE. OS_WIN98_GOLD = 6, /// The program is running on Windows 2000 or one of its successors. OS_WIN2000ORGREATER = 7, /// Do not use; use OS_PROFESSIONAL. OS_WIN2000PRO = 8, /// Do not use; use OS_SERVER. OS_WIN2000SERVER = 9, /// Do not use; use OS_ADVSERVER. OS_WIN2000ADVSERVER = 10, /// Do not use; use OS_DATACENTER. OS_WIN2000DATACENTER = 11, /// /// The program is running on Windows 2000 Terminal Server in either Remote Administration mode or Application Server mode, or /// Windows Server 2003 (or one of its successors) in Terminal Server mode or Remote Desktop for Administration mode. Consider /// using a more specific value such as OS_TERMINALSERVER, OS_TERMINALREMOTEADMIN, or OS_PERSONALTERMINALSERVER. /// OS_WIN2000TERMINAL = 12, /// The program is running on Windows Embedded, any version. Equivalent to VER_SUITE_EMBEDDEDNT. OS_EMBEDDED = 13, /// The program is running as a Terminal Server client. Equivalent to GetSystemMetrics(SM_REMOTESESSION). OS_TERMINALCLIENT = 14, /// /// The program is running on Windows 2000 Terminal Server in the Remote Administration mode or Windows Server 2003 (or /// one of its successors) in the Remote Desktop for Administration mode (these are the default installation modes). This is /// equivalent to VER_SUITE_TERMINAL && VER_SUITE_SINGLEUSERTS. /// OS_TERMINALREMOTEADMIN = 15, /// Always returns FALSE. OS_WIN95_GOLD = 16, /// Always returns FALSE. OS_MEORGREATER = 17, /// Always returns FALSE. OS_XPORGREATER = 18, /// Always returns FALSE. OS_HOME = 19, /// The program is running on Windows NT Workstation or Windows 2000 (or one of its successors) Professional. Equivalent /// to VER_PLATFORM_WIN32_NT && VER_NT_WORKSTATION. OS_PROFESSIONAL = 20, /// The program is running on Windows Datacenter Server or Windows Server Datacenter Edition, any version. Equivalent to /// (VER_NT_SERVER || VER_NT_DOMAIN_CONTROLLER) && VER_SUITE_DATACENTER. OS_DATACENTER = 21, /// The program is running on Windows Advanced Server or Windows Server Enterprise Edition, any version. Equivalent to /// (VER_NT_SERVER || VER_NT_DOMAIN_CONTROLLER) && VER_SUITE_ENTERPRISE && !VER_SUITE_DATACENTER. OS_ADVSERVER = 22, /// /// The program is running on Windows Server (Standard) or Windows Server Standard Edition, any version. This value will not /// return true for VER_SUITE_DATACENTER, VER_SUITE_ENTERPRISE, VER_SUITE_SMALLBUSINESS, or VER_SUITE_SMALLBUSINESS_RESTRICTED. /// OS_SERVER = 23, /// The program is running on Windows 2000 Terminal Server in Application Server mode, or on Windows Server 2003 (or one /// of its successors) in Terminal Server mode. This is equivalent to VER_SUITE_TERMINAL && VER_SUITE_SINGLEUSERTS. OS_TERMINALSERVER = 24, /// The program is running on Windows XP (or one of its successors), Home Edition or Professional. This is equivalent to /// VER_SUITE_SINGLEUSERTS && !VER_SUITE_TERMINAL. OS_PERSONALTERMINALSERVER = 25, /// Fast user switching is enabled. OS_FASTUSERSWITCHING = 26, /// Always returns FALSE. OS_WELCOMELOGONUI = 27, /// The computer is joined to a domain. OS_DOMAINMEMBER = 28, /// The program is running on any Windows Server product. Equivalent to VER_NT_SERVER || VER_NT_DOMAIN_CONTROLLER. OS_ANYSERVER = 29, /// The program is a 32-bit program running on 64-bit Windows. OS_WOW6432 = 30, /// Always returns FALSE. OS_WEBSERVER = 31, /// /// The program is running on Microsoft Small Business Server with restrictive client license in force. Equivalent to VER_SUITE_SMALLBUSINESS_RESTRICTED. /// OS_SMALLBUSINESSSERVER = 32, /// The program is running on Windows XP Tablet PC Edition, or one of its successors. OS_TABLETPC = 33, /// /// The user should be presented with administrator UI. It is possible to have server administrative UI on a non-server machine. /// This value informs the application that an administrator's profile has roamed to a non-server, and UI should be appropriate /// to an administrator. Otherwise, the user is shown a mix of administrator and nonadministrator settings. /// OS_SERVERADMINUI = 34, /// The program is running on Windows XP Media Center Edition, or one of its successors. Equivalent to GetSystemMetrics(SM_MEDIACENTER). OS_MEDIACENTER = 35, /// The program is running on Windows Appliance Server. OS_APPLIANCE = 36, } /// The flags to control the operation of SHAutoComplete. [PInvokeData("shlwapi.h", MSDNShortId = "b47efa8d-2118-4805-bb04-97bd143228dc")] [Flags] public enum SHACF : uint { /// /// Ignore the registry default and force the AutoAppend feature off. This flag must be used in combination with one or more of /// the SHACF_FILESYS* or SHACF_URL* flags. /// SHACF_AUTOAPPEND_FORCE_OFF = 0x80000000, /// /// Ignore the registry value and force the AutoAppend feature on. The completed string will be displayed in the edit box with /// the added characters highlighted. This flag must be used in combination with one or more of the SHACF_FILESYS* or SHACF_URL* flags. /// SHACF_AUTOAPPEND_FORCE_ON = 0x40000000, /// /// Ignore the registry default and force the AutoSuggest feature off. This flag must be used in combination with one or more of /// the SHACF_FILESYS* or SHACF_URL* flags. /// SHACF_AUTOSUGGEST_FORCE_OFF = 0x20000000, /// /// Ignore the registry value and force the AutoSuggest feature on. A selection of possible completed strings will be displayed /// as a drop-down list, below the edit box. This flag must be used in combination with one or more of the SHACF_FILESYS* or /// SHACF_URL* flags. /// SHACF_AUTOSUGGEST_FORCE_ON = 0x10000000, /// /// The default setting, equivalent to SHACF_FILESYSTEM | SHACF_URLALL. SHACF_DEFAULT cannot be combined with any other flags. /// SHACF_DEFAULT = 0x00000000, /// Include the file system only. SHACF_FILESYS_ONLY = 0x00000010, /// Include the file system and directories, UNC servers, and UNC server shares. SHACF_FILESYS_DIRS = 0x00000020, /// Include the file system and the rest of the Shell (Desktop, Computer, and Control Panel, for example). SHACF_FILESYSTEM = 0x00000001, /// Include the URLs in the users History and Recently Used lists. Equivalent to SHACF_URLHISTORY | SHACF_URLMRU. SHACF_URLALL = (SHACF_URLHISTORY | SHACF_URLMRU), /// Include the URLs in the user's History list. SHACF_URLHISTORY = 0x00000002, /// Include the URLs in the user's Recently Used list. SHACF_URLMRU = 0x00000004, /// /// Allow the user to select from the autosuggest list by pressing the TAB key. If this flag is not set, pressing the TAB key /// will shift focus to the next control and close the autosuggest list. If SHACF_USETAB is set, pressing the TAB key will select /// the first item in the list. Pressing TAB again will select the next item in the list, and so on. When the user reaches the /// end of the list, the next TAB key press will cycle the focus back to the edit control. This flag must be used in combination /// with one or more of the SHACF_FILESYS* or SHACF_URL* flags listed on this page. /// SHACF_USETAB = 0x00000008, /// Also include the virtual namespace SHACF_VIRTUAL_NAMESPACE = 0x00000040 } /// /// /// Flags that control the calling function's behavior. Used by SHCreateThread and SHCreateThreadWithHandle. In those /// functions, these values are defined as being of type SHCT_FLAGS. /// /// /// /// /// Constant/value /// Description /// /// /// CTF_INSIST0x00000001 /// /// 0x00000001. If the attempt to create the thread with CreateThread fails, setting this flag will cause the function pointed to by /// pfnThreadProc to be called synchronously from the calling thread. This flag can be used only if pfnCallback is NULL. /// /// /// /// CTF_THREAD_REF0x00000002 /// /// 0x00000002. Hold a reference to the creating thread for the duration of the call to the function pointed to by pfnThreadProc. /// This reference must have been set with SHSetThreadRef. /// /// /// /// CTF_PROCESS_REF0x00000004 /// /// 0x00000004. Hold a reference to the Windows Explorer process for the duration of the call to the function pointed to by /// pfnThreadProc. This flag is useful for Shell extension handlers, which might need to keep the Windows Explorer process from /// closing prematurely. This action is useful during tasks such as working on a background thread or copying files. For more /// information, see SHGetInstanceExplorer. /// /// /// /// CTF_COINIT_STA0x00000008 /// /// 0x00000008. Initialize COM as a Single Threaded Apartment (STA) for the created thread before calling either the optional /// function pointed to by pfnCallback or the function pointed to by pfnThreadProc. This flag is useful when COM needs to be /// initialized for a thread. COM will automatically be uninitialized as well. /// /// /// /// CTF_COINIT0x00000008 /// Equivalent to CTF_COINIT_STA. /// /// /// CTF_FREELIBANDEXIT0x00000010 /// /// 0x00000010. Internet Explorer 6 or later.LoadLibrary will be called on the DLL that contains the pfnThreadProc function to /// prevent it from being unloaded. After pfnThreadProc returns, the DLL will be freed with FreeLibrary, thereby decrementing the DLL /// reference count. Pass this flag to prevent the DLL from being unloaded prematurely; for example, by CoFreeUnusedLibraries. Note /// that if this flag is passed, the pfnThreadProc function must reside in a DLL. This flag is implicit in Windows Vista and later. /// /// /// /// CTF_REF_COUNTED0x00000020 /// /// 0x00000020. Internet Explorer 6 or later. A thread reference will automatically be created for the created thread and set with /// SHSetThreadRef. After the pfnThreadProc returns, the thread reference is released and messages are sent until the reference count /// on the thread reference drops to zero, that is, until threads that are dependent on the created thread have released their references. /// /// /// /// CTF_WAIT_ALLOWCOM0x00000040 /// /// 0x00000040. Internet Explorer 6 or later. The calling thread waits and pumps COM and SendMessage messages. If the synchronous /// procedure attempts to send a Windows message with SendMessage to a window hosted on the calling thread, the message will arrive /// successfully. If the synchronous procedure attempts to use COM to communicate with an STA object hosted on the calling thread, /// the function call will successfully reach the intended object. The calling thread is open to re-entrance fragility. While the /// calling thread can handle the synchronous procedure's use of SendMessage and COM, if other threads are using SendMessage or COM /// to communicate to objects hosted on the calling thread, then these might be unexpected messages or function calls which are /// processed while the synchronous procedure is completing. /// /// /// /// CTF_UNUSED0x00000080 /// 0x00000080. Internet Explorer 7 or later. Not used. /// /// /// CTF_INHERITWOW640x00000100 /// /// 0x00000100. Internet Explorer 7 or later. The new thread inherits the Windows-on-Windows 64-bit (WOW64) disable state for the /// file system redirector. /// /// /// /// CTF_WAIT_NO_REENTRANCY0x00000200 /// /// 0x00000200. Windows Vista or later. The calling thread blocks all other processes while waiting for the synchronous procedure to /// run on the new thread. If the synchronous procedure attempts to send a Windows message with SendMessage to a window hosted on the /// calling thread, this causes the synchronous procedure to deadlock. If the synchronous procedure attempts to use COM to talk to an /// STA object hosted on the calling thread, this also causes the synchronous procedure to deadlock. The calling thread is protected /// from all re-entrance concerns by specifying this flag. /// /// /// /// CTF_KEYBOARD_LOCALE0x00000400 /// 0x00000400. Windows 7 or later. Use the keyboard locale from the original thread in the new thread that it spawns. /// /// /// CTF_OLEINITIALIZE0x00000800 /// 0x00000800. Windows 7 or later. Initialize COM with the single-threaded apartment (STA) model for the created thread. /// /// /// CTF_COINIT_MTA0x00001000 /// 0x00001000. Windows 7 and later. Initialize COM with the multithreaded apartment (MTA) model for the created thread. /// /// /// CTF_NOADDREFLIB0x00002000 /// /// 0x00002000. Windows 7 or later. This flag is essentially the opposite of CTF_FREELIBANDEXIT. This avoids /// LoadLibrary/FreeLibraryAndExitThread calls that can result in contention for the loader lock. Use CTF_NOADDREFLIB only when the /// new thread has means to ensure that the code of the original thread procedure will remain loaded. This value should not be used /// in the context of COM objects, because COM objects must ensure that the DLL stays loaded (normally, COM unloads the DLLs). /// /// /// /// /// /// // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762495(v=vs.85).aspx [PInvokeData("Shlwapi.h", MSDNShortId = "bb762495")] [Flags] public enum SHCT_FLAGS { /// /// If the attempt to create the thread with CreateThread fails, setting this flag will cause the function pointed to by /// pfnThreadProc to be called synchronously from the calling thread. This flag can be used only if pfnCallback is NULL. /// CTF_INSIST = 0x00000001, /// /// Hold a reference to the creating thread for the duration of the call to the function pointed to by pfnThreadProc. This /// reference must have been set with SHSetThreadRef. /// CTF_THREAD_REF = 0x00000002, /// /// Hold a reference to the Windows Explorer process for the duration of the call to the function pointed to by pfnThreadProc. /// This flag is useful for Shell extension handlers, which might need to keep the Windows Explorer process from closing /// prematurely. This action is useful during tasks such as working on a background thread or copying files. For more /// information, see SHGetInstanceExplorer. /// CTF_PROCESS_REF = 0x00000004, /// /// Initialize COM as a Single Threaded Apartment (STA) for the created thread before calling either the optional function /// pointed to by pfnCallback or the function pointed to by pfnThreadProc. This flag is useful when COM needs to be initialized /// for a thread. COM will automatically be uninitialized as well. /// CTF_COINIT_STA = 0x00000008, /// Equivalent to CTF_COINIT_STA. CTF_COINIT = 0x00000008, /// /// Internet Explorer 6 or later. LoadLibrary will be called on the DLL that contains the pfnThreadProc function to prevent it /// from being unloaded. After pfnThreadProc returns, the DLL will be freed with FreeLibrary, thereby decrementing the DLL /// reference count. Pass this flag to prevent the DLL from being unloaded prematurely; for example, by CoFreeUnusedLibraries. /// Note that if this flag is passed, the pfnThreadProc function must reside in a DLL. This flag is implicit in Windows Vista and later. /// CTF_FREELIBANDEXIT = 0x00000010, /// /// Internet Explorer 6 or later. A thread reference will automatically be created for the created thread and set with /// SHSetThreadRef. After the pfnThreadProc returns, the thread reference is released and messages are sent until the reference /// count on the thread reference drops to zero, that is, until threads that are dependent on the created thread have released /// their references. /// CTF_REF_COUNTED = 0x00000020, /// /// Internet Explorer 6 or later. The calling thread waits and pumps COM and SendMessage messages. If the synchronous procedure /// attempts to send a Windows message with SendMessage to a window hosted on the calling thread, the message will arrive /// successfully. If the synchronous procedure attempts to use COM to communicate with an STA object hosted on the calling /// thread, the function call will successfully reach the intended object. The calling thread is open to re-entrance fragility. /// While the calling thread can handle the synchronous procedure's use of SendMessage and COM, if other threads are using /// SendMessage or COM to communicate to objects hosted on the calling thread, then these might be unexpected messages or /// function calls which are processed while the synchronous procedure is completing. /// CTF_WAIT_ALLOWCOM = 0x00000040, /// Internet Explorer 7 or later. Not used. CTF_UNUSED = 0x00000080, /// /// Internet Explorer 7 or later. The new thread inherits the Windows-on-Windows 64-bit (WOW64) disable state for the file system redirector. /// CTF_INHERITWOW64 = 0x00000100, /// /// Windows Vista or later. The calling thread blocks all other processes while waiting for the synchronous procedure to run on /// the new thread. If the synchronous procedure attempts to send a Windows message with SendMessage to a window hosted on the /// calling thread, this causes the synchronous procedure to deadlock. If the synchronous procedure attempts to use COM to talk /// to an STA object hosted on the calling thread, this also causes the synchronous procedure to deadlock. The calling thread is /// protected from all re-entrance concerns by specifying this flag. /// CTF_WAIT_NO_REENTRANCY = 0x00000200, /// Windows 7 or later. Use the keyboard locale from the original thread in the new thread that it spawns. CTF_KEYBOARD_LOCALE = 0x00000400, /// Windows 7 or later. Initialize COM with the single-threaded apartment (STA) model for the created thread. CTF_OLEINITIALIZE = 0x00000800, /// Windows 7 and later. Initialize COM with the multithreaded apartment (MTA) model for the created thread. CTF_COINIT_MTA = 0x00001000, /// /// Windows 7 or later. This flag is essentially the opposite of CTF_FREELIBANDEXIT. This avoids LoadLibrary/ /// FreeLibraryAndExitThread calls that can result in contention for the loader lock. Use CTF_NOADDREFLIB only when the new /// thread has means to ensure that the code of the original thread procedure will remain loaded. This value should not be used /// in the context of COM objects, because COM objects must ensure that the DLL stays loaded (normally, COM unloads the DLLs). /// CTF_NOADDREFLIB = 0x00002000, } /// Value that indicates the type of Shell32.dll that the platform contains. [PInvokeData("shlwapi.h", MSDNShortId = "14af733b-81b4-40a2-b93b-6f387b181f12")] public enum SHELLPLATFORM { /// The function was unable to determine the Shell32.dll version. PLATFORM_UNKNOWN = 0, /// Obsolete: Use PLATFORM_BROWSERONLY. PLATFORM_IE3 = 1, /// The Shell32.dll version is browser-only, with no new shell. PLATFORM_BROWSERONLY = 1, /// The platform contains an integrated shell. PLATFORM_INTEGRATED = 2, } /// Flags used by . [PInvokeData("shlwapi.h", MSDNShortId = "6852867a-30a5-4d4e-b790-3746104e3ed8")] [Flags] public enum SHGVSPB : uint { /// Returns the per-user properties for the specified pidl. SHGVSPB_PERUSER = 0x00000001, /// /// Returns the All User properties for the specified pidl. /// One value from the following set of flags is required. /// SHGVSPB_ALLUSERS = 0x00000002, /// Returns the property bag for the folder specified by the pidl parameter. SHGVSPB_PERFOLDER = 0x00000004, /// Returns the property bag that applies to all folders. SHGVSPB_ALLFOLDERS = 0x00000008, /// /// Returns the property bag used to provide defaults for subfolders that do not have their property bag. /// The following flags are optional. /// SHGVSPB_INHERIT = 0x00000010, /// Allows the property bag to roam. See Roaming User Profiles. This flag cannot be combined with SHGVSPB_ALLFOLDERS. SHGVSPB_ROAM = 0x00000020, /// /// Suppresses the search for a suitable default when the property bag cannot be found for the specified folder. By default, if /// SHGVSPB_INHERIT is not specified and a property bag cannot be found for the specified folder, the system searches for /// identically named property bags in other locations that may be able to provide default values. For example, the system /// searches in the ancestors of the folder to see if any of them provide a SHGVSPB_INHERIT property bag. Other places the system /// searches are in the user defaults and the global defaults. /// The following set of flags consists of values that combine some flags listed above, and are used for brevity and convenience. /// SHGVSPB_NOAUTODEFAULTS = 0x80000000, /// Combines SHGVSPB_PERUSER and SHGVSPB_PERFOLDER. SHGVSPB_FOLDER = (SHGVSPB_PERUSER | SHGVSPB_PERFOLDER), /// Combines SHGVSPB_PERUSER, SHGVSPB_PERFOLDER, and SHGVSPB_NOAUTODEFAULTS. SHGVSPB_FOLDERNODEFAULTS = (SHGVSPB_PERUSER | SHGVSPB_PERFOLDER | SHGVSPB_NOAUTODEFAULTS), /// Combines SHGVSPB_PERUSER and SHGVSPB_ALLFOLDERS. SHGVSPB_USERDEFAULTS = (SHGVSPB_PERUSER | SHGVSPB_ALLFOLDERS), /// /// Combines SHGVSPB_ALLUSERS and SHGVSPB_ALLFOLDERS. /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is named SHGVSPB_GLOBALDEAFAULTS. /// SHGVSPB_GLOBALDEFAULTS = (SHGVSPB_ALLUSERS | SHGVSPB_ALLFOLDERS), } /// /// Provides a set of values that indicate from which base key an item will be deleted. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-shregdel_flags typedef enum SHREGDEL_FLAGS { // SHREGDEL_DEFAULT , SHREGDEL_HKCU , SHREGDEL_HKLM , SHREGDEL_BOTH } ; [PInvokeData("shlwapi.h", MSDNShortId = "90a8bf22-f62b-4027-8219-7a5ead6577da")] [Flags] public enum SHREGDEL_FLAGS { /// Deletes from HKEY_CURRENT_USER. If the specified item is not found under HKEY_CURRENT_USER, deletes from HKEY_LOCAL_MACHINE. SHREGDEL_DEFAULT = 0x00000000, /// Enumerates from HKEY_CURRENT_USER only. SHREGDEL_HKCU = 0x00000001, /// Enumerates under HKEY_LOCAL_MACHINE only. SHREGDEL_HKLM = 0x00000010, /// Deletes from both HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE. SHREGDEL_BOTH = 0x00000011, } /// /// Provides a set of values that indicate the base key that will be used for an enumeration. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ne-shlwapi-shregenum_flags typedef enum SHREGENUM_FLAGS { // SHREGENUM_DEFAULT , SHREGENUM_HKCU , SHREGENUM_HKLM , SHREGENUM_BOTH } ; [PInvokeData("shlwapi.h", MSDNShortId = "4216a983-9d53-44b1-8273-e5a90ac4b3ef")] public enum SHREGENUM_FLAGS { /// /// Enumerates under HKEY_CURRENT_USER, or, if the specified item is not found in HKEY_CURRENT_USER, enumerates under HKEY_LOCAL_MACHINE. /// SHREGENUM_DEFAULT = 0x00000000, /// Enumerates under HKEY_CURRENT_USER only. SHREGENUM_HKCU = 0x00000001, /// Enumerates under HKEY_LOCAL_MACHINE only. SHREGENUM_HKLM = 0x00000010, /// Not used. SHREGENUM_BOTH = 0x00000011, } /// Flags used by . [PInvokeData("shlwapi.h", MSDNShortId = "10e3e31e-bff6-4260-95fa-2d750de16ab3")] [Flags] public enum SHREGSET { /// /// Create/open the key under both HKEY_CURRENT_USER (forced) and HKEY_LOCAL_MACHINE (only if empty). This flag is /// the equivalent of ( SHREGSET_FORCE_HKCU | SHREGSET_HKLM). /// SHREGSET_DEFAULT = (SHREGSET_FORCE_HKCU | SHREGSET_HKLM), /// Create/open the key under HKEY_CURRENT_USER. Only creates a key if it is empty. SHREGSET_HKCU = 0x00000001, /// Create/open the key under HKEY_CURRENT_USER. Creates a key even if it is not empty. SHREGSET_FORCE_HKCU = 0x00000002, /// Create/open the key under HKEY_LOCAL_MACHINE. Only creates a key if it is empty. SHREGSET_HKLM = 0x00000004, /// Create/open the key under HKEY_LOCAL_MACHINE. Creates a key even if it is not empty. SHREGSET_FORCE_HKLM = 0x00000008, } /// Flags that restrict the data to be set or returned. // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762547(v=vs.85).aspx [PInvokeData("Shlwapi.h", MSDNShortId = "bb762547")] [Flags] public enum SRRF : uint { /// Type REG_NONE. SRRF_RT_REG_NONE = 0x00000001, /// Type REG_SZ. REG_EXPAND_SZ types are automatically converted to REG_SZ unless the SRRF_NOEXPAND flag is specified. SRRF_RT_REG_SZ = 0x00000002, /// /// Type REG_EXPAND_SZ. If retrieving a value, you must also get the SRRF_NOEXPAND flag, or SHRegGetValue fails with ERROR_INVALID_PARAMETER. /// SRRF_RT_REG_EXPAND_SZ = 0x00000004, /// Type REG_BINARY. SRRF_RT_REG_BINARY = 0x00000008, /// Type REG_DWORD. SRRF_RT_REG_DWORD = 0x00000010, /// Type REG_MULTI_SZ. SRRF_RT_REG_MULTI_SZ = 0x00000020, /// Type REG_QWORD. SRRF_RT_REG_QWORD = 0x00000040, /// /// REG_DWORD and 32-bit REG_BINARY types. This is equivalent to SRRF_RT_REG_BINARY | SRRF_RT_REG_DWORD. If retrieving a value, /// if the value's binary data is larger than 32 bits, it is not returned. /// SRRF_RT_DWORD = 0x00000018, /// /// REG_QWORD and 64-bit REG_BINARY types. This is equivalent to SRRF_RT_REG_BINARY | SRRF_RT_REG_QWORD. If retrieving a value, /// if the value's binary data is larger than 64 bits, it is not returned. /// SRRF_RT_QWORD = 0x00000048, /// All types. Set this flag if no other SRRF_RT value is set. SRRF_RT_ANY = 0x0000FFFF, /// No mode restriction. This is the default value. SRRF_RM_ANY = 0x00000000, /// Restrict system startup mode to "normal boot". SRRF_RM_NORMAL = 0x00010000, /// Restrict system startup mode to "safe mode". SRRF_RM_SAFE = 0x00020000, /// Restrict system startup mode to "safe mode with networking". SRRF_RM_SAFENETWORK = 0x00040000, /// Do not automatically expand REG_EXPAND_SZ environment strings. SRRF_NOEXPAND = 0x10000000, /// If retrieving a value, if pvData is not NULL, set the contents of the pvData buffer to all zeros on failure. SRRF_ZEROONFAILURE = 0x20000000, /// When retrieving a value, if the requested key is virtualized, fail with ERROR_FILE_NOT_FOUND. SRRF_NOVIRT = 0x40000000, } /// /// Performs a comparison between two characters. The comparison is not case-sensitive. /// /// /// Type: TCHAR /// The first character to be compared. /// /// /// Type: TCHAR /// The second character to be compared. /// /// /// Type: BOOL /// Returns zero if the two characters are the same, or nonzero otherwise. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-chrcmpia BOOL ChrCmpIA( WORD w1, WORD w2 ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "ae2f3cbf-c65b-41a4-8d59-39d6fadf40ca")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ChrCmpI(ushort w1, ushort w2); /// /// Changes the luminance of a RGB value. Hue and saturation are not affected. /// /// /// Type: COLORREF /// The initial RGB value. /// /// /// Type: int /// /// The luminance in units of 0.1 percent of the total range. For example, a value of n = 50 corresponds to 5 percent of the maximum luminance. /// /// /// /// Type: BOOL /// /// If fScale is set to TRUE, n specifies how much to increment or decrement the current luminance. If fScale is set to /// FALSE, n specifies the absolute luminance. /// /// /// /// Type: COLORREF /// Returns the modified RGB value. /// /// /// If fScale is set to TRUE, n can range from -1000 to +1000. /// /// If fScale is set to FALSE, n can range from 0 to 1000. Available luminance values range from 0 to a maximum. If the /// requested value is negative or exceeds the maximum, the luminance will be set to either zero or the maximum value, respectively. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-coloradjustluma COLORREF ColorAdjustLuma( COLORREF clrRGB, // int n, BOOL fScale ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "d113ad59-cde4-4f11-b7f1-53b3fb69ec10")] public static extern COLORREF ColorAdjustLuma(COLORREF clrRGB, int n, [MarshalAs(UnmanagedType.Bool)] bool fScale); /// /// Converts colors from hue-luminance-saturation (HLS) to RGB format. /// /// /// Type: WORD /// The original HLS hue value. /// /// /// Type: WORD /// The original HLS luminance value. /// /// /// Type: WORD /// The original HLS saturation value. /// /// /// Type: COLORREF /// Returns the RGB value. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-colorhlstorgb COLORREF ColorHLSToRGB( WORD wHue, WORD // wLuminance, WORD wSaturation ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "1bf0b337-01de-4ce3-851f-d845866fb46f")] public static extern COLORREF ColorHLSToRGB(ushort wHue, ushort wLuminance, ushort wSaturation); /// /// Converts colors from RGB to hue-luminance-saturation (HLS) format. /// /// /// Type: COLORREF /// The original RGB color. /// /// /// Type: WORD* /// A pointer to a value that, when this method returns successfully, receives the HLS hue value. /// /// /// Type: WORD* /// A pointer to a value that, when this method returns successfully, receives the HLS luminance value. /// /// /// Type: WORD* /// A pointer to a value that, when this method returns successfully, receives the HLS saturation value. /// /// /// This function does not return a value. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-colorrgbtohls void ColorRGBToHLS( COLORREF clrRGB, WORD // *pwHue, WORD *pwLuminance, WORD *pwSaturation ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "ed000f53-cc7e-4693-994c-a5dd7c789f1f")] public static extern void ColorRGBToHLS(COLORREF clrRGB, out ushort pwHue, out ushort pwLuminance, out ushort pwSaturation); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Establishes or terminates a connection between a client's sink and a connection point container. /// /// /// Type: IUnknown* /// /// A pointer to the IUnknown interface of the object to be connected to the connection point container. If you set fConnect to /// FALSE to indicate that you are disconnecting the object, this parameter is ignored and can be set to NULL. /// /// /// /// Type: REFIID /// The IID of the interface on the connection point container whose connection point object is being requested. /// /// /// Type: BOOL /// TRUE if a connection is being established; FALSE if a connection is being broken. /// /// /// Type: IUnknown* /// A pointer to the connection point container's IUnknown interface. /// /// /// Type: DWORD* /// /// A connection token. If you set fConnect to TRUE to make a new connection, this parameter receives a token that uniquely /// identifies the connection. If you set fConnect to FALSE to break a connection, this parameter must point to the token that /// you received when you called ConnectToConnectionPoint to establish the connection. /// /// /// /// Type: IConnectionPoint** /// /// A pointer to the connection point container's IConnectionPoint interface, if the operation was successful. The calling /// application must release this pointer when it is no longer needed. If the request is unsuccessful, the pointer receives /// NULL. This parameter is optional and can be NULL. /// /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-connecttoconnectionpoint LWSTDAPI // ConnectToConnectionPoint( IUnknown *punk, REFIID riidEvent, BOOL fConnect, IUnknown *punkTarget, DWORD *pdwCookie, // IConnectionPoint **ppcpOut ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f0c6051e-cced-4f38-a35d-d4c184d39084")] public static extern HRESULT ConnectToConnectionPoint([In, Optional, MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid riidEvent, [MarshalAs(UnmanagedType.Bool)] bool fConnect, [In, MarshalAs(UnmanagedType.IUnknown)] object punkTarget, ref uint pdwCookie, out IConnectionPoint ppcpOut); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Establishes or terminates a connection between a client's sink and a connection point container. /// /// /// Type: IUnknown* /// /// A pointer to the IUnknown interface of the object to be connected to the connection point container. If you set fConnect to /// FALSE to indicate that you are disconnecting the object, this parameter is ignored and can be set to NULL. /// /// /// /// Type: REFIID /// The IID of the interface on the connection point container whose connection point object is being requested. /// /// /// Type: BOOL /// TRUE if a connection is being established; FALSE if a connection is being broken. /// /// /// Type: IUnknown* /// A pointer to the connection point container's IUnknown interface. /// /// /// Type: DWORD* /// /// A connection token. If you set fConnect to TRUE to make a new connection, this parameter receives a token that uniquely /// identifies the connection. If you set fConnect to FALSE to break a connection, this parameter must point to the token that /// you received when you called ConnectToConnectionPoint to establish the connection. /// /// /// /// Type: IConnectionPoint** /// /// A pointer to the connection point container's IConnectionPoint interface, if the operation was successful. The calling /// application must release this pointer when it is no longer needed. If the request is unsuccessful, the pointer receives /// NULL. This parameter is optional and can be NULL. /// /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-connecttoconnectionpoint LWSTDAPI // ConnectToConnectionPoint( IUnknown *punk, REFIID riidEvent, BOOL fConnect, IUnknown *punkTarget, DWORD *pdwCookie, // IConnectionPoint **ppcpOut ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f0c6051e-cced-4f38-a35d-d4c184d39084")] public static extern HRESULT ConnectToConnectionPoint([In, Optional, MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid riidEvent, [MarshalAs(UnmanagedType.Bool)] bool fConnect, [In, MarshalAs(UnmanagedType.IUnknown)] object punkTarget, ref uint pdwCookie, IntPtr ppcpOut = default); /// /// Retrieves a string used with websites when specifying language preferences. /// /// /// Type: LPTSTR /// /// A pointer to a string that, when this function returns successfully, receives the language preferences information. We recommend /// that this buffer be of size 2048 characters to ensure sufficient space to return the full string. You can also call this function /// with this parameter set to NULL to retrieve the size of the string that will be returned. /// /// /// /// Type: DWORD* /// A pointer to the size, in characters, of the string at pszLanguages. /// On entry, this value is the size of pszLanguages, including the terminating null character. /// On exit, it is the actual size of pszLanguages, not including the terminating null character. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// For those versions of Windows that do not include GetAcceptLanguages in Shlwapi.h, this function's individual ANSI or /// Unicode version must be called directly from Shlwapi.dll. GetAcceptLanguagesA is ordinal 14 and GetAcceptLanguagesW /// is ordinal 15. /// /// /// Some websites offer content in multiple languages. You can specify your language preferences in the Internet Options item in /// Control Panel. GetAcceptLanguages retrieves a string that represents those preferences. That string is sent in an /// additional language header when negotiating HTTP connections. /// /// /// Note If your app or service passes language tags from this function to any National Language Support functions, or to /// Microsoft .NET, it must first convert the tags through the ResolveLocaleName function. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-getacceptlanguagesa LWSTDAPI GetAcceptLanguagesA( LPSTR // pszLanguages, DWORD *pcchLanguages ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "a680a7fd-f980-485d-b52a-eb4d482ebc17")] public static extern HRESULT GetAcceptLanguages(StringBuilder pszLanguages, ref uint pcchLanguages); /// /// /// [ GetMenuPosFromID is available for use in the operating systems specified in the Requirements section. It may be altered /// or unavailable in subsequent versions.] /// /// Determines the position of an item in a menu. Used in the case where the item's ID is known. /// /// /// Type: HMENU /// The handle of the menu. /// /// /// Type: UINT /// An application-defined 16-bit value that identifies the menu item. /// /// /// Type: int /// The item's zero-based position in the menu. /// /// /// Beginning with Windows Vista, this function is declared in Shlwapi.h. /// Windows XP: This function is declared in Shlwapi.dll. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-getmenuposfromid int GetMenuPosFromID( HMENU hmenu, UINT // id ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "25fb51bc-9b36-4afb-bb07-7bc455c7fbc4")] public static extern int GetMenuPosFromID(HMENU hmenu, uint id); /// /// Hashes an array of data. /// /// /// Type: BYTE* /// A pointer to the data array. /// /// /// Type: DWORD /// The number of elements in the array at pbData. /// /// /// Type: BYTE* /// A pointer to a value that, when this function returns successfully, receives the hashed array. /// /// /// Type: DWORD /// The number of elements in pbHash. It should be no larger than 256. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-hashdata LWSTDAPI HashData( BYTE *pbData, DWORD cbData, // BYTE *pbHash, DWORD cbHash ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "7b42b3ae-c021-49be-b5a7-d3bc0a5d346a")] public static extern HRESULT HashData(IntPtr pbData, uint cbData, IntPtr pbHash, uint cbHash); /// /// Determines whether a character represents a space. /// /// /// Type: TCHAR /// A single character. /// /// /// Type: BOOL /// Returns TRUE if the character is a space; otherwise, FALSE. /// /// /// /// For those versions of Windows that do not include IsCharSpace in Shlwapi.h, IsCharSpaceW must be called directly /// from Shlwapi.dll (ordinal 29), using a WCHAR in the wch parameter. IsCharSpaceA is not available in versions of Windows /// that do not include IsCharSpace in Shlwapi.h. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-ischarspacew BOOL IsCharSpaceW( WCHAR wch ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "40ccde4d-38e8-4c03-a826-b6c060037ae5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsCharSpace(char wch); /// /// Determines whether Windows Internet Explorer is in the Enhanced Security Configuration. /// /// /// Type: BOOL /// Returns TRUE if Internet Explorer is in the Enhanced Security Configuration, and FALSE otherwise. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-isinternetescenabled BOOL IsInternetESCEnabled( ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "2f803b69-9734-484c-9392-a48e116cf506")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsInternetESCEnabled(); /// /// Checks for specified operating systems and operating system features. /// /// /// Type: DWORD /// /// A value that specifies which operating system or operating system feature to check for. One of the following values (you cannot /// combine values). /// /// /// /// Name /// Value /// Description /// /// /// OS_WINDOWS /// 0 /// /// The program is running on one of the following versions of Windows: Equivalent to VER_PLATFORM_WIN32_WINDOWS. Note that none of /// those systems are supported at this time. OS_WINDOWS returns FALSE on all supported systems. /// /// /// /// OS_NT /// 1 /// Always returns TRUE. /// /// /// OS_WIN95ORGREATER /// 2 /// Always returns FALSE. /// /// /// OS_NT4ORGREATER /// 3 /// Always returns FALSE. /// /// /// OS_WIN98ORGREATER /// 5 /// Always returns FALSE. /// /// /// OS_WIN98_GOLD /// 6 /// Always returns FALSE. /// /// /// OS_WIN2000ORGREATER /// 7 /// The program is running on Windows 2000 or one of its successors. /// /// /// OS_WIN2000PRO /// 8 /// Do not use; use OS_PROFESSIONAL. /// /// /// OS_WIN2000SERVER /// 9 /// Do not use; use OS_SERVER. /// /// /// OS_WIN2000ADVSERVER /// 10 /// Do not use; use OS_ADVSERVER. /// /// /// OS_WIN2000DATACENTER /// 11 /// Do not use; use OS_DATACENTER. /// /// /// OS_WIN2000TERMINAL /// 12 /// /// The program is running on Windows 2000 Terminal Server in either Remote Administration mode or Application Server mode, or /// Windows Server 2003 (or one of its successors) in Terminal Server mode or Remote Desktop for Administration mode. Consider using /// a more specific value such as OS_TERMINALSERVER, OS_TERMINALREMOTEADMIN, or OS_PERSONALTERMINALSERVER. /// /// /// /// OS_EMBEDDED /// 13 /// The program is running on Windows Embedded, any version. Equivalent to VER_SUITE_EMBEDDEDNT. /// /// /// OS_TERMINALCLIENT /// 14 /// The program is running as a Terminal Server client. Equivalent to GetSystemMetrics(SM_REMOTESESSION). /// /// /// OS_TERMINALREMOTEADMIN /// 15 /// /// The program is running on Windows 2000 Terminal Server in the Remote Administration mode or Windows Server 2003 (or one of its /// successors) in the Remote Desktop for Administration mode (these are the default installation modes). This is equivalent to /// VER_SUITE_TERMINAL && VER_SUITE_SINGLEUSERTS. /// /// /// /// OS_WIN95_GOLD /// 16 /// Always returns FALSE. /// /// /// OS_MEORGREATER /// 17 /// Always returns FALSE. /// /// /// OS_XPORGREATER /// 18 /// Always returns FALSE. /// /// /// OS_HOME /// 19 /// Always returns FALSE. /// /// /// OS_PROFESSIONAL /// 20 /// /// The program is running on Windows NT Workstation or Windows 2000 (or one of its successors) Professional. Equivalent to /// VER_PLATFORM_WIN32_NT && VER_NT_WORKSTATION. /// /// /// /// OS_DATACENTER /// 21 /// /// The program is running on Windows Datacenter Server or Windows Server Datacenter Edition, any version. Equivalent to /// (VER_NT_SERVER || VER_NT_DOMAIN_CONTROLLER) && VER_SUITE_DATACENTER. /// /// /// /// OS_ADVSERVER /// 22 /// /// The program is running on Windows Advanced Server or Windows Server Enterprise Edition, any version. Equivalent to (VER_NT_SERVER /// || VER_NT_DOMAIN_CONTROLLER) && VER_SUITE_ENTERPRISE && !VER_SUITE_DATACENTER. /// /// /// /// OS_SERVER /// 23 /// /// The program is running on Windows Server (Standard) or Windows Server Standard Edition, any version. This value will not return /// true for VER_SUITE_DATACENTER, VER_SUITE_ENTERPRISE, VER_SUITE_SMALLBUSINESS, or VER_SUITE_SMALLBUSINESS_RESTRICTED. /// /// /// /// OS_TERMINALSERVER /// 24 /// /// The program is running on Windows 2000 Terminal Server in Application Server mode, or on Windows Server 2003 (or one of its /// successors) in Terminal Server mode. This is equivalent to VER_SUITE_TERMINAL && VER_SUITE_SINGLEUSERTS. /// /// /// /// OS_PERSONALTERMINALSERVER /// 25 /// /// The program is running on Windows XP (or one of its successors), Home Edition or Professional. This is equivalent to /// VER_SUITE_SINGLEUSERTS && !VER_SUITE_TERMINAL. /// /// /// /// OS_FASTUSERSWITCHING /// 26 /// Fast user switching is enabled. /// /// /// OS_WELCOMELOGONUI /// 27 /// Always returns FALSE. /// /// /// OS_DOMAINMEMBER /// 28 /// The computer is joined to a domain. /// /// /// OS_ANYSERVER /// 29 /// The program is running on any Windows Server product. Equivalent to VER_NT_SERVER || VER_NT_DOMAIN_CONTROLLER. /// /// /// OS_WOW6432 /// 30 /// The program is a 32-bit program running on 64-bit Windows. /// /// /// OS_WEBSERVER /// 31 /// Always returns FALSE. /// /// /// OS_SMALLBUSINESSSERVER /// 32 /// The program is running on Microsoft Small Business Server with restrictive client license in force. Equivalent to VER_SUITE_SMALLBUSINESS_RESTRICTED. /// /// /// OS_TABLETPC /// 33 /// The program is running on Windows XP Tablet PC Edition, or one of its successors. /// /// /// OS_SERVERADMINUI /// 34 /// /// The user should be presented with administrator UI. It is possible to have server administrative UI on a non-server machine. This /// value informs the application that an administrator's profile has roamed to a non-server, and UI should be appropriate to an /// administrator. Otherwise, the user is shown a mix of administrator and nonadministrator settings. /// /// /// /// OS_MEDIACENTER /// 35 /// The program is running on Windows XP Media Center Edition, or one of its successors. Equivalent to GetSystemMetrics(SM_MEDIACENTER). /// /// /// OS_APPLIANCE /// 36 /// The program is running on Windows Appliance Server. /// /// /// /// /// Type: BOOL /// Returns a nonzero value if the specified operating system or operating system feature is detected, otherwise FALSE. /// /// /// /// Values are not provided for Windows Vista and Windows 7. To determine whether either of those operating systems are present, use VerifyVersionInfo. /// /// /// In Windows versions earlier than Windows Vista, IsOS was not exported by name or declared in a public header file. To use /// it in those cases, you must use GetProcAddress and request ordinal 437 from Shlwapi.dll to obtain a function pointer. Under /// Windows Vista, IsOS is included in Shlwapi.h and this is not necessary. /// /// /// When referring to server products, "Windows Server" refers only to the Standard Edition server. If all server products are /// covered by a particular flag, it is called out explicitly in the table. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-isos BOOL IsOS( DWORD dwOS ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "827a76bc-3581-4f1c-8095-8e2fd30dfdbc")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsOS(OS dwOS); /// /// Copies a stream to another stream. /// /// /// Type: IStream* /// A pointer to the source stream. /// /// /// Type: IStream* /// A pointer to the destination stream. /// /// /// Type: DWORD /// The number of bytes to copy from the source stream. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_copy LWSTDAPI IStream_Copy( IStream *pstmFrom, // IStream *pstmTo, DWORD cb ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "7d6a1080-dad4-4821-8f2a-bd1e01ca10cf")] public static extern HRESULT IStream_Copy(IStream pstmFrom, IStream pstmTo, uint cb); /// /// Reads bytes from a specified stream and returns a value that indicates whether all bytes were successfully read. /// /// Type: IStream* /// A pointer to the IStream interface of the stream from which to read. /// Type: VOID* /// A pointer to a buffer to receive the stream data from pstm. This buffer must be at least cb bytes in size. /// Type: ULONG /// The number of bytes of data that the function should attempt to read from the input stream. /// /// Type: HRESULT /// /// Returns S_OK if the function successfully reads the specified number of bytes from the stream, or a COM failure code /// otherwise. In particular, if the read attempt was successful but fewer than cb bytes were read, the function returns E_FAIL. /// /// /// /// This function calls the ISequentialStream::Read method to read data from the specified stream into the buffer. If the function /// fails for any reason, the contents of the output buffer and the position of the read pointer in the input stream are undefined. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_read // LWSTDAPI IStream_Read(IStream *pstm, void *pv, ULONG cb ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "07a3a500-babb-458b-ba98-9344c63ea014")] public static extern HRESULT IStream_Read(IStream pstm, IntPtr pv, uint cb); /// /// Reads bytes from a specified stream and returns a value that indicates whether all bytes were successfully read. /// /// Type: IStream* /// A pointer to the IStream interface of the stream from which to read. /// Type: VOID* /// A pointer to a buffer to receive the stream data from pstm. This buffer must be at least cb bytes in size. /// Type: ULONG /// The number of bytes of data that the function should attempt to read from the input stream. /// /// Type: HRESULT /// /// Returns S_OK if the function successfully reads the specified number of bytes from the stream, or a COM failure code /// otherwise. In particular, if the read attempt was successful but fewer than cb bytes were read, the function returns E_FAIL. /// /// /// /// This function calls the ISequentialStream::Read method to read data from the specified stream into the buffer. If the function /// fails for any reason, the contents of the output buffer and the position of the read pointer in the input stream are undefined. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_read // LWSTDAPI IStream_Read(IStream *pstm, void *pv, ULONG cb ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "07a3a500-babb-458b-ba98-9344c63ea014")] public static extern HRESULT IStream_Read(IStream pstm, SafeAllocatedMemoryHandle pv, uint cb); /// /// Reads a pointer to an item identifier list (PIDL) from an IStream object into a PIDLIST_RELATIVE object. /// /// /// Type: IStream* /// A pointer to the IStream from which the PIDL is read. /// /// /// Type: PIDLIST_RELATIVE* /// A pointer to the resulting PIDL. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_readpidl LWSTDAPI IStream_ReadPidl( IStream *pstm, // PIDLIST_RELATIVE *ppidlOut ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "63b1f842-139b-4558-8105-4986ce592b56")] public static extern HRESULT IStream_ReadPidl(IStream pstm, out IntPtr ppidlOut); /// /// Reads from a stream and writes into a string. /// /// /// Type: IStream* /// A pointer to the stream from which to read. /// /// /// Type: PWSTR* /// A pointer to the null-terminated, Unicode string into which the stream is written. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_readstr LWSTDAPI IStream_ReadStr( IStream *pstm, // PWSTR *ppsz ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "e3f140c4-4033-4c82-af2c-4a7744461920")] public static extern HRESULT IStream_ReadStr(IStream pstm, [MarshalAs(UnmanagedType.LPWStr)] ref StringBuilder ppsz); /// /// Moves the seek position in a specified stream to the beginning of the stream. /// /// /// Type: IStream* /// A pointer to the IStream interface of the stream whose position is to be reset. /// /// /// Type: HRESULT /// /// Returns S_OK on success or a COM failure code otherwise. See IStream::Seek for further discussion of possible error codes. /// /// /// /// This function calls IStream::Seek to move the stream's seek position to the beginning of the stream. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_reset LWSTDAPI IStream_Reset( IStream *pstm ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "1e7a881d-decb-4018-b2e8-e0cba454236d")] public static extern HRESULT IStream_Reset(IStream pstm); /// /// Retrieves the size, in bytes, of a specified stream. /// /// /// Type: IStream* /// A pointer to the IStream interface of the stream whose size is to be determined. /// /// /// Type: ULARGE_INTEGER* /// A pointer to a ULARGE_INTEGER structure to receive the size of the stream. /// /// /// Type: HRESULT /// /// Returns S_OK on success or a COM failure code otherwise. See IStream::Stat for further discussion of possible error codes. /// /// /// /// /// This function gets the size of the stream by calling the specified stream object's IStream::Stat method. It then copies the value /// of the cbSize member of the STATSTG structure returned by IStream::Stat to the ULARGE_INTEGER structure pointed to /// by pui. If the function fails, the contents of the ULARGE_INTEGER structure are undefined. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_size LWSTDAPI IStream_Size( IStream *pstm, // ULARGE_INTEGER *pui ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "93c7c24d-6431-4859-b0b8-b36392bc5108")] public static extern HRESULT IStream_Size(IStream pstm, out ulong pui); /// /// Writes data of unknown format from a buffer to a specified stream. /// /// /// Type: IStream* /// An IStream pointer that specifies the target stream. /// /// /// Type: const void* /// Pointer to a buffer that holds the data to send to the target stream. This buffer must be at least cb bytes in size. /// /// /// Type: ULONG /// The number of bytes of data to write to the target stream. /// /// /// Type: HRESULT /// /// Returns S_OK if the function successfully wrote the specified number of bytes to the stream, or an error value otherwise. In /// particular, if less than cb bytes was written to the target stream, even if some data was successfully written, the function /// returns E_FAIL. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_write LWSTDAPI IStream_Write( IStream *pstm, const // void *pv, ULONG cb ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "fdcfdaf8-7fcb-433e-b3d4-98ca143fbe6b")] public static extern HRESULT IStream_Write(IStream pstm, IntPtr pv, uint cb); /// /// Writes data of unknown format from a buffer to a specified stream. /// /// /// Type: IStream* /// An IStream pointer that specifies the target stream. /// /// /// Type: const void* /// Pointer to a buffer that holds the data to send to the target stream. This buffer must be at least cb bytes in size. /// /// /// Type: ULONG /// The number of bytes of data to write to the target stream. /// /// /// Type: HRESULT /// /// Returns S_OK if the function successfully wrote the specified number of bytes to the stream, or an error value otherwise. In /// particular, if less than cb bytes was written to the target stream, even if some data was successfully written, the function /// returns E_FAIL. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_write LWSTDAPI IStream_Write( IStream *pstm, const // void *pv, ULONG cb ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "fdcfdaf8-7fcb-433e-b3d4-98ca143fbe6b")] public static extern HRESULT IStream_Write(IStream pstm, SafeAllocatedMemoryHandle pv, uint cb); /// /// Writes a pointer to an item identifier list (PIDL) from a PCUIDLIST_RELATIVE object into an IStream object. /// /// /// Type: IStream* /// A pointer to the IStream object in which to write. /// /// /// Type: PCUIDLIST_RELATIVE /// The source PIDL. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_writepidl LWSTDAPI IStream_WritePidl( IStream // *pstm, PCUIDLIST_RELATIVE pidlWrite ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "29b6a42b-08bd-4b5f-92ad-a6456e7a6f98")] public static extern HRESULT IStream_WritePidl(IStream pstm, IntPtr pidlWrite); /// /// Reads from a string and writes into a stream. /// /// /// Type: IStream* /// A pointer to the stream in which to write. /// /// /// Type: PCWSTR /// A pointer to a null-terminated, Unicode string from which to read. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-istream_writestr LWSTDAPI IStream_WriteStr( IStream *pstm, // PCWSTR psz ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "13292ccd-fc0c-4230-a935-4d5aed8cec97")] public static extern HRESULT IStream_WriteStr(IStream pstm, [MarshalAs(UnmanagedType.LPWStr)] string psz); /// /// Releases a Component Object Model (COM) pointer and sets it to NULL. /// /// /// Type: void** /// The address of a pointer to a COM interface. /// /// /// This function does not return a value. /// /// /// /// If ppunk points to a NULL pointer, no operation is performed. Otherwise, ppunk is assumed to be the address of a COM /// interface pointer, derived from IUnknown. The function calls the interface's IUnknown::Release method then sets the interface /// pointer to NULL. /// /// Examples /// The following example uses IUnknown_AtomicRelease to release the stream, if it exists. If not, it does nothing. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_atomicrelease void IUnknown_AtomicRelease( void // **ppunk ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "6bb3f9cf-bf28-4f94-8557-56c1952384ec")] public static extern void IUnknown_AtomicRelease([MarshalAs(UnmanagedType.IUnknown)] out object ppunk); /// /// Calls the specified object's IObjectWithSite::GetSite method. /// /// /// Type: IUnknown* /// A pointer to the COM object whose IObjectWithSite::GetSite method is to be called. /// /// /// Type: REFIID /// The IID of the interface pointer that should be returned in ppvSite. /// /// /// TBD /// /// /// Type: HRESULT /// Returns S_OK if the site was successfully retrieved or a COM error code otherwise. /// /// /// /// This function calls the specified object's QueryInterface method to obtain the IObjectWithSite interface. If successful, the /// function calls the interface's IObjectWithSite::GetSite method to obtain the site. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_getsite LWSTDAPI IUnknown_GetSite( IUnknown // *punk, REFIID riid, void **ppv ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "95e83078-ab74-40d6-8e31-653e578770f2")] public static extern HRESULT IUnknown_GetSite([MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 1)] out object ppv); /// /// /// Attempts to retrieve a window handle from a Component Object Model (COM) object by querying for various interfaces that have a /// GetWindow method. /// /// /// /// Type: IUnknown* /// A pointer to the COM object from which this function will attempt to obtain a window handle. /// /// /// Type: HWND* /// /// A pointer to a HWND that, when this function returns successfully, receives the window handle. If a window handle was not /// obtained, this parameter is set to NULL. /// /// /// /// Type: HRESULT /// /// Returns S_OK if a window handle was successfully returned, or a COM error code otherwise. If no suitable interface was found, the /// function returns E_NOINTERFACE. Otherwise, the function returns the HRESULT returned by the corresponding interface's /// GetWindow method. /// /// /// /// /// This function attempts to retrieve the window handle by calling IOleWindow::GetWindow, IInternetSecurityMgrSite::GetWindow, and /// IShellView::GetWindow. It is possible that future versions of IUnknown_GetWindow may attempt additional interfaces. /// /// /// Note The query for IShellView is theoretically unnecessary because IShellView derives from IOleWindow. The function /// explicitly queries for this interface because some objects implement QueryInterface incorrectly and fail to respond to a query /// for the base interface. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_getwindow LWSTDAPI IUnknown_GetWindow( IUnknown // *punk, HWND *phwnd ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f8a6f61f-bea3-4049-89fb-c33ef00b327f")] public static extern HRESULT IUnknown_GetWindow([MarshalAs(UnmanagedType.IUnknown)] object punk, out HWND phwnd); /// /// Retrieves an interface for a service from a specified object. /// /// /// Type: IUnknown* /// A pointer to the IUnknown instance of the COM object that supports the service. /// /// /// Type: REFGUID /// The service's unique identifier (SID). /// /// /// Type: REFIID /// The IID of the desired service interface. /// /// /// Type: void** /// /// When this method returns, contains the interface pointer requested riid. If successful, the calling application is responsible /// for calling IUnknown::Release using this value when the service is no longer needed. In the case of failure, this value is NULL. /// /// /// /// Type: HRESULT /// /// Returns S_OK if successful. Returns E_FAIL if the object does not support IServiceProvider. Otherwise, the function /// returns the HRESULT returned by the object's QueryService method. /// /// /// /// /// If the object passed in the punk parameter supports the IServiceProvider interface, then its QueryService method is invoked, /// passing the guidService, riid, and ppvOut parameters and propagating the return value. Otherwise, the function returns E_FAIL. /// /// /// For those versions of Windows that do not include IUnknown_QueryService in Shlwapi.h, this function must be called /// directly from Shlwapi.dll using ordinal 176. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_queryservice LWSTDAPI IUnknown_QueryService( // IUnknown *punk, REFGUID guidService, REFIID riid, void **ppvOut ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "3e3f3ed0-ad36-40ef-b30c-8c85ff159f21")] public static extern HRESULT IUnknown_QueryService([MarshalAs(UnmanagedType.IUnknown)] object punk, in Guid guidService, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 2)] out object ppvOut); /// Retrieves an interface for a service from a specified object. /// The type of the desired service interface. /// Type: IUnknown* /// A pointer to the IUnknown instance of the COM object that supports the service. /// Type: REFGUID /// The service's unique identifier (SID). /// Type: Guid? /// The IID of the desired service interface. If , the Guid of the type is used. /// /// Type: HRESULT /// /// When this method returns, contains the interface pointer requested riid. If successful, the calling application is responsible /// for calling IUnknown::Release using this value when the service is no longer needed. In the case of failure, this value is NULL. /// /// /// /// /// If the object passed in the punk parameter supports the IServiceProvider interface, then its QueryService method is invoked, /// passing the guidService, riid, and ppvOut parameters and propagating the return value. Otherwise, the function returns E_FAIL. /// /// /// For those versions of Windows that do not include IUnknown_QueryService in Shlwapi.h, this function must be called /// directly from Shlwapi.dll using ordinal 176. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_queryservice LWSTDAPI IUnknown_QueryService( // IUnknown *punk, REFGUID guidService, REFIID riid, void **ppvOut ); [PInvokeData("shlwapi.h", MSDNShortId = "3e3f3ed0-ad36-40ef-b30c-8c85ff159f21")] public static TOut IUnknown_QueryService(object punk, in Guid guidService, in Guid? riid = null) { var iid = riid ?? typeof(TOut).GUID; IUnknown_QueryService(punk, guidService, iid, out var ppvOut).ThrowIfFailed(); return (TOut)ppvOut; } /// /// Changes the value of a Component Object Model (COM) interface pointer and releases the previous interface. /// /// /// Type: IUnknown** /// /// The address of a COM interface pointer to receive the pointer assigned to punk. If the previous value of the pointer is non- /// NULL, the function releases that interface by calling its IUnkown::Release method. /// /// /// /// Type: IUnknown* /// /// The interface pointer to be copied to ppunk. If the value is non- NULL, the function increments the interface's reference count. /// /// /// /// This function does not return a value. /// /// /// This function mimics the behavior of a smart pointer. Conceptually, the function does the following: /// /// /// Releases the original interface, if ppunk is non- NULL /// /// /// Assigns punk to ppunk /// /// /// Calls IUnknown::AddRef on the interface pointed to by punk, if punk is non- NULL. /// /// /// Examples /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_set void IUnknown_Set( IUnknown **ppunk, IUnknown // *punk ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "b3c4bee2-12cb-483e-9a46-f09d63ae9a2e")] public static extern void IUnknown_Set([MarshalAs(UnmanagedType.IUnknown)] ref object ppunk, [MarshalAs(UnmanagedType.IUnknown)] object punk); /// /// Sets the specified object's site by calling its IObjectWithSite::SetSite method. /// /// /// Type: IUnknown* /// A pointer to the IUnknown interface of the object whose site is to be changed. /// /// /// Type: IUnknown* /// A pointer to the IUnknown interface of the new site. /// /// /// Type: HRESULT /// Returns S_OK if the site was successfully set, or a COM error code otherwise. /// /// /// /// This function calls the specified object's IUnknown::QueryInterface method to obtain a pointer to the object's IObjectWithSite /// interface. If successful, the function calls IObjectWithSite::SetSite to set or change the site. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-iunknown_setsite LWSTDAPI IUnknown_SetSite( IUnknown // *punk, IUnknown *punkSite ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "66175435-f85b-4e26-b148-f4edb74cb41d")] public static extern HRESULT IUnknown_SetSite([In, MarshalAs(UnmanagedType.IUnknown)] object punk, [In, MarshalAs(UnmanagedType.IUnknown)] object punkSite); /// /// [This function is not available for use as of Windows 7.] /// Maps an appropriate resource DLL into the address space of the calling function, based on the user's default UI language. /// /// /// Type: LPCTSTR /// /// A null-terminated string with the file name of the resource DLL to be loaded. Do not include any path information. /// MLLoadLibrary derives that information as described in the Remarks below. /// /// /// /// Type: HMODULE /// /// A handle to an already-loaded DLL that represents the code library for which the multilingual resource library is being requested. /// /// /// /// Type: DWORD /// Reserved. This parameter must be set to zero. /// /// /// Type: HINSTANCE /// Returns the module's handle if successful, or NULL otherwise. /// // HINSTANCE MLLoadLibrary( _In_ LPCTSTR lpszLibFileName, _In_ HMODULE hModule, _In_ DWORD dwCrossCodePage); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773822(v=vs.85).aspx [DllImport(Lib.Shlwapi, CharSet = CharSet.Auto)] [PInvokeData("Shlwapi.h", MSDNShortId = "bb773822")] [Obsolete] public static extern IntPtr MLLoadLibrary(string lpszLibFileName, HINSTANCE hModule, uint dwCrossCodePage); /// /// A table-driven implementation of the IUnknown::QueryInterface method. /// /// /// Type: void* /// A pointer to the base of a COM object. /// /// /// Type: LPCQITAB /// /// An array of QITAB structures. The last structure in the array must have its piid member set to NULL and its /// dwOffset member set to 0. /// /// /// /// Type: REFIID /// A reference to the IID of the interface to retrieve through ppv. /// /// /// Type: void** /// When this method returns successfully, contains the interface pointer requested in riid. /// /// /// Type: HRESULT /// /// Returns S_OK if the requested interface was found in the table or if the requested interface was IUnknown. Returns E_NOINTERFACE /// if the requested interface was not found. /// /// /// /// /// Note Prior to Windows Vista, QISearch was not exported by name or declared in a public header file. To use it in /// those cases, you must use GetProcAddress and request ordinal 219 from Shlwapi.dll to obtain a function pointer. Under Windows /// Vista, QISearch is included in Shlwapi.h and this is not necessary. /// /// /// If the requested interface is IUnknown, then QISearch uses the first entry of the specified array of QITAB structures. /// Otherwise, QISearch searches the table until it either finds a matching IID or reaches the end of the table. If a matching /// IID is found, the function advances the associated interface pointer by the number of bytes specified by the dwOffset /// member of the interface's QITAB structure and reinterpreted as a COM pointer. That pointer is assigned to the /// QISearch function's ppv parameter. The method also calls IUnknown::AddRef to increment the interface's reference count. /// /// /// If QISearch reaches the end of the table without finding the interface, it returns E_NOINTERFACE and sets ppv to NULL. /// /// /// It is important to include all applicable interfaces in the table. For example, if the object implements a derived interface, you /// should also include the base interface in the table. /// /// /// We recommend that you use the IID_PPV_ARGS macro, defined in Objbase.h, to package the riid and ppv parameters. This macro /// provides the correct IID based on the interface pointed to by the value in ppv, which eliminates the possibility of a coding /// error in riid that could lead to unexpected results. /// /// /// Note Active Template Library (ATL) provides a significantly better version of a table-driven implementation of QueryInterface. /// /// Examples /// /// The following example illustrates how to use QISearch to implement QueryInterface. It uses the offsetofclass macro from /// ATL to compute the offset from the base of the CSample object to a specified interface. /// /// /// This object supports two interfaces aside from IUnknown, so there are two non- NULL entries in the QITAB table. The entry /// for each interface specifies a pointer to the associated IID (IID_IPersist or IID_IPersistFolder) and the offset of the interface /// pointer relative to the class's base pointer. The sample uses the offsetofclass macro from ATL to determine that offset. /// /// /// Note Forgetting to include all base classes, including indirect ones, is a common error. Notice that there is an entry for /// the IPersist interface. This interface is an indirect base class for CSample, inherited through IPersistFolder. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-qisearch HRESULT QISearch( void *that, LPCQITAB pqit, // REFIID riid, void **ppv ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "8429778b-bc9c-43f6-8d75-0fb78e36e790")] public static extern HRESULT QISearch(IntPtr that, QITAB[] pqit, in Guid riid, [MarshalAs(UnmanagedType.IUnknown, IidParameterIndex = 2)] out object ppv); /// /// /// [ SHAllocShared is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions.] /// /// Allocates a handle in a specified process to a copy of a specified memory block in the calling process. /// /// /// Type: const void* /// /// A pointer to the memory block in the calling process that is to be copied. You can set this parameter to NULL if you want /// to share a block of memory without copying any data to it. /// /// /// /// Type: DWORD /// The size, in bytes, of the memory block pointed to by pvData. /// /// /// TBD /// /// /// Type: HANDLE /// Returns a handle to the shared memory for the process specified by dwDestinationProcessId. Returns NULL if unsuccessful. /// /// /// Use SHFreeShared to free the handle when you are finished. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shallocshared HANDLE SHAllocShared( const void *pvData, // DWORD dwSize, DWORD dwProcessId ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "0388b6a0-24d9-48eb-bef2-3a1658d8bb3c")] public static extern IntPtr SHAllocShared(IntPtr pvData, uint dwSize, uint dwProcessId); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Copies an ANSI string. /// /// /// Type: LPCSTR /// A pointer to a null-terminated ANSI string to be converted to Unicode. /// /// /// Type: LPWSTR /// /// A pointer to a buffer that, when this function returns successfully, receives the characters copied from pszSrc. The buffer must /// be large enough to contain the number of characters specified by the cchBuf parameter, including a room for a terminating null character. /// /// /// /// Type: int /// /// The number of characters that can be contained by the buffer pointed to by pszDst. This parameter must be greater than zero. /// /// /// /// Type: int /// Returns the number of characters written to pszDst, including the terminating null character. Returns 0 if unsuccessful. /// /// /// /// Security Warning: Using this function incorrectly can compromise the security of your application. For example, if pszDst /// buffer is not large enough to contain the number of characters specified by cchBuf, a buffer overrun can occur. Buffer overruns /// can cause a denial of service attack against an application if an access violation occurs. In the worst case, a buffer overrun /// might allow an attacker to inject executable code into your process, especially if pszDst is a stack-based buffer. Note that the /// output string is silently truncated if the buffer is not large enough. This can result in canonicalization or other security vulnerabilities. /// /// /// If the pszDst buffer is not large enough to contain the entire converted output string, the string is truncated to fit the /// buffer. There is no way to detect that the return string has been truncated. The string will always be null-terminated, even if /// it has been truncated. This function takes care to not truncate between the lead and trail bytes of a DBCS character pair. In /// that case, only cchBuf-1 characters are returned. /// /// If the pszSrc and pszDst buffers overlap, the function's behavior is undefined. /// /// Note Do not assume that the function has not changed any of the characters in the output buffer that follow the string's /// terminating null character. The contents of the output buffer following the string's terminating null character are undefined, up /// to and including the last character in the buffer. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shansitoansi int SHAnsiToAnsi( PCSTR pszSrc, PSTR pszDst, // int cchBuf ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("shlwapi.h", MSDNShortId = "e57142ca-3098-4118-aac0-89724f711872")] public static extern int SHAnsiToAnsi(string pszSrc, StringBuilder pszDst, int cchBuf); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Converts a string from the ANSI code page to the Unicode code page. /// /// /// Type: PCSTR /// A pointer to a null-terminated ANSI string to be converted to Unicode. /// /// /// Type: PWSTR /// /// A pointer to a buffer that, when this function returns successfully, receives the string specified by pszSrc, after the ANSI /// characters have been converted to Unicode (WCHAR). The buffer must be large enough to contain the number of Unicode characters /// specified by the cwchBuf parameter, including a terminating null character. /// /// /// /// Type: int /// /// The number of Unicode characters that can be contained by the buffer pointed to by pwszDst. This parameter must be greater than zero. /// /// /// /// Type: int /// Returns the number of Unicode characters written to pwszDst, including the terminating null character. Returns 0 if unsuccessful. /// /// /// /// Security Warning: Using this function incorrectly can compromise the security of your application. For example, if pwszDst /// buffer is not large enough to contain the number of characters specified by cwchBuf, a buffer overrun can occur. Buffer overruns /// can cause a denial of service attack against an application if an access violation occurs. In the worst case, a buffer overrun /// might allow an attacker to inject executable code into your process, especially if pwszDst is a stack-based buffer. When copying /// an entire string, note that sizeof returns the number of bytes, which is not the correct value to use for the cwchBuf parameter. /// Instead, use sizeof(pwszDst)/sizeof(WCHAR). Note that this technique assumes that pwszDst is an array, not a pointer. /// /// /// If the pwszDst buffer is not large enough to contain the entire converted output string, the string is truncated to fit the /// buffer. There is no way to detect that the return string has been truncated. The string is always null-terminated, even if it has /// been truncated. This ensures that no more than cwchBuf characters are copied to pwszDst. No attempt is made to avoid truncating /// the string in the middle of a Unicode surrogate pair. /// /// If the pszSrc and pwszDst buffers overlap, the function's behavior is undefined. /// /// Note Do not assume that the function has not changed any of the characters in the output buffer that follow the string's /// terminating null character. The contents of the output buffer following the string's terminating null character are undefined, up /// to and including the last character in the buffer. /// /// SHAnsiToTChar is defined to be the same as SHAnsiToUnicode. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shansitounicode int SHAnsiToUnicode( PCSTR pszSrc, PWSTR // pwszDst, int cwchBuf ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "9578f26e-56ea-4f3b-b024-b2e285d0c4d2")] public static extern int SHAnsiToUnicode([MarshalAs(UnmanagedType.LPStr)] string pszSrc, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszDst, int cwchBuf); /// /// Instructs system edit controls to use AutoComplete to help complete URLs or file system paths. /// /// /// Type: HWND /// /// The window handle of a system edit control. Typically, this parameter is the handle of an edit control or the edit control /// embedded in a ComboBoxEx control. /// /// /// /// Type: DWORD /// /// The flags to control the operation of SHAutoComplete. The first four flags are used to override the Internet Explorer /// registry settings. The user can change these settings manually by launching the Internet Options property sheet from the /// Tools menu and clicking the Advanced tab. /// /// SHACF_AUTOAPPEND_FORCE_OFF (0x80000000) /// /// Ignore the registry default and force the AutoAppend feature off. This flag must be used in combination with one or more of the /// SHACF_FILESYS* or SHACF_URL* flags. /// /// SHACF_AUTOAPPEND_FORCE_ON (0x40000000) /// /// Ignore the registry value and force the AutoAppend feature on. The completed string will be displayed in the edit box with the /// added characters highlighted. This flag must be used in combination with one or more of the SHACF_FILESYS* or SHACF_URL* flags. /// /// SHACF_AUTOSUGGEST_FORCE_OFF (0x20000000) /// /// Ignore the registry default and force the AutoSuggest feature off. This flag must be used in combination with one or more of the /// SHACF_FILESYS* or SHACF_URL* flags. /// /// SHACF_AUTOSUGGEST_FORCE_ON (0x10000000) /// /// Ignore the registry value and force the AutoSuggest feature on. A selection of possible completed strings will be displayed as a /// drop-down list, below the edit box. This flag must be used in combination with one or more of the SHACF_FILESYS* or SHACF_URL* flags. /// /// SHACF_DEFAULT (0x00000000) /// /// The default setting, equivalent to SHACF_FILESYSTEM | SHACF_URLALL. SHACF_DEFAULT cannot be combined with /// any other flags. /// /// SHACF_FILESYS_ONLY (0x00000010) /// Include the file system only. /// SHACF_FILESYS_DIRS (0x00000020) /// Include the file system and directories, UNC servers, and UNC server shares. /// SHACF_FILESYSTEM (0x00000001) /// Include the file system and the rest of the Shell (Desktop, Computer, and Control Panel, for example). /// SHACF_URLALL (SHACF_URLHISTORY | SHACF_URLMRU) /// Include the URLs in the users History and Recently Used lists. Equivalent to SHACF_URLHISTORY | SHACF_URLMRU. /// SHACF_URLHISTORY (0x00000002) /// Include the URLs in the user's History list. /// SHACF_URLMRU (0x00000004) /// Include the URLs in the user's Recently Used list. /// SHACF_USETAB (0x00000008) /// /// Allow the user to select from the autosuggest list by pressing the TAB key. If this flag is not set, pressing the TAB key will /// shift focus to the next control and close the autosuggest list. If SHACF_USETAB is set, pressing the TAB key will select /// the first item in the list. Pressing TAB again will select the next item in the list, and so on. When the user reaches the end of /// the list, the next TAB key press will cycle the focus back to the edit control. This flag must be used in combination with one or /// more of the SHACF_FILESYS* or SHACF_URL* flags listed on this page. /// /// SHACF_VIRTUAL_NAMESPACE (0x00000040) /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// SHAutoComplete works on any system edit control, including the edit control and controls that contain edit controls such /// as ComboBoxEx controls. To retrieve a handle to an edit control embedded in a ComboBoxEx control, send the ComboBoxEx control a /// CBEM_GETEDITCONTROL message. /// /// /// An application must have invoked either CoInitialize or OleInitialize prior to calling this function. CoUninitialize or /// OleUninitialize cannot be called until the edit box has finished processing the WM_DESTROY message for hwndEdit. /// /// The maximum number of items that can be displayed in an autosuggest drop-down list box is 1000. /// /// On versions of Windows prior to Windows Vista and server versions prior to Windows Server 2008, SHAutoComplete should not /// be called more than once with the same HWND. Doing so results in a memory leak. It prevents the original resources from /// being released, including the previous instance of the AutoComplete object, enumerator objects that the previous AutoComplete /// object has referenced, and Windows Graphics Device Interface (GDI) resources. Rather than call SHAutoComplete again with a /// different set of flags to change the AutoComplete list, call CoCreateInstance with CLSID_AutoComplete to obtain the AutoComplete /// object. Then pass the HWND to the object to initialize it and provide your own custom enumerator. You can use /// CLSID_ACLMulti if you want AutoComplete to use multiple lists. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shautocomplete LWSTDAPI SHAutoComplete( HWND hwndEdit, // DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "b47efa8d-2118-4805-bb04-97bd143228dc")] public static extern HRESULT SHAutoComplete(HWND hwndEdit, SHACF dwFlags); /// /// /// Recursively copies the subkeys and values of the source subkey to the destination key. SHCopyKey does not copy the /// security attributes of the keys. /// /// /// /// Type: HKEY /// A handle to the source key (for example, HKEY_CURRENT_USER). /// /// /// Type: LPCTSTR /// The subkey whose subkeys and values are to be copied. /// /// /// Type: HKEY /// The destination key. /// /// /// Type: DWORD /// Reserved. Must be 0. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or one of the nonzero error codes defined in Winerror.h otherwise. Use FormatMessage with /// the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// Important This function does not duplicate the security attributes of the keys and values that it copies. Rather, all /// security attributes in the destination key are the default attributes. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcopykeya LSTATUS SHCopyKeyA( HKEY hkeySrc, LPCSTR // pszSrcSubKey, HKEY hkeyDest, DWORD fReserved ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "52521ef4-fe59-4766-8828-acb557b0e968")] public static extern Win32Error SHCopyKey(HKEY hkeySrc, string pszSrcSubKey, HKEY hkeyDest, uint fReserved = 0); /// /// Creates a memory stream using a similar process to CreateStreamOnHGlobal. /// /// /// Type: const BYTE* /// /// A pointer to a buffer of size cbInit. The contents of this buffer are used to set the initial contents of the memory stream. If /// this parameter is NULL, the returned memory stream does not have any initial content. /// /// /// /// Type: UINT /// The number of bytes in the buffer pointed to by pInit. If pInit is set to NULL, cbInit must be zero. /// /// /// Type: IStream* /// On success, returns a pointer to the created memory stream. Returns NULL if the stream object could not be allocated. /// /// /// /// Prior to Windows Vista, this function was not included in the public Shlwapi.h file, nor was it exported by name from /// Shlwapi.dll. To use it on earlier systems, you must call it directly from the Shlwapi.dll file as ordinal 12. /// /// /// This function creates a memory stream. This is an implementation of the IStream interface that stores its contents in memory. /// SHCreateMemStream differs from CreateStreamOnHGlobal in the following ways. /// /// /// /// /// Thread safety. The stream created by SHCreateMemStream is thread-safe as of Windows 8. On earlier systems, the stream is /// not thread-safe. The stream created by CreateStreamOnHGlobal is thread-safe. /// /// /// /// /// Initial contents. SHCreateMemStream accepts the initial contents in the form of a buffer. CreateStreamOnHGlobal accepts /// the initial contents in the form of an HGLOBAL. /// /// /// /// /// Access to contents. SHCreateMemStream does not allow direct access to the stream contents. CreateStreamOnHGlobal permits /// access through GetHGlobalFromStream. /// /// /// /// /// Failure information. If SHCreateMemStream returns NULL, it was unable to allocate the neccessary memory. Callers /// should assume the cause is E_OUTOFMEMORY. /// /// /// /// /// Support for IStream::Clone. Prior to Windows 8, the stream created by SHCreateMemStream does not support /// IStream::Clone. The stream created by CreateStreamOnHGlobal does. As of Windows 8, the stream created by /// SHCreateMemStream does support IStream::Clone. /// /// /// /// /// The stream returned by SHCreateMemStream returns S_FALSE from IStream::Read if you attempt to read past the end of the /// buffer. The stream returned by CreateStreamOnHGlobal returns S_OK and sets *pcbRead to 0 if you attempt to read past the end of /// the buffer. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatememstream IStream * SHCreateMemStream( const BYTE // *pInit, UINT cbInit ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f3ae8241-f3a6-4007-a10f-ff05960c5de8")] public static extern IStream SHCreateMemStream(IntPtr pInit, uint cbInit); /// /// Creates a halftone palette for the specified device context. /// /// /// Type: HDC /// The device context. /// /// /// Type: HPALETTE /// Returns the palette if successful; otherwise 0. /// /// /// /// This function behaves the same as CreateHalftonePalette. The palette that is returned depends on the device context in the /// following way: /// /// /// /// If hdc is set to NULL, a full palette is returned. /// /// /// If the device context is indexed, a full palette is returned. /// /// /// If the device context is not indexed, a default palette (VGA colors) is returned. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreateshellpalette HPALETTE SHCreateShellPalette( HDC // hdc ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "49afb04a-34e3-4696-a046-bc9308ae7adf")] public static extern IntPtr SHCreateShellPalette(HDC hdc); /// /// /// [ SHCreateStreamOnFile is available for use in the operating systems specified in the Requirements section. It may be /// altered or unavailable in subsequent versions. Instead, use SHCreateStreamOnFileEx.] /// /// Opens or creates a file and retrieves a stream to read or write to that file. /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string that specifies the file name. /// /// /// Type: DWORD /// /// One or more STGM values that are used to specify the file access mode and how the object that exposes the stream is created and deleted. /// /// /// /// Type: IStream** /// Receives an IStream interface pointer for the stream associated with the file. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// SHCreateStreamOnFileEx fully supports all STGM modes and allows the caller to specify file attributes if creating a new file. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatestreamonfilea LWSTDAPI SHCreateStreamOnFileA( // LPCSTR pszFile, DWORD grfMode, IStream **ppstm ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "9b1fd6c4-d7b0-40b9-bc9f-ea062a1079c1")] public static extern HRESULT SHCreateStreamOnFile(string pszFile, STGM grfMode, out IStream ppstm); /// /// Opens or creates a file and retrieves a stream to read or write to that file. /// /// /// Type: LPCWSTR /// A pointer to a null-terminated string that specifies the file name. /// /// /// Type: DWORD /// /// One or more STGM values that are used to specify the file access mode and how the object that exposes the stream is created and deleted. /// /// /// /// Type: DWORD /// /// One or more flag values that specify file attributes in the case that a new file is created. For a complete list of possible /// values, see the dwFlagsAndAttributes parameter of the CreateFile function. /// /// /// /// Type: BOOL /// /// A BOOL value that helps specify, in conjunction with grfMode, how existing files should be treated when creating the /// stream. See Remarks for details. /// /// /// /// Type: IStream* /// Reserved. /// /// /// Type: IStream** /// Receives an IStream interface pointer for the stream associated with the file. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// The SHCreateStreamOnFileEx function extends the semantics of the STGM flags and produces the same effect as calling the /// CreateFile function. /// /// The grfMode and fCreate parameters work together to specify how the function should behave with respect to existing files. /// /// /// grfMode /// fCreate /// File exists? /// Behavior /// /// /// STGM_CREATE /// Ignored /// Yes /// The file is recreated. /// /// /// STGM_CREATE /// Ignored /// No /// The file is created. /// /// /// STGM_FAILIFTHERE /// FALSE /// Yes /// The file is opened. /// /// /// STGM_FAILIFTHERE /// FALSE /// No /// The call fails. /// /// /// STGM_FAILIFTHERE /// TRUE /// Yes /// The call fails. /// /// /// STGM_FAILIFTHERE /// TRUE /// No /// The file is created. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatestreamonfileex LWSTDAPI SHCreateStreamOnFileEx( // LPCWSTR pszFile, DWORD grfMode, DWORD dwAttributes, BOOL fCreate, IStream *pstmTemplate, IStream **ppstm ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("shlwapi.h", MSDNShortId = "f948f7dd-987d-4c2d-b650-62081133c3f4")] public static extern HRESULT SHCreateStreamOnFileEx(string pszFile, STGM grfMode, FileFlagsAndAttributes dwAttributes, [MarshalAs(UnmanagedType.Bool)] bool fCreate, [Optional] IStream pstmTemplate, out IStream ppstm); /// /// Creates a thread. /// /// /// Type: LPTHREAD_START_ROUTINE /// /// A pointer to an application-defined function of the LPTHREAD_START_ROUTINE type. If a new thread was successfully created, this /// application-defined function is called in the context of that thread. SHCreateThread does not wait for the function /// pointed to by this parameter to complete before returning to its caller. The application-defined function's return value is the /// exit code of the thread. /// /// /// /// Type: void* /// /// A pointer to an optional application-defined data structure that contains initialization data. It is passed to the function /// pointed to by pfnThreadProc and, optionally, pfnCallback. This value can be NULL. /// /// /// /// TBD /// /// /// Type: LPTHREAD_START_ROUTINE /// /// A pointer to an optional application-defined function of the LPTHREAD_START_ROUTINE type. This function is called in the context /// of the created thread before the function pointed to by pfnThreadProc is called. It will also receive pData as its argument. /// SHCreateThread will wait for the function pointed to by pfnCallback to return before returning to its caller. The return /// value of the function pointed to by pfnCallback is ignored. /// /// /// /// Type: BOOL /// /// Returns TRUE if the thread is successfully created, or FALSE otherwise. On failure, use GetLastError to retrieve /// the specific error value as shown here. /// /// /// /// The function pointed to by pfnThreadProc and pfnCallback must take the following form. /// /// The function name is arbitrary. The pData parameter points to an application-defined data structure with initialization information. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatethread BOOL SHCreateThread( LPTHREAD_START_ROUTINE // pfnThreadProc, void *pData, SHCT_FLAGS flags, LPTHREAD_START_ROUTINE pfnCallback ); [DllImport(Lib.Shlwapi, SetLastError = true, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "2140e396-29cd-4665-b684-337170570b73")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHCreateThread(ThreadProc pfnThreadProc, IntPtr pData, SHCT_FLAGS flags, ThreadProc pfnCallback); /// /// Creates a per-thread reference to a Component Object Model (COM) object. /// /// /// Type: LONG* /// /// A pointer to a value, usually a local variable in the thread's ThreadProc, that is used by the interface in ppunk as a reference counter. /// /// /// /// Type: IUnknown** /// /// The address of a pointer to an IUnknown interface. If successful, this parameter holds the thread's IUnknown pointer on /// return. Your application is responsible for freeing the pointer when it is finished. /// /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// See Managing Thread References for more details on using the Shlwapi thread APIs. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatethreadref LWSTDAPI SHCreateThreadRef( LONG *pcRef, // IUnknown **ppunk ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "6abca2df-832c-410b-93c7-5131e481e595")] public static extern HRESULT SHCreateThreadRef(ref int pcRef, [MarshalAs(UnmanagedType.IUnknown)] out object ppunk); /// /// Creates a new thread and retrieves its handle. /// /// /// Type: LPTHREAD_START_ROUTINE /// /// A pointer to an application-defined function of type LPTHREAD_START_ROUTINE. If a new thread was successfully created, this /// application-defined function is called in the context of that thread. SHCreateThreadWithHandle does not wait for the /// function pointed to by pfnThreadProc to complete before returning to its caller. The return value for the function specified by /// pfnThreadProc is the exit code of the thread. /// /// /// /// Type: void* /// /// A pointer to an optional application-defined data structure that contains initialization data. It is passed to the function /// pointed to by pfnThreadProc and, optionally, the function pointed to by pfnCallback. /// /// /// /// Type: SHCT_FLAGS /// Flags that control the behavior of the function; one or more of the CTF constants. /// /// /// Type: LPTHREAD_START_ROUTINE /// /// A pointer to an optional application-defined function of type LPTHREAD_START_ROUTINE. This function is called in the context of /// the created thread before the function pointed to by pfnThreadProc is called. It will also receive pData as its argument. /// SHCreateThreadWithHandle waits for the function pointed to by pfnCallback to complete before returning to its caller. The /// return value for the function specified by pfnCallback is ignored. /// /// /// /// Type: HANDLE* /// /// A pointer to the HANDLE of the created thread. When it is no longer needed, this handle should be closed by calling the /// CloseHandle function. This value can be NULL. /// /// /// /// Type: BOOL /// TRUE if the thread is successfully created; otherwise, FALSE /// /// /// /// Prior to Windows 7, this function did not have an associated header or library file. To use this function under those earlier /// operating systems, call LoadLibrary with the DLL name (Shlwapi.dll) to obtain a module handle. Then call GetProcAddress with that /// module handle and a function ordinal of 615 to get the address of this function. /// /// The function pointed to by pfnThreadProc and pfnCallback must take the following form. /// /// The function name is arbitrary. The pData parameter points to an application-defined data structure with initialization information. /// /// Examples /// /// The following code example provides a function pointer prototype typedef for calling SHCreateThreadWithHandle by ordinal /// and shows how to accomplish such a call. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shcreatethreadwithhandle BOOL SHCreateThreadWithHandle( // LPTHREAD_START_ROUTINE pfnThreadProc, void *pData, SHCT_FLAGS flags, LPTHREAD_START_ROUTINE pfnCallback, HANDLE *pHandle ); [DllImport(Lib.Shlwapi, SetLastError = true, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "22a3a97a-857f-46b8-a2e0-8f3a14f40322")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHCreateThreadWithHandle(ThreadProc pfnThreadProc, IntPtr pData, SHCT_FLAGS flags, ThreadProc pfnCallback, out SafeHFILE pHandle); /// /// Deletes an empty key. /// /// /// Type: HKEY /// A handle to an open registry key, or one of the following predefined keys: /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of a null-terminated string specifying the name of the key to delete. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the /// FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// SHDeleteEmptyKey does not delete a key if it contains any subkeys or values. Use SHDeleteKey instead. /// Alternatively, use the RegDeleteKey or RegDeleteTree function. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shdeleteemptykeya LSTATUS SHDeleteEmptyKeyA( HKEY hkey, // LPCSTR pszSubKey ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "6a560bc3-f65e-4b7d-9fbc-b4f2971ce2a9")] public static extern Win32Error SHDeleteEmptyKey(HKEY hkey, string pszSubKey); /// /// Deletes a subkey and all its descendants. This function removes the key and all the key's values from the registry. /// /// /// Type: HKEY /// A handle to an open registry key, or one of the following predefined keys: /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of a null-terminated string specifying the name of the key to delete. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the /// FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// Alternatively, use the RegDeleteKey or RegDeleteTree function. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shdeletekeya LSTATUS SHDeleteKeyA( HKEY hkey, LPCSTR // pszSubKey ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "3c46db08-52d8-48fa-bda5-3c087908a1d3")] public static extern Win32Error SHDeleteKey(HKEY hkey, string pszSubKey); /// /// Deletes a named value from the specified registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of a null-terminated string specifying the name of the subkey for which to change the value. /// /// /// Type: LPCTSTR /// The address of the value to be deleted. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shdeletevaluea LSTATUS SHDeleteValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "54f3459b-486c-4907-84b1-39b1f8abb12d")] public static extern Win32Error SHDeleteValue(HKEY hkey, string pszSubKey, string pszValue); /// /// Enumerates the subkeys of the specified open registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: DWORD /// The index of the subkey to retrieve. This parameter should be zero for the first call and incremented for subsequent calls. /// /// /// Type: LPTSTR /// The address of a character buffer that receives the enumerated key name. /// /// /// Type: LPDWORD /// /// The address of a DWORD that, on entry, contains the size of the buffer at pszName, in characters. On exit, this contains /// the number of characters that were copied to pszName. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shenumkeyexa LSTATUS SHEnumKeyExA( HKEY hkey, DWORD // dwIndex, LPSTR pszName, LPDWORD pcchName ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "51bf9cf7-87bc-407c-b2ee-18db3cdfe1dc")] public static extern Win32Error SHEnumKeyEx(HKEY hkey, uint dwIndex, StringBuilder pszName, ref uint pcchName); /// /// Enumerates the values of the specified open registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: DWORD /// The index of the value to retrieve. This parameter should be zero for the first call and incremented for subsequent calls. /// /// /// Type: LPTSTR /// The address of a character buffer that receives the enumerated value name. The size of this buffer is specified in pcchValueName. /// /// /// Type: LPDWORD /// /// The address of a DWORD that, on entry, contains the size of the buffer at pszValueName, in characters. On exit, this /// contains the number of characters that were copied to pszValueName. /// /// /// /// Type: LPDWORD /// /// The address of a DWORD that receives the data type of the value. These are the same values as those described under the /// lpType parameter of RegEnumValue. /// /// /// /// Type: LPVOID /// /// The address of a buffer that receives the data for the value entry. The size of this buffer is specified in pcbData. This /// parameter can be NULL if the data is not required. /// /// /// /// Type: LPDWORD /// /// The address of a DWORD that, on entry, contains the size of the buffer at pvData, in bytes. On exit, this contains the /// number of bytes that were copied to pvData. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shenumvaluea LSTATUS SHEnumValueA( HKEY hkey, DWORD // dwIndex, PSTR pszValueName, LPDWORD pcchValueName, LPDWORD pdwType, void *pvData, LPDWORD pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "bb0eaa07-5112-4ce3-8796-5439bd863226")] public static extern Win32Error SHEnumValue(HKEY hkey, uint dwIndex, StringBuilder pszValueName, ref uint pcchValueName, ref REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData); /// /// Enumerates the values of the specified open registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: DWORD /// The index of the value to retrieve. This parameter should be zero for the first call and incremented for subsequent calls. /// /// /// Type: LPTSTR /// The address of a character buffer that receives the enumerated value name. The size of this buffer is specified in pcchValueName. /// /// /// Type: LPDWORD /// /// The address of a DWORD that, on entry, contains the size of the buffer at pszValueName, in characters. On exit, this /// contains the number of characters that were copied to pszValueName. /// /// /// /// Type: LPDWORD /// /// The address of a DWORD that receives the data type of the value. These are the same values as those described under the /// lpType parameter of RegEnumValue. /// /// /// /// Type: LPVOID /// /// The address of a buffer that receives the data for the value entry. The size of this buffer is specified in pcbData. This /// parameter can be NULL if the data is not required. /// /// /// /// Type: LPDWORD /// /// The address of a DWORD that, on entry, contains the size of the buffer at pvData, in bytes. On exit, this contains the /// number of bytes that were copied to pvData. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shenumvaluea LSTATUS SHEnumValueA( HKEY hkey, DWORD // dwIndex, PSTR pszValueName, LPDWORD pcchValueName, LPDWORD pdwType, void *pvData, LPDWORD pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "bb0eaa07-5112-4ce3-8796-5439bd863226")] public static extern Win32Error SHEnumValue(HKEY hkey, uint dwIndex, StringBuilder pszValueName, ref uint pcchValueName, ref REG_VALUE_TYPE pdwType, SafeAllocatedMemoryHandle pvData, ref uint pcbData); /// /// /// [ SHFormatDateTime is available for use in the operating systems specified in the Requirements section. It may be altered /// or unavailable in subsequent versions.] /// /// Produces a string representation of a time specified as a FILETIME structure. /// /// /// Type: const FILETIME UNALIGNED* /// A pointer to the FILETIME structure whose time is to be converted to a string. /// /// /// Type: DWORD* /// A pointer to a DWORD value that contains bitwise flags that specify the date and time format. /// /// When you call the function, you can combine zero or more of the following flags, with exceptions as noted. You can also set this /// parameter to NULL, in which case the function assumes that the FDTF_DEFAULT flag is set. /// /// FDTF_SHORTTIME (0x00000001) /// /// 0x00000001. Formats the time of day as specified by the Regional and Language Options application in Control Panel, but /// without seconds. This flag cannot be combined with FDTF_LONGTIME. /// /// The short time was successfully formatted. /// FDTF_SHORTDATE (0x00000002) /// /// 0x00000002. Formats the date as specified by the short date format in the Regional and Language Options application in /// Control Panel. This flag cannot be combined with FDTF_LONGDATE. /// /// The short date was successfully formatted. /// FDTF_DEFAULT /// Equivalent to FDTF_SHORTDATE | FDTF_SHORTTIME. /// FDTF_LONGDATE (0x00000004) /// /// 0x00000004. Formats the date as specified by the long date format in the Regional and Language Options application in /// Control Panel. This flag cannot be combined with FDTF_SHORTDATE. /// /// The long date was successfully formatted. /// FDTF_LONGTIME (0x00000008) /// /// 0x00000008. Formats the time of day as specified by the Regional and Language Options application in Control Panel, /// including seconds. This flag cannot be combined with FDTF_SHORTTIME. /// /// The long time was successfully formatted. /// FDTF_RELATIVE (0x00000010) /// /// 0x00000010. If the FDTF_LONGDATE flag is set and the date in the FILETIME structure is the same date that SHFormatDateTime /// is called, then the day of the week (if present) is changed to "Today". If the date in the structure is the previous day, then /// the day of the week (if present) is changed to "Yesterday". /// /// Relative notation was used for the date. /// FDTF_LTRDATE (0x00000100) /// 0x00000100. Adds marks for left-to-right reading layout. This flag cannot be combined with FDTF_RTLDATE. /// FDTF_RTLDATE (0x00000200) /// 0x00000200. Adds marks for right-to-left reading layout. This flag cannot be combined with FDTF_LTRDATE. /// FDTF_NOAUTOREADINGORDER (0x00000400) /// /// 0x00000400. No reading order marks are inserted. Normally, in the absence of the FDTF_LTRDATE or FDTF_RTLDATE flag, /// SHFormatDateTime determines the reading order from the user's default locale, inserts reading order marks, and updates the /// pdwFlags output value appropriately. This flag prevents that process from occurring. It is used most commonly by legacy callers /// of SHFormatDateTime. This flag cannot be combined with FDTF_RTLDATE or FDTF_LTRDATE. /// /// Windows Server 2003 and Windows XP: This value is not available. /// /// When the function returns, the DWORD value pointed to by this parameter can contain zero or more of the following flags. /// /// FDTF_SHORTTIME (0x00000001) /// /// 0x00000001. Formats the time of day as specified by the Regional and Language Options application in Control Panel, but /// without seconds. This flag cannot be combined with FDTF_LONGTIME. /// /// The short time was successfully formatted. /// FDTF_SHORTDATE (0x00000002) /// /// 0x00000002. Formats the date as specified by the short date format in the Regional and Language Options application in /// Control Panel. This flag cannot be combined with FDTF_LONGDATE. /// /// The short date was successfully formatted. /// FDTF_LONGDATE (0x00000004) /// /// 0x00000004. Formats the date as specified by the long date format in the Regional and Language Options application in /// Control Panel. This flag cannot be combined with FDTF_SHORTDATE. /// /// The long date was successfully formatted. /// FDTF_LONGTIME (0x00000008) /// /// 0x00000008. Formats the time of day as specified by the Regional and Language Options application in Control Panel, /// including seconds. This flag cannot be combined with FDTF_SHORTTIME. /// /// The long time was successfully formatted. /// FDTF_RELATIVE (0x00000010) /// /// 0x00000010. If the FDTF_LONGDATE flag is set and the date in the FILETIME structure is the same date that SHFormatDateTime /// is called, then the day of the week (if present) is changed to "Today". If the date in the structure is the previous day, then /// the day of the week (if present) is changed to "Yesterday". /// /// Relative notation was used for the date. /// /// /// Type: LPTSTR /// /// A pointer to a buffer that receives the formatted date and time. The buffer must be large enough to contain the number of TCHAR /// characters specified by the cchBuf parameter, including a terminating null character. /// /// /// /// Type: UINT /// The number of TCHARs that can be contained by the buffer pointed to by pszBuf. /// /// /// Type: int /// /// Returns the number of TCHARs written to the buffer, including the terminating null character. On failure, this value is 0. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shformatdatetimew int SHFormatDateTimeW( const FILETIME // *pft, DWORD *pdwFlags, LPWSTR pszBuf, UINT cchBuf ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "2208ed29-6029-4051-bdcc-885c42fe5c1b")] public static extern int SHFormatDateTime(in FILETIME pft, ref FDTF pdwFlags, StringBuilder pszBuf, uint cchBuf); /// /// /// [ SHFreeShared is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions.] /// /// Frees shared memory, regardless of which process allocated it. /// /// /// Type: HANDLE /// A handle to the mapped memory. /// /// /// Type: DWORD /// The process ID of the process from which the memory was allocated. /// /// /// Type: BOOL /// Returns TRUE if successful; otherwise, FALSE. To get extended error information, call GetLastError. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shfreeshared BOOL SHFreeShared( HANDLE hData, DWORD // dwProcessId ); [DllImport(Lib.Shlwapi, SetLastError = true, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "5a86ae5d-8caa-4126-a22e-bc3cc7df2381")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHFreeShared(IntPtr hData, uint dwProcessId); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Retrieves the inverse color table mapping for the halftone palette. /// /// /// Type: BYTE* /// /// A pointer to an array of BYTEs that receives the inverse color table mapping, or a pointer to an LPBYTE /// which receives a pointer to a cached copy of the inverse color table mapping, depending on the value of the cbMap parameter. /// /// /// /// Type: ULONG /// The size of the buffer pointed to by pbMap, which also defines its contents. Two values are recognized. /// (sizeof(BYTE*)) /// The buffer pointed to by pbMap receives a pointer to a cached copy of the inverse color map table. /// (32768) /// /// The buffer pointed to by pbMap receives a copy of the inverse color map table. The buffer must be exactly 32,768 bytes in size. /// /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// The inverse color mapping table is a table of 32,768 bytes. It contains the indexes of colors in the halftone palette. Each index /// is stored at a position in the buffer that corresponds to a particular RGB value expressed in 555 format. These pairings allow /// you to find a color in the halftone palette which is a close approximation of the original color. /// /// /// For example, the method for determining a color in the halftone palette that is a close approximation for the color #306040 is as follows: /// /// /// /// /// Decompose the color into its red, green, and blue components. In this case, the red component is 0x30, the green component is /// 0x60 and the blue component is 0x40. /// /// /// /// /// Reassemble the color into 555 format. The formula for reducing a 24-bit RGB color into 555 format is shown here. In this example, /// the value in 555 format is ((0x30 / 8) << 10) + ((0x60 / 8) << 5) + (0x40 / 8) = 6536. /// /// /// /// /// The index value stored in position 6536 in the inverse color map table is the index of the color in the halftone palette that is /// a reasonable approximation to the color #306040. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shgetinversecmap LWSTDAPI SHGetInverseCMAP( BYTE *pbMap, // ULONG cbMap ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "46d5ccd2-3c5d-431b-b27b-6a7a95043e0a")] public static extern HRESULT SHGetInverseCMAP(IntPtr pbMap, uint cbMap); /// /// Retrieves the per-thread object reference set by SHSetThreadRef. /// /// /// Type: IUnknown** /// /// The address of a pointer that, when this function returns successfully, points to the object whose reference is stored. Your /// application is responsible for freeing this resource when it is no longer needed. /// /// /// /// Type: HRESULT /// Returns S_OK if the object reference exists, or E_NOINTERFACE otherwise. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shgetthreadref LWSTDAPI SHGetThreadRef( IUnknown **ppunk ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "307b284b-f493-4d24-a7be-17c150d62b34")] public static extern HRESULT SHGetThreadRef([MarshalAs(UnmanagedType.IUnknown)] out object ppunk); /// /// Retrieves a registry value. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of a null-terminated string that specifies the name of the subkey from which to retrieve the value. /// /// /// Type: LPCTSTR /// The address of the value. /// /// /// Type: LPDWORD /// The type of value. For more information, see Registry Data Types. /// /// /// Type: LPVOID /// The address of the destination data buffer. /// /// /// Type: LPDWORD /// The size of the destination data buffer. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// If your application must set/retrieve a series of values in the same key, it is better to open the key once and set/retrieve the /// values with the regular Microsoft Win32 registry functions rather than use this function repeatedly. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shgetvaluea LSTATUS SHGetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "8cca6bfe-d365-4d10-bc8d-f3bebefaad02")] public static extern Win32Error SHGetValue(HKEY hkey, string pszSubKey, string pszValue, out REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData); /// /// Retrieves a registry value. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of a null-terminated string that specifies the name of the subkey from which to retrieve the value. /// /// /// Type: LPCTSTR /// The address of the value. /// /// /// Type: LPDWORD /// The type of value. For more information, see Registry Data Types. /// /// /// Type: LPVOID /// The address of the destination data buffer. /// /// /// Type: LPDWORD /// The size of the destination data buffer. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// If your application must set/retrieve a series of values in the same key, it is better to open the key once and set/retrieve the /// values with the regular Microsoft Win32 registry functions rather than use this function repeatedly. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shgetvaluea LSTATUS SHGetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "8cca6bfe-d365-4d10-bc8d-f3bebefaad02")] public static extern Win32Error SHGetValue(HKEY hkey, string pszSubKey, string pszValue, out REG_VALUE_TYPE pdwType, SafeAllocatedMemoryHandle pvData, ref uint pcbData); /// /// /// [ SHGetViewStatePropertyBag is available for use in the operating systems specified in the Requirements section. It may be /// altered or unavailable in subsequent versions.] /// /// /// Retrieves a property bag in which the view state information for a folder can be stored and subsequently retrieved. The user's /// settings are kept for the next time the user visits the folder. /// /// /// /// Type: PCIDLIST_ABSOLUTE /// /// A PIDL of the folder for which you are requesting properties. This parameter must be NULL if the SHGVSPB_ALLFOLDERS flag /// is passed. /// /// /// /// Type: PCWSTR /// A pointer to a string that contains the name of the requested property bag. /// /// /// Type: DWORD /// A value that specifies a combination of the following flags. /// One value from the following set of flags is required. /// SHGVSPB_PERUSER /// Returns the per-user properties for the specified pidl. /// SHGVSPB_ALLUSERS /// Returns the All User properties for the specified pidl. /// One value from the following set of flags is required. /// SHGVSPB_PERFOLDER /// Returns the property bag for the folder specified by the pidl parameter. /// SHGVSPB_ALLFOLDERS /// Returns the property bag that applies to all folders. /// SHGVSPB_INHERIT /// Returns the property bag used to provide defaults for subfolders that do not have their property bag. /// The following flags are optional. /// SHGVSPB_ROAM /// Allows the property bag to roam. See Roaming User Profiles. This flag cannot be combined with SHGVSPB_ALLFOLDERS. /// SHGVSPB_NOAUTODEFAULTS /// /// Suppresses the search for a suitable default when the property bag cannot be found for the specified folder. By default, if /// SHGVSPB_INHERIT is not specified and a property bag cannot be found for the specified folder, the system searches for identically /// named property bags in other locations that may be able to provide default values. For example, the system searches in the /// ancestors of the folder to see if any of them provide a SHGVSPB_INHERIT property bag. Other places the system searches are in the /// user defaults and the global defaults. /// /// The following set of flags consists of values that combine some flags listed above, and are used for brevity and convenience. /// SHGVSPB_FOLDER /// Combines SHGVSPB_PERUSER and SHGVSPB_PERFOLDER. /// SHGVSPB_FOLDERNODEFAULTS /// Combines SHGVSPB_PERUSER, SHGVSPB_PERFOLDER, and SHGVSPB_NOAUTODEFAULTS. /// SHGVSPB_USERDEFAULTS /// Combines SHGVSPB_PERUSER and SHGVSPB_ALLFOLDERS. /// SHGVSPB_GLOBALDEFAULTS /// Combines SHGVSPB_ALLUSERS and SHGVSPB_ALLFOLDERS. /// Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: This flag is named SHGVSPB_GLOBALDEAFAULTS. /// /// /// Type: REFIID /// A reference to the IID of the interface to retrieve through ppv. /// /// /// Type: void** /// When this method returns successfully, contains the interface pointer requested in riid. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// /// Critical information should not be stored in the view state property bag because the system keeps only a limited number of view /// states. If a folder is not visited for a long time, its view state is eventually deleted. /// /// /// We recommend that you use the IID_PPV_ARGS macro, defined in Objbase.h, to package the riid and ppv parameters. This macro /// provides the correct IID based on the interface pointed to by the value in ppv, which eliminates the possibility of a coding /// error in riid that could lead to unexpected results. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shgetviewstatepropertybag LWSTDAPI // SHGetViewStatePropertyBag( PCIDLIST_ABSOLUTE pidl, PCWSTR pszBagName, DWORD dwFlags, REFIID riid, void **ppv ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "6852867a-30a5-4d4e-b790-3746104e3ed8")] public static extern HRESULT SHGetViewStatePropertyBag(IntPtr pidl, [MarshalAs(UnmanagedType.LPWStr)] string pszBagName, SHGVSPB dwFlags, in Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Compares whether a window is equal to, a child of, or a descendant of, a second window. /// /// /// Type: HWND /// A handle to the first window. /// /// /// Type: HWND /// A handle to a window to be tested against hwndParent. /// /// /// Type: HRESULT /// /// Returns S_OK if the window specified by hwnd is equal to, a child of, or a descendent of the window specified by /// hwndParent. Returns S_FALSE if the window specified by hwnd is not equal to, not a child of, and not a descendent of the /// window specified by hwndParent. The return value is undefined if either window handle is invalid. /// /// // HRESULT SHIsChildOrSelf( _In_ HWND hwndParent, _In_ HWND hwnd); https://msdn.microsoft.com/en-us/library/windows/desktop/bb773834(v=vs.85).aspx [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("Shlwapi.h", MSDNShortId = "bb773834")] public static extern HRESULT SHIsChildOrSelf([In] HWND hwndParent, [In] HWND hwnd); /// /// Not supported. /// /// /// Type: DWORD /// The type of machine being examined. The following is the only recognized value. /// ILMM_IE4 /// /// An older (circa 1997), low-end machine. Since system resources in general were lower on these older machines, the low-memory /// threshold is accordingly lower. /// /// /// /// Type: BOOL /// TRUE if the machine is considered low on resources, FALSE otherwise. /// Note Always returns FALSE under Windows XP. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shislowmemorymachine BOOL SHIsLowMemoryMachine( DWORD // dwType ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "3a91156d-eef9-4d3c-9cb8-fd50bfa94354")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHIsLowMemoryMachine(uint dwType = 0); /// /// Extracts a specified text resource when given that resource in the form of an indirect string (a string that begins with the '@' symbol). /// /// /// Type: PCWSTR /// /// A pointer to a buffer that contains the indirect string from which the resource will be retrieved. This string should begin with /// the '@' symbol and use one of the forms discussed in the Remarks section. This function will successfully accept a string that /// does not begin with an '@' symbol, but the string will be simply passed unchanged to pszOutBuf. /// /// /// /// Type: PWSTR /// /// A pointer to a buffer that, when this function returns successfully, receives the text resource. Both pszOutBuf and pszSource /// can point to the same buffer, in which case the original string will be overwritten. /// /// /// /// Type: UINT /// The size of the buffer pointed to by pszOutBuf, in characters. /// /// /// Type: void** /// Not used; set to NULL. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// An indirect string can be provided in several forms, each of which has its own interpretation: /// /// /// /// File name and resource ID The string is extracted from the file named, using the resource value as a locator. If the /// resource value is zero or greater, the number becomes the index of the string in the binary file. If the number is negative, it /// becomes a resource ID. The retrieved string is copied to the output buffer and the function returns S_OK. /// /// /// /// /// File name and resource ID with a version modifier This form can be used when a resource is changed but still uses the /// same index or ID as the old resource. Without a version modifier, the Multilingual User Interface (MUI) cache will not recognize /// that the resource has changed and will not refresh. By appending the version modifier, the value is seen as a new resource and /// is added to the cache. Note that it is recommended that you use a new ID or index for a new resource, and use a version modifier /// only when that is not possible. /// /// /// /// /// PRI file path and resource ID The Package Resource Index (PRI) is a binary format introduced in Windows 8 that contains /// indexed resources or references to resources. The .pri file is bundled as part of an app's package. For more information on .pri /// files, see Creating and retrieving resources in Windows Store apps. /// /// /// /// /// Package name and resource ID The string is extracted from the Resources.pri file stored in the app's root directory of /// the package identified by PackageFullName, using the resource as a locator. The retrieved string is copied to the output buffer /// and the function returns S_OK. The string is extracted based on the app's environment or ResourceContext. An example of this /// type of indirect string is shown here. In this example, the reference name is fully-qualified, but it contains no namespace (for /// example, "resources"). The deployment stack expands the name to look for it in all namespaces. /// /// /// /// /// If the string is not an indirect string, then the string is directly copied without change to pszOutBuf and the function returns S_OK. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shloadindirectstring LWSTDAPI SHLoadIndirectString( PCWSTR // pszSource, PWSTR pszOutBuf, UINT cchOutBuf, void **ppvReserved ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f0265cd8-deb8-4bca-b379-39aff49c7df1")] public static extern HRESULT SHLoadIndirectString([MarshalAs(UnmanagedType.LPWStr)] string pszSource, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved = default); /// /// Extracts a specified text resource when given that resource in the form of an indirect string (a string that begins with the '@' symbol). /// /// /// Type: PCWSTR /// /// A pointer to a buffer that contains the indirect string from which the resource will be retrieved. This string should begin with /// the '@' symbol and use one of the forms discussed in the Remarks section. This function will successfully accept a string that /// does not begin with an '@' symbol, but the string will be simply passed unchanged to pszOutBuf. /// /// /// /// Type: PWSTR /// /// A pointer to a buffer that, when this function returns successfully, receives the text resource. Both pszOutBuf and pszSource /// can point to the same buffer, in which case the original string will be overwritten. /// /// /// /// Type: UINT /// The size of the buffer pointed to by pszOutBuf, in characters. /// /// /// Type: void** /// Not used; set to NULL. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// An indirect string can be provided in several forms, each of which has its own interpretation: /// /// /// /// File name and resource ID The string is extracted from the file named, using the resource value as a locator. If the /// resource value is zero or greater, the number becomes the index of the string in the binary file. If the number is negative, it /// becomes a resource ID. The retrieved string is copied to the output buffer and the function returns S_OK. /// /// /// /// /// File name and resource ID with a version modifier This form can be used when a resource is changed but still uses the /// same index or ID as the old resource. Without a version modifier, the Multilingual User Interface (MUI) cache will not recognize /// that the resource has changed and will not refresh. By appending the version modifier, the value is seen as a new resource and /// is added to the cache. Note that it is recommended that you use a new ID or index for a new resource, and use a version modifier /// only when that is not possible. /// /// /// /// /// PRI file path and resource ID The Package Resource Index (PRI) is a binary format introduced in Windows 8 that contains /// indexed resources or references to resources. The .pri file is bundled as part of an app's package. For more information on .pri /// files, see Creating and retrieving resources in Windows Store apps. /// /// /// /// /// Package name and resource ID The string is extracted from the Resources.pri file stored in the app's root directory of /// the package identified by PackageFullName, using the resource as a locator. The retrieved string is copied to the output buffer /// and the function returns S_OK. The string is extracted based on the app's environment or ResourceContext. An example of this /// type of indirect string is shown here. In this example, the reference name is fully-qualified, but it contains no namespace (for /// example, "resources"). The deployment stack expands the name to look for it in all namespaces. /// /// /// /// /// If the string is not an indirect string, then the string is directly copied without change to pszOutBuf and the function returns S_OK. /// /// // https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-shloadindirectstring LWSTDAPI SHLoadIndirectString( PCWSTR // pszSource, PWSTR pszOutBuf, UINT cchOutBuf, void **ppvReserved ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "NF:shlwapi.SHLoadIndirectString")] public static extern HRESULT SHLoadIndirectString([MarshalAs(UnmanagedType.LPWStr)] string pszSource, IntPtr pszOutBuf, uint cchOutBuf, IntPtr ppvReserved = default); /// /// /// [ SHLockShared is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions.] /// /// Maps a block of memory from a specified process into the calling process. /// /// /// Type: HANDLE /// A handle to the memory you want to map into the calling process. /// /// /// Type: DWORD /// The process ID of the process from which you want to map the block of memory. /// /// /// Returns a void pointer to the shared memory. Returns NULL if unsuccessful. /// /// /// Call SHUnlockShared to unlock the memory that this function maps. Call SHFreeShared to release the memory. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shlockshared void * SHLockShared( HANDLE hData, DWORD // dwProcessId ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "5b948044-6cec-4649-a266-21959154f999")] public static extern IntPtr SHLockShared(IntPtr hData, uint dwProcessId); /// /// /// [ SHMessageBoxCheck is available for use in the operating systems specified in the Requirements section. It may be altered /// or unavailable in subsequent versions.] /// /// /// Displays a message box that gives the user the option of suppressing further occurrences. If the user has already opted to /// suppress the message box, the function does not display a dialog box and instead simply returns the default value. /// /// /// /// Type: HWND /// The window handle to the message box's owner. This value can be NULL. /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string that contains the message to be displayed. /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that contains the title of the message box. If this parameter is set to NULL, the /// title is set to Error!. /// /// /// /// Type: UINT /// /// The flags that specify the contents and behavior of the message box. This function supports only a subset of the flags supported /// by MessageBox. If you use any flags that are not listed below, the function's behavior is undefined. /// /// You must specify the buttons to be displayed by setting one and only one of the following flags. /// MB_OKCANCEL /// Display a message box with OK and Cancel buttons. /// MB_YESNO /// Display a message box with Yes and No buttons. /// MB_OK /// Display a message box with an OK button. /// You can display an optional icon by setting one and only one of the following flags. /// MB_ICONHAND /// Display a stop-sign icon. /// MB_ICONQUESTION /// Display a question-mark icon. /// MB_ICONEXCLAMATION /// Display an exclamation-point icon. /// MB_ICONINFORMATION /// Display an icon with a lowercase "i" in a circle. /// /// /// Type: int /// /// The value that the function returns when the user has opted not to have the message box displayed again. If the user has not /// opted to suppress the message box, the message box is displayed and the function ignores iDefault. /// /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that contains a unique string value to associate with this message. To avoid collisions /// with values used by Microsoft, this string should include a GUID. This string must not exceed REGSTR_MAX_VALUE_LENGTH characters /// in length, including the terminating null character. /// /// /// /// Type: int /// If the user has already chosen to suppress the message box, the function immediately returns the value assigned to iDefault. /// /// If the user clicks the OK, Cancel, Yes, or No button, the function returns IDOK, IDCANCEL, IDYES, or /// IDNO, respectively. /// /// /// If the user closes the message box by clicking the X button in the caption, the function returns IDCANCEL. This value is /// returned in this case even if the MB_OKCANCEL flag has not been set. /// /// /// If an error occurs, the return value is normally –1. However, under certain low-memory conditions, the function might return iDefault. /// /// /// /// /// Security Warning: Do not take any dangerous actions if the function returns either –1 or iDefault. If an error occurs when /// attempting to display the message box, SHMessageBoxCheck returns –1 or, in some cases, iDefault. Such errors can be caused /// by insufficient memory or resources. If you get one of these return values, you should be aware that the user did not necessarily /// see the dialog box and consequently did not positively agree to any action. /// /// /// Do not confuse "Do not show this dialog box" with "Remember this answer". SHMessageBoxCheck does not provide "Remember /// this answer" functionality. If the user chooses to suppress the message box again, the function does not preserve which button /// they clicked. Instead, subsequent invocations of SHMessageBoxCheck simply return the value specified by iDefault. Consider /// the following example. /// /// /// If the user selects In the future, do not show me this dialog box and clicks the Yes button, /// SHMessageBoxCheck returns IDYES. However, the next time this code is executed, SHMessageBoxCheck does not return /// IDYES, even though the user selected Yes originally. Instead, it returns IDNO, because that is the value specified by iDefault. /// /// /// The default button displayed by the message box should agree with your iDefault value. The lack of support for the MB_DEFBUTTON2 /// flag means that iDefault should be set to IDOK if you have specified the MB_OK or MB_OKCANCEL flag. The iDefault value should be /// set to IDYES if you have set the MB_YESNO flag. /// /// SHMessageBoxCheck records the message boxes that the user has chosen to suppress under the following registry key. /// SoftwareMicrosoftWindowsCurrentVersionExplorerLowRegistryDontShowMeThisDialogAgain /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shmessageboxchecka int SHMessageBoxCheckA( HWND hwnd, // LPCSTR pszText, LPCSTR pszCaption, UINT uType, int iDefault, LPCSTR pszRegVal ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "7e62cde0-2b9f-44d3-afb8-5df71f98453a")] public static extern int SHMessageBoxCheck(HWND hwnd, string pszText, string pszCaption, uint uType, int iDefault, string pszRegVal); /// /// // IStream *SHOpenRegStream2( HKEY hkey, LPCTSTR pszSubkey, LPCTSTR pszValue, DWORD grfMode ); https://msdn.microsoft.com/en-us/library/bb759879(v=vs.85).aspx [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "bb759879")] public static extern IStream SHOpenRegStream2(HKEY hkey, string pszSubkey, string pszValue, STGM grfMode); /// /// Retrieves information about a specified registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPDWORD /// The address of a DWORD that receives the number of subkeys under the specified key. /// /// /// Type: LPDWORD /// The address of a DWORD that receives the number of characters in the name of the subkey with the largest name. /// /// /// Type: LPDWORD /// The address of a DWORD that receives the number of values under the specified key. /// /// /// Type: LPDWORD /// The address of a DWORD that receives the number of characters in the name of the value with the largest name. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shqueryinfokeya LSTATUS SHQueryInfoKeyA( HKEY hkey, // LPDWORD pcSubKeys, LPDWORD pcchMaxSubKeyLen, LPDWORD pcValues, LPDWORD pcchMaxValueNameLen ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "dea535e7-5e61-4587-aa22-b1d62b76943a")] public static extern Win32Error SHQueryInfoKey(HKEY hkey, out uint pcSubKeys, out uint pcchMaxSubKeyLen, out uint pcValues, out uint pcchMaxValueNameLen); /// /// Opens a registry key and queries it for a specific value. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// The address of the null-terminated string that contains the name of the value to be queried. /// /// /// Type: LPDWORD /// Reserved. Must be NULL. /// /// /// Type: LPDWORD /// The address of the variable that receives the key's value type. For more information, see Registry Data Types. /// /// /// Type: LPVOID /// The address of the buffer that receives the value's data. This parameter can be NULL if the data is not required. /// /// /// Type: LPDWORD /// /// The address of the variable that specifies the size, in bytes, of the buffer pointed to by the pvData parameter. When the /// function returns, this variable contains the size of the data copied to pvData. /// /// /// /// Type: DWORD /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shqueryvalueexa LSTATUS SHQueryValueExA( HKEY hkey, LPCSTR // pszValue, DWORD *pdwReserved, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "9969acae-5965-40fe-bde9-6de9ddf26bb8")] public static extern Win32Error SHQueryValueEx(HKEY hkey, string pszValue, [Optional] IntPtr pdwReserved, out REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData); /// /// Closes a handle to a user-specific registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. Use FormatMessage with the /// FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregcloseuskey LSTATUS SHRegCloseUSKey( HUSKEY hUSKey ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "1e9900d6-8411-4e6b-a9c0-006f378a2625")] public static extern Win32Error SHRegCloseUSKey(HUSKEY hUSKey); /// /// Creates or opens a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that contains the subkey to be created or opened. If a value with this name is already /// present in the subkey, it will be opened. /// /// /// /// Type: REGSAM /// The desired security access. For more information on security access, see REGSAM. /// /// /// Type: HUSKEY /// /// The key to be used as a base for relative paths. If pszPath is a relative path, the key it specifies will be relative to /// hRelativeUSKey. If pszPath is an absolute path, set hRelativeUSKey to NULL. The key will then be created under /// HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER, depending the value of dwFlags. /// /// /// /// Type: PHUSKEY /// A pointer to an HUSKEY that will receive the handle to the new key. /// /// /// Type: DWORD /// The base key under which the key should be opened. This can be one or more of the following values. /// SHREGSET_HKCU /// Create/open the key under HKEY_CURRENT_USER. Only creates a key if it is empty. /// SHREGSET_FORCE_HKCU /// Create/open the key under HKEY_CURRENT_USER. Creates a key even if it is not empty. /// SHREGSET_HKLM /// Create/open the key under HKEY_LOCAL_MACHINE. Only creates a key if it is empty. /// SHREGSET_FORCE_HKLM /// Create/open the key under HKEY_LOCAL_MACHINE. Creates a key even if it is not empty. /// SHREGSET_DEFAULT /// /// Create/open the key under both HKEY_CURRENT_USER (forced) and HKEY_LOCAL_MACHINE (only if empty). This flag is the /// equivalent of ( SHREGSET_FORCE_HKCU | SHREGSET_HKLM). /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// If you want to write values to the new key, use SHRegWriteUSValue to write each value, passing the HUSKEY handle that is /// returned through phNewUSKey. When you have finished, close the user-specific registry key with SHRegCloseUSKey. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregcreateuskeya LSTATUS SHRegCreateUSKeyA( LPCSTR // pszPath, REGSAM samDesired, HUSKEY hRelativeUSKey, PHUSKEY phNewUSKey, DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "10e3e31e-bff6-4260-95fa-2d750de16ab3")] public static extern Win32Error SHRegCreateUSKey(string pszPath, uint samDesired, HUSKEY hRelativeUSKey, out SafeHUSKEY phNewUSKey, SHREGSET dwFlags); /// /// Deletes an empty registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// TBD /// /// /// Type: SHREGDEL_FLAGS /// One of the SHREGDEL_FLAGS that specifies from which base key the subkey will be deleted. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregdeleteemptyuskeya LSTATUS SHRegDeleteEmptyUSKeyA( // HUSKEY hUSKey, LPCSTR pszSubKey, SHREGDEL_FLAGS delRegFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "adb09a2b-674c-472d-9f16-8e150476f1f5")] public static extern Win32Error SHRegDeleteEmptyUSKey(HUSKEY hUSKey, string pszSubKey, SHREGDEL_FLAGS delRegFlags); /// /// Deletes a registry subkey value in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// Type: LPCTSTR /// A pointer to the null-terminated string that names the value to remove. /// /// /// Type: SHREGDEL_FLAGS /// One of the SHREGDEL_FLAGS that specifies from which base key the value will be deleted. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregdeleteusvaluea LSTATUS SHRegDeleteUSValueA( HUSKEY // hUSKey, LPCSTR pszValue, SHREGDEL_FLAGS delRegFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "f70407af-d8ee-4333-be32-01887d4add4c")] public static extern Win32Error SHRegDeleteUSValue(HUSKEY hUSKey, string pszValue, SHREGDEL_FLAGS delRegFlags); /// /// Duplicates a registry key's HKEY handle. /// /// /// Type: HKEY /// The HKEY handle to be duplicated. /// /// /// Type: HKEY /// Returns a duplicate of the handle specified in hkey. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregduplicatehkey HKEY SHRegDuplicateHKey( HKEY hkey ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "73182aa9-0c4d-4723-ba3c-8bab6b51181b")] public static extern SafeRegistryHandle SHRegDuplicateHKey(HKEY hkey); /// /// Enumerates the subkeys of a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// Type: DWORD /// The index of the subkey to retrieve. This parameter should be zero for the first call and incremented for subsequent calls. /// /// /// Type: LPTSTR /// A pointer to a character buffer that receives the enumerated key name. /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that, on entry, contains the size of the buffer at pszName, in characters. On exit, this contains the number /// of characters that were copied to pszName. /// /// /// /// Type: SHREGENUM_FLAGS /// A SHREGENUM_FLAGS that specifies the base key in which the enumeration should take place. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregenumuskeya LSTATUS SHRegEnumUSKeyA( HUSKEY hUSKey, // DWORD dwIndex, LPSTR pszName, LPDWORD pcchName, SHREGENUM_FLAGS enumRegFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "9418ad45-f451-4976-afd7-fa1e0088038d")] public static extern Win32Error SHRegEnumUSKey(HUSKEY hUSKey, uint dwIndex, StringBuilder pszName, ref uint pcchName, SHREGENUM_FLAGS enumRegFlags); /// Enumerates the values of the specified registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// Type: DWORD /// The index of the value to retrieve. This parameter should be zero for the first call and incremented for subsequent calls. /// /// /// Type: LPTSTR /// A pointer to a character buffer that receives the enumerated value name. The size of this buffer is specified in pcchValueNameLen. /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that, on entry, contains the size of the buffer at pszValueName, in characters. On exit, this /// contains the number of characters that were copied to pszValueName. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that receives the data type of the value. These are the same values as those described under the /// lpType parameter of RegEnumValue. /// /// /// /// Type: void* /// /// A pointer to a buffer that receives the data for the value entry. The size of this buffer is specified in pcbData. This parameter /// can be NULL if the data is not required. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that, on entry, contains the size of the buffer at pvData. On exit, this contains the number of bytes /// that were copied to pvData. /// /// /// /// Type: SHREGENUM_FLAGS /// One of the SHREGENUM_FLAGS that specifies the base key in which the enumeration should take place. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the /// FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://msdn.microsoft.com/en-us/windows/desktop/bb773520 [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("Shlwapi.h", MSDNShortId = "bb773520")] public static extern Win32Error SHRegEnumUSValue(HUSKEY hUSKey, uint dwIndex, StringBuilder pszValueName, ref uint pcchValueNameLen, out REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData, SHREGENUM_FLAGS enumRegFlags); /// /// Retrieves a Boolean value from a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string with the name of the subkey relative to HKEY_LOCAL_MACHINE and /// HKEY_CURRENT_USER. For example, "Software\MyCompany\MyProduct". /// /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string that specifies the name of the value. This value can be NULL. /// /// /// Type: BOOL /// /// A variable that specifies which key to look under. When set to TRUE, SHRegGetUSValue ignores HKEY_CURRENT_USER and /// returns a value from HKEY_LOCAL_MACHINE. /// /// /// /// Type: BOOL /// A value that is returned if there is no registry value. /// /// /// Type: BOOL /// Returns either the value from the registry, or fDefault if none is found. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetboolusvaluea BOOL SHRegGetBoolUSValueA( LPCSTR // pszSubKey, LPCSTR pszValue, BOOL fIgnoreHKCU, BOOL fDefault ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "afd95ce4-0ced-48ce-814f-1d02d7913be5")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHRegGetBoolUSValue(string pszSubKey, string pszValue, [MarshalAs(UnmanagedType.Bool)] bool fIgnoreHKCU, [MarshalAs(UnmanagedType.Bool)] bool fDefault); /// /// [This function is no longer supported.] /// /// Evaluates a registry key value and returns a boolean value that reflects whether the value exists and the expected state matches /// the actual state. This function will first check HKEY_CURRENT_USER for the requested information in the specified subkey. If the /// information does not exist under the HKEY_CURRENT_USER subtree it will check the HKEY_LOCAL_MACHINE subtree for the same information. /// /// /// /// Type: PCWSTR /// A pointer to a null-terminated Unicode string that specifies the path to the key to be checked. /// /// /// Type: PCWSTR /// A pointer to a null-terminated Unicode string that specifies the value to be evaluated. /// /// /// Type: BOOL /// The expected state of the evaluation, as defined by the calling function. /// /// /// Type: BOOL /// TRUE if the evaluation matches the fDefault value; otherwise, FALSE. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetboolvaluefromhkcuhklm BOOL // SHRegGetBoolValueFromHKCUHKLM( PCWSTR pszKey, PCWSTR pszValue, BOOL fDefault ); [DllImport(Lib.Shell32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("shlwapi.h", MSDNShortId = "05239aef-a6cf-426f-919e-08b70baee3f8")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHRegGetBoolValueFromHKCUHKLM(string pszKey, string pszValue, [MarshalAs(UnmanagedType.Bool)] bool fDefault); /// /// Reads a numeric string value from the registry and converts it to an integer. /// /// /// Type: HKEY /// A handle to the registry key that specifies the value to be read. /// /// /// TBD /// /// /// TBD /// /// /// Type: int /// Returns the converted string as an int, or the default value specified by nDefault. /// /// /// /// Prior to Windows 2000 Service Pack 3 (SP3), Windows Server 2003 Service Pack 1 (SP1), and Windows XP, SHRegGetIntW was not /// exported by name. On those systems you must load it directly from Shlwapi.dll as ordinal 280. /// /// This function is only available in a Unicode version. ANSI is not supported. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetintw int SHRegGetIntW( HKEY hk, PCWSTR pwzKey, int // iDefault ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "027e3470-46be-4d37-b815-e1fd550d0c60")] public static extern int SHRegGetIntW(IntPtr hk, [MarshalAs(UnmanagedType.LPWStr)] string pwzKey, int iDefault); /// /// Retrieves a file path from the registry, expanding environment variables as needed. /// /// /// TBD /// /// /// TBD /// /// /// TBD /// /// /// Type: LPTSTR /// /// A buffer to hold the expanded path. You should set the size of this buffer to MAX_PATH to ensure that it is large enough /// to hold the returned string. /// /// /// /// Type: DWORD /// Reserved. /// /// /// Type: LSTATUS /// Returns ERROR_SUCCESS if successful, or a Windows error code otherwise. /// /// /// /// The data type of the specified registry value must be either REG_EXPAND_SZ or REG_SZ. If it has the /// REG_EXPAND_SZ type, any environment variables in the registry string will be expanded with ExpandEnvironmentStrings. If it /// has the REG_SZ data type, environment variables will not be expanded and the string pointed to by pszPath will be /// identical to the string in the registry. /// /// The following environment strings will be replaced by their equivalent path. /// /// /// Environment string /// Folder /// /// /// %USERPROFILE% /// The current user's profile folder /// /// /// %ALLUSERSPROFILE% /// The All Users profile folder /// /// /// %ProgramFiles% /// The Program Files folder /// /// /// %SystemRoot% /// The system root folder /// /// /// %SystemDrive% /// The system drive letter /// /// /// /// Note %USERPROFILE% is relative to the user making the call. This function does not work if the user is being impersonated /// from a service. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetpatha LSTATUS SHRegGetPathA( HKEY hKey, LPCSTR // pcszSubKey, LPCSTR pcszValue, LPSTR pszPath, DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "2874b868-33f9-4f20-9e0b-136125cf268c")] public static extern Win32Error SHRegGetPath(HKEY hKey, string pcszSubKey, string pcszValue, StringBuilder pszPath, uint dwFlags = 0); /// /// Retrieves a value from a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string with the name of the subkey relative to HKEY_LOCAL_MACHINE and /// HKEY_CURRENT_USER. For example: "Software\MyCompany\MyProduct". /// /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string with the name of the value. This value can be NULL. /// /// /// Type: DWORD* /// /// A pointer to a DWORD that receives the type of data stored in the retrieved value. When using default values, the input /// pdwType is the type of the default value. For possible values, see Registry Data Types. If type information is not required, this /// parameter can be NULL. /// /// /// /// Type: void* /// A pointer to a buffer that receives the value's data. /// /// /// Type: DWORD* /// /// A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by pvData. When SHRegGetUSValue /// returns, pcbData contains the size of the data copied to pvData. /// /// /// /// Type: BOOL /// /// A variable that specifies which key to look under. When set to TRUE, SHRegGetUSValue ignores /// HKEY_CURRENT_USER and returns the value from the key under HKEY_LOCAL_MACHINE. /// /// /// /// Type: void* /// A pointer to a buffer that receives the value's default data. /// /// /// Type: DWORD /// The length, in bytes, of the buffer pointed to by pvDefaultData. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// When fIgnoreHKCU is set to TRUE, SHRegGetUSValue returns the value from the key under HKEY_LOCAL_MACHINE. /// When set to FALSE, SHRegGetUSValue first tries to return the value from the key under HKEY_CURRENT_USER. /// However, if the key is not found under HKEY_CURRENT_USER, the value is returned from the key under /// HKEY_LOCAL_MACHINE. If neither key is present, or if an error occurred and dwDefaultDataSize is nonzero, then the default /// data is copied to pvData and ERROR_SUCCESS returns. ERROR_SUCCESS returns for both default and non-default data, and there is no /// way of distinguishing which value copies to pvData. To prevent the use of default data, set pvDefaultData to NULL and /// dwDefaultDataSize to zero. /// /// /// This function opens the key each time it is used. If your code involves getting a series of values from the same key, it is more /// efficient to open the key once with SHRegOpenUSKey and then use SHRegQueryUSValue to retrieve the data. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetusvaluea LSTATUS SHRegGetUSValueA( LPCSTR // pszSubKey, LPCSTR pszValue, DWORD *pdwType, void *pvData, DWORD *pcbData, BOOL fIgnoreHKCU, void *pvDefaultData, DWORD // dwDefaultDataSize ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "4d3b3bbe-dc2e-40c9-8ff1-0f9d2e323743")] public static extern Win32Error SHRegGetUSValue(string pszSubKey, string pszValue, ref REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData, [MarshalAs(UnmanagedType.Bool)] bool fIgnoreHKCU, IntPtr pvDefaultData, uint dwDefaultDataSize); /// /// Retrieves a value from a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string with the name of the subkey relative to HKEY_LOCAL_MACHINE and /// HKEY_CURRENT_USER. For example: "Software\MyCompany\MyProduct". /// /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string with the name of the value. This value can be NULL. /// /// /// Type: DWORD* /// /// A pointer to a DWORD that receives the type of data stored in the retrieved value. When using default values, the input /// pdwType is the type of the default value. For possible values, see Registry Data Types. If type information is not required, this /// parameter can be NULL. /// /// /// /// Type: void* /// A pointer to a buffer that receives the value's data. /// /// /// Type: DWORD* /// /// A pointer to a variable that specifies the size, in bytes, of the buffer pointed to by pvData. When SHRegGetUSValue /// returns, pcbData contains the size of the data copied to pvData. /// /// /// /// Type: BOOL /// /// A variable that specifies which key to look under. When set to TRUE, SHRegGetUSValue ignores /// HKEY_CURRENT_USER and returns the value from the key under HKEY_LOCAL_MACHINE. /// /// /// /// Type: void* /// A pointer to a buffer that receives the value's default data. /// /// /// Type: DWORD /// The length, in bytes, of the buffer pointed to by pvDefaultData. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// When fIgnoreHKCU is set to TRUE, SHRegGetUSValue returns the value from the key under HKEY_LOCAL_MACHINE. /// When set to FALSE, SHRegGetUSValue first tries to return the value from the key under HKEY_CURRENT_USER. /// However, if the key is not found under HKEY_CURRENT_USER, the value is returned from the key under /// HKEY_LOCAL_MACHINE. If neither key is present, or if an error occurred and dwDefaultDataSize is nonzero, then the default /// data is copied to pvData and ERROR_SUCCESS returns. ERROR_SUCCESS returns for both default and non-default data, and there is no /// way of distinguishing which value copies to pvData. To prevent the use of default data, set pvDefaultData to NULL and /// dwDefaultDataSize to zero. /// /// /// This function opens the key each time it is used. If your code involves getting a series of values from the same key, it is more /// efficient to open the key once with SHRegOpenUSKey and then use SHRegQueryUSValue to retrieve the data. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetusvaluea LSTATUS SHRegGetUSValueA( LPCSTR // pszSubKey, LPCSTR pszValue, DWORD *pdwType, void *pvData, DWORD *pcbData, BOOL fIgnoreHKCU, void *pvDefaultData, DWORD // dwDefaultDataSize ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "4d3b3bbe-dc2e-40c9-8ff1-0f9d2e323743")] public static extern Win32Error SHRegGetUSValue(string pszSubKey, string pszValue, ref REG_VALUE_TYPE pdwType, SafeAllocatedMemoryHandle pvData, ref uint pcbData, [MarshalAs(UnmanagedType.Bool)] bool fIgnoreHKCU, SafeAllocatedMemoryHandle pvDefaultData, uint dwDefaultDataSize); /// /// /// [ SHRegGetValue may be altered or unavailable in subsequent versions of the operating system or product. Use RegGetValue /// in its place.] /// /// Retrieves a registry value. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that specifies the relative path from hkey to the subkey to retrieve the value from. /// This parameter can be NULL or an empty string, in which case the data is retrieved from the hkey location. /// /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that contains the name of the value. This parameter can be NULL or an empty /// string, in which case the data is retrieved from the Default value. /// /// /// /// Type: SRRF /// /// One or more of the SRRF flags that restricts the data to be retrieved. At least one type restriction (SRRF_RT) value must be specified. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that receives the type of data stored in the retrieved value. When using default values, the input /// pdwType is the type of the default value. For possible values, see Registry Data Types. If the SRRF_NOEXPAND flag is not set, /// REG_EXPAND_SZ types are automatically expanded and returned as REG_SZ. If type information is not required, this parameter can be NULL. /// /// /// /// Type: LPVOID /// /// A pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not needed. For example, /// if you were testing only for a value's existence, the specific value data would be superfluous. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that, on entry, contains the size of the destination data buffer pvData, in bytes. This value can be /// NULL only if pvData is NULL. On exit, pcbData points to one of these values. /// /// /// /// pvData /// Return Value /// pcbData /// /// /// NULL /// ERROR_SUCCESS /// /// Size in bytes sufficient to hold the registry data. Note that this is not guaranteed to be the precise size, but only a /// sufficient size. /// /// /// /// Non-NULL /// ERROR_SUCCESS /// Exact number of bytes written to pvData. /// /// /// Non-NULL /// ERROR_MORE_DATA /// /// Size in bytes needed to hold the entire data. Note that this is not guaranteed to be the precise size, but only a sufficient size. /// /// /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the /// FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// SHRegGetValue provides data type checking, boot mode checking, auto-expansion of REG_EXPAND_SZ data, and guaranteed /// null-termination of REG_SZ, REG_EXPAND_SZ, and REG_MULTI_SZ data. /// /// /// The key identified by hkey must have been opened with KEY_QUERY_VALUE security access. If pszSubKey is not NULL or an /// empty string, that key also must be able to be opened with KEY_QUERY_VALUE security access in the current calling context. /// /// /// If the data's type is REG_SZ, REG_EXPAND_SZ or REG_MULTI_SZ, then any returned data includes or takes into account the string's /// null-termination. For example, if pvData is not NULL, the data returned in that buffer is null-terminated. /// If pcbData is not NULL, the buffer size that it points to includes the bytes required to hold the terminating null character. /// /// /// Unless the SRRF_NOEXPAND flag is set, string data of type REG_EXPAND_SZ is automatically expanded before being returned. The /// expanded string's type is reported in pdwType as REG_SZ, the pcbData parameter points to the number of bytes written for the /// expanded string, and the buffer pointed to by pvData holds the expanded version of the string. /// /// Performance Notes /// /// If pszSubKey is not NULL or an empty string, that key is opened and closed by this function each time it is accessed. If /// your application must retrieve a series of values from the same subkey, you will see better performance by opening the key using /// RegOpenKeyEx before calling SHRegGetValue. Use the key returned in the phkResult parameter of RegOpenKeyEx as the /// hkey parameter in this function, with pszSubKey set to NULL. /// /// /// The potential for an additional call to the registry to read or re-read the data exists when the data type is REG_EXPAND_SZ and /// the SRRF_NOEXPAND flag has not been set. The following conditions result in that additional call. /// /// /// /// /// pvData is NULL, pcbData is not NULL. Though the data is not retrieved, the registry must be read to get the string /// and that string expanded to determine the required size of the data buffer. /// /// /// /// /// pvData is not NULL, but is too small to hold the data. The data is re-read to get the full string, the string is expanded, /// and the total required size is determined. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetvaluea LSTATUS SHRegGetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, SRRF srrfFlags, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "5650eb4c-40fd-47d7-af76-2688d62d9bca")] public static extern Win32Error SHRegGetValue(HKEY hkey, string pszSubKey, string pszValue, SRRF srrfFlags, ref REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData); /// /// /// [ SHRegGetValue may be altered or unavailable in subsequent versions of the operating system or product. Use RegGetValue /// in its place.] /// /// Retrieves a registry value. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that specifies the relative path from hkey to the subkey to retrieve the value from. /// This parameter can be NULL or an empty string, in which case the data is retrieved from the hkey location. /// /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string that contains the name of the value. This parameter can be NULL or an empty /// string, in which case the data is retrieved from the Default value. /// /// /// /// Type: SRRF /// /// One or more of the SRRF flags that restricts the data to be retrieved. At least one type restriction (SRRF_RT) value must be specified. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that receives the type of data stored in the retrieved value. When using default values, the input /// pdwType is the type of the default value. For possible values, see Registry Data Types. If the SRRF_NOEXPAND flag is not set, /// REG_EXPAND_SZ types are automatically expanded and returned as REG_SZ. If type information is not required, this parameter can be NULL. /// /// /// /// Type: LPVOID /// /// A pointer to a buffer that receives the value's data. This parameter can be NULL if the data is not needed. For example, /// if you were testing only for a value's existence, the specific value data would be superfluous. /// /// /// /// Type: LPDWORD /// /// A pointer to a DWORD that, on entry, contains the size of the destination data buffer pvData, in bytes. This value can be /// NULL only if pvData is NULL. On exit, pcbData points to one of these values. /// /// /// /// pvData /// Return Value /// pcbData /// /// /// NULL /// ERROR_SUCCESS /// /// Size in bytes sufficient to hold the registry data. Note that this is not guaranteed to be the precise size, but only a /// sufficient size. /// /// /// /// Non-NULL /// ERROR_SUCCESS /// Exact number of bytes written to pvData. /// /// /// Non-NULL /// ERROR_MORE_DATA /// /// Size in bytes needed to hold the entire data. Note that this is not guaranteed to be the precise size, but only a sufficient size. /// /// /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the /// FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// SHRegGetValue provides data type checking, boot mode checking, auto-expansion of REG_EXPAND_SZ data, and guaranteed /// null-termination of REG_SZ, REG_EXPAND_SZ, and REG_MULTI_SZ data. /// /// /// The key identified by hkey must have been opened with KEY_QUERY_VALUE security access. If pszSubKey is not NULL or an /// empty string, that key also must be able to be opened with KEY_QUERY_VALUE security access in the current calling context. /// /// /// If the data's type is REG_SZ, REG_EXPAND_SZ or REG_MULTI_SZ, then any returned data includes or takes into account the string's /// null-termination. For example, if pvData is not NULL, the data returned in that buffer is null-terminated. /// If pcbData is not NULL, the buffer size that it points to includes the bytes required to hold the terminating null character. /// /// /// Unless the SRRF_NOEXPAND flag is set, string data of type REG_EXPAND_SZ is automatically expanded before being returned. The /// expanded string's type is reported in pdwType as REG_SZ, the pcbData parameter points to the number of bytes written for the /// expanded string, and the buffer pointed to by pvData holds the expanded version of the string. /// /// Performance Notes /// /// If pszSubKey is not NULL or an empty string, that key is opened and closed by this function each time it is accessed. If /// your application must retrieve a series of values from the same subkey, you will see better performance by opening the key using /// RegOpenKeyEx before calling SHRegGetValue. Use the key returned in the phkResult parameter of RegOpenKeyEx as the /// hkey parameter in this function, with pszSubKey set to NULL. /// /// /// The potential for an additional call to the registry to read or re-read the data exists when the data type is REG_EXPAND_SZ and /// the SRRF_NOEXPAND flag has not been set. The following conditions result in that additional call. /// /// /// /// /// pvData is NULL, pcbData is not NULL. Though the data is not retrieved, the registry must be read to get the string /// and that string expanded to determine the required size of the data buffer. /// /// /// /// /// pvData is not NULL, but is too small to hold the data. The data is re-read to get the full string, the string is expanded, /// and the total required size is determined. /// /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetvaluea LSTATUS SHRegGetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, SRRF srrfFlags, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "5650eb4c-40fd-47d7-af76-2688d62d9bca")] public static extern Win32Error SHRegGetValue(HKEY hkey, string pszSubKey, string pszValue, SRRF srrfFlags, ref REG_VALUE_TYPE pdwType, SafeAllocatedMemoryHandle pvData, ref uint pcbData); /// /// [This function is no longer supported.] /// /// Obtains specified information from the registry. This function will check HKEY_CURRENT_USER for the requested information in the /// specified subkey. If the information does not exist under the HKEY_CURRENT_USER subtree, the function checks the /// HKEY_LOCAL_MACHINE subtree for the same information. /// /// /// /// Type: PCWSTR /// A pointer to a null-terminated Unicode string that specifies the path to the registry key. /// /// /// Type: PCWSTR /// /// A pointer to a null-terminated Unicode string that specifies the key value. This value can be NULL, in which case /// data is retrieved from the Default value. /// /// /// /// Type: SRRF /// /// The SRRF flag constants. If more than one flag is used they can be combined using a bitwise OR. These flags are used to restrict /// the type of data returned. This value cannot be 0. /// /// /// /// Type: DWORD* /// /// When this function returns, contains a pointer to a DWORD which receives a code that indicates the type of data stored in /// the specified value. This can be set to NULL if no type information is wanted. If this value is not NULL, and the /// SRRF_NOEXPAND flag has not been set, data types of REG_EXPAND_SZ will be returned as REG_SZ since they are automatically expanded /// in this method. /// /// /// /// Type: LPCVOID /// /// A pointer to a buffer that contains the value's data. This parameter can be NULL if the data is not needed. This value /// must contain the size of the pvData buffer on entry. If pvData is NULL (or if pvData is not NULL, but too small of /// a buffer to hold the registry data), then on exit it will contain the size required to hold the registry data. /// /// /// /// Type: DWORD* /// When this function returns, contains a pointer to the size of the data, in bytes. /// /// /// Type: LONG /// /// If successful, this function returns ERROR_SUCCESS and all out parameters requested. Returns ERROR_MORE_DATA if the function /// fails due to insufficient space in a provided non- NULL pvData. In this case only pdwType and pcbData may contain valid /// data, pvData will be undefined. Otherwise, returns a nonzero error code defined in Winerror.h . You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetvaluefromhkcuhklm LSTATUS // SHRegGetValueFromHKCUHKLM( PCWSTR pwszKey, PCWSTR pwszValue, SRRF srrfFlags, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("shlwapi.h", MSDNShortId = "5c4b13f4-0dd8-476e-9e89-ace23d541389")] public static extern Win32Error SHRegGetValueFromHKCUHKLM(string pwszKey, string pwszValue, SRRF srrfFlags, ref REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData); /// /// [This function is no longer supported.] /// /// Obtains specified information from the registry. This function will check HKEY_CURRENT_USER for the requested information in the /// specified subkey. If the information does not exist under the HKEY_CURRENT_USER subtree, the function checks the /// HKEY_LOCAL_MACHINE subtree for the same information. /// /// /// /// Type: PCWSTR /// A pointer to a null-terminated Unicode string that specifies the path to the registry key. /// /// /// Type: PCWSTR /// /// A pointer to a null-terminated Unicode string that specifies the key value. This value can be NULL, in which case /// data is retrieved from the Default value. /// /// /// /// Type: SRRF /// /// The SRRF flag constants. If more than one flag is used they can be combined using a bitwise OR. These flags are used to restrict /// the type of data returned. This value cannot be 0. /// /// /// /// Type: DWORD* /// /// When this function returns, contains a pointer to a DWORD which receives a code that indicates the type of data stored in /// the specified value. This can be set to NULL if no type information is wanted. If this value is not NULL, and the /// SRRF_NOEXPAND flag has not been set, data types of REG_EXPAND_SZ will be returned as REG_SZ since they are automatically expanded /// in this method. /// /// /// /// Type: LPCVOID /// /// A pointer to a buffer that contains the value's data. This parameter can be NULL if the data is not needed. This value /// must contain the size of the pvData buffer on entry. If pvData is NULL (or if pvData is not NULL, but too small of /// a buffer to hold the registry data), then on exit it will contain the size required to hold the registry data. /// /// /// /// Type: DWORD* /// When this function returns, contains a pointer to the size of the data, in bytes. /// /// /// Type: LONG /// /// If successful, this function returns ERROR_SUCCESS and all out parameters requested. Returns ERROR_MORE_DATA if the function /// fails due to insufficient space in a provided non- NULL pvData. In this case only pdwType and pcbData may contain valid /// data, pvData will be undefined. Otherwise, returns a nonzero error code defined in Winerror.h . You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreggetvaluefromhkcuhklm LSTATUS // SHRegGetValueFromHKCUHKLM( PCWSTR pwszKey, PCWSTR pwszValue, SRRF srrfFlags, DWORD *pdwType, void *pvData, DWORD *pcbData ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("shlwapi.h", MSDNShortId = "5c4b13f4-0dd8-476e-9e89-ace23d541389")] public static extern Win32Error SHRegGetValueFromHKCUHKLM(string pwszKey, string pwszValue, SRRF srrfFlags, ref REG_VALUE_TYPE pdwType, SafeAllocatedMemoryHandle pvData, ref uint pcbData); /// /// Opens a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// TBD /// /// /// Type: REGSAM /// The desired security access. For more information on security access, see REGSAM. /// /// /// Type: HUSKEY /// /// The key to be used as a base for relative paths. If pszPath is a relative path, the key it specifies will be relative to /// hRelativeUSKey. If pszPath is an absolute path, set hRelativeUSKey to NULL. /// /// /// /// Type: PHUSKEY /// A pointer to the handle of the opened key. /// /// /// Type: BOOL /// /// The variable that specifies which key to look under. When set to TRUE, SHRegOpenUSKey ignores /// HKEY_CURRENT_USER and returns a value from HKEY_LOCAL_MACHINE. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregopenuskeya LSTATUS SHRegOpenUSKeyA( LPCSTR pszPath, // REGSAM samDesired, HUSKEY hRelativeUSKey, PHUSKEY phNewUSKey, BOOL fIgnoreHKCU ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "756430a9-a495-412e-95c3-a93222bc467a")] public static extern Win32Error SHRegOpenUSKey(string pszPath, uint samDesired, HUSKEY hRelativeUSKey, out SafeHUSKEY phNewUSKey, [MarshalAs(UnmanagedType.Bool)] bool fIgnoreHKCU); /// /// Retrieves information about a specified registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// Type: LPDWORD /// A pointer to a DWORD that receives the number of subkeys under the specified key. /// /// /// Type: LPDWORD /// A pointer to a DWORD that receives the number of characters in the largest subkey name. /// /// /// Type: LPDWORD /// A pointer to a DWORD that receives the number of values under the specified key. /// /// /// Type: LPDWORD /// A pointer to a DWORD that receives the number of characters in the largest value name. /// /// /// Type: SHREGENUM_FLAGS /// One of the SHREGENUM_FLAGS that specifies the base key in which the query should take place. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a textual description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregqueryinfouskeya LSTATUS SHRegQueryInfoUSKeyA( HUSKEY // hUSKey, LPDWORD pcSubKeys, LPDWORD pcchMaxSubKeyLen, LPDWORD pcValues, LPDWORD pcchMaxValueNameLen, SHREGENUM_FLAGS enumRegFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "e47b4fad-50c7-43d7-82f2-6a835ac543f0")] public static extern Win32Error SHRegQueryInfoUSKey(HUSKEY hUSKey, out uint pcSubKeys, out uint pcchMaxSubKeyLen, out uint pcValues, out uint pcchMaxValueNameLen, SHREGENUM_FLAGS enumRegFlags); /// /// /// Retrieves the type and data for a specified name associated with an open registry subkey in a user-specific subtree /// (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey, or one of the following predefined values. The subkey must have been opened with /// the KEY_SET_VALUE access right. For more information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// A pointer to the null-terminated string that contains the name of the value to be queried. /// /// /// Type: LPDWORD* /// /// A pointer to the variable that sets or receives the key's value type. For more information, see Registry Data Types. This /// parameter can be NULL. /// /// /// /// Type: LPVOID* /// A pointer to the buffer that receives the value's data. This parameter can be NULL if the data is not required. /// /// /// Type: LPDWORD* /// /// A pointer to the variable that specifies the size, in bytes, of the buffer pointed to by the pvData parameter. When the function /// returns, this variable contains the size of the data copied to pvData. /// /// /// /// Type: BOOL /// /// The variable that specifies which key to look under. When set to TRUE, SHRegQueryUSValue ignores /// HKEY_CURRENT_USER and returns the value from the key under HKEY_LOCAL_MACHINE. /// /// /// /// Type: LPVOID* /// A pointer to the default data. /// /// /// Type: DWORD /// The length, in bytes, of the default data. /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// When fIgnoreHKCU is set to TRUE, SHRegQueryUSValue returns the value from the key under HKEY_LOCAL_MACHINE. /// When set to FALSE, SHRegQueryUSValue first tries to return the value from the key under HKEY_CURRENT_USER. /// However, if the key is not found under HKEY_CURRENT_USER, the value returns from the key under HKEY_LOCAL_MACHINE. /// If neither key is present, or if an error occurs and dwDefaultDataSize is nonzero, then the default data is copied to pvData and /// ERROR_SUCCESS returns. ERROR_SUCCESS returns for both default and non-default data, and there is no way of distinguishing which /// value copies to pvData. To prevent the use of default data, set pvDefaultData to NULL and dwDefaultDataSize to zero. /// /// /// If you only need to read a single value, SHRegGetUSValue will both open the key and return the value. To use /// SHRegQueryUSValue, you must first open the key with SHRegOpenUSKey. However, once the key is opened, you can use /// SHRegQueryUSValue as many times as necessary. If you need to retrieve more than one value from the same key, using /// multiple calls to SHRegQueryUSValue is usually more efficient than SHRegGetUSValue, as the key is only opened once. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregqueryusvaluea LSTATUS SHRegQueryUSValueA( HUSKEY // hUSKey, LPCSTR pszValue, DWORD *pdwType, void *pvData, DWORD *pcbData, BOOL fIgnoreHKCU, void *pvDefaultData, DWORD // dwDefaultDataSize ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "302a51b5-9cf9-46e5-908c-df0d3c31c91c")] public static extern Win32Error SHRegQueryUSValue(HUSKEY hUSKey, string pszValue, ref REG_VALUE_TYPE pdwType, IntPtr pvData, ref uint pcbData, [MarshalAs(UnmanagedType.Bool)] bool fIgnoreHKCU, IntPtr pvDefaultData, uint dwDefaultDataSize); /// /// Takes a file path, replaces folder names with environment strings, and places the resulting string in the registry. /// /// /// Type: HKEY /// A handle to a key that is currently open, or a registry root key. /// /// /// Type: LPCTSTR /// /// A pointer to a null-terminated string containing the name of an existing subkey. If the subkey does not exist, /// SHRegSetPath will fail. /// /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string with the name of the value to hold the path string. /// /// /// Type: LPCTSTR /// A pointer to a null-terminated string with a fully qualified file path. /// /// /// Type: DWORD /// Reserved. /// /// /// Type: LSTATUS /// Returns ERROR_SUCCESS if successful, or a Windows error code otherwise. /// /// /// /// For Windows 2000, SHRegSetPath uses PathUnExpandEnvStrings to convert folder names to their corresponding environment /// string. If any environment variables were substituted, the registry value will be set with the REG_EXPAND_SZ data type. /// Otherwise, it will be set with the REG_SZ data type. /// /// The following folder paths will be replaced by their equivalent environment string. /// /// /// Folder /// Environment string /// /// /// The current user's profile folder /// %USERPROFILE% /// /// /// The All Users profile folder /// %ALLUSERSPROFILE% /// /// /// The Program Files folder /// %ProgramFiles% /// /// /// The system root folder /// %SystemRoot% /// /// /// The system drive letter /// %SystemDrive% /// /// /// /// Note %USERPROFILE% is relative to the user making the call. This function does not work if the user is being impersonated /// from a service. /// /// /// The environment variables listed in the above table might not all be set on any particular system. If an environment variable is /// not set, it will not be unexpanded. In particular, none of these variables are set for the default environment of Windows 95 or /// Windows 98. The %ProgramFiles% variable is new for Windows 2000, and will typically not be set on Microsoft Windows NT 4.0 systems. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregsetpatha LSTATUS SHRegSetPathA( HKEY hKey, LPCSTR // pcszSubKey, LPCSTR pcszValue, LPCSTR pcszPath, DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "3ee6ec69-5d16-4bdd-a591-651af05bf944")] public static extern Win32Error SHRegSetPath(HKEY hKey, string pcszSubKey, string pcszValue, string pcszPath, uint dwFlags = 0); /// /// Sets a registry subkey value in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// TBD /// /// /// TBD /// /// /// Type: DWORD /// Type of data to be stored. This parameter must be the REG_SZ type. For more information, see Registry Data Types. /// /// /// Type: LPVOID* /// Apointer to a null-terminated string that contains the value to be set for the specified key. /// /// /// Type: DWORD /// Length, in bytes, of the string pointed to by the pvData parameter, not including the terminating null character. /// /// /// Type: DWORD /// Flags indicating where the data should be written. /// SHREGSET_HKCU /// Write to HKEY_CURRENT_USER if empty. /// SHREGSET_FORCE_HKCU /// Write to HKEY_CURRENT_USER. /// SHREGSET_HKLM /// Write to HKEY_LOCAL_MACHINE if empty. /// SHREGSET_FORCE_HKLM /// Write to HKEY_LOCAL_MACHINE. /// SHREGSET_DEFAULT /// Equivalent to ( SHREGSET_FORCE_HKCU | SHREGSET_HKLM). /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful, or a nonzero error code defined in Winerror.h otherwise. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// This function opens the key each time it is used. If your code involves setting a series of values in the same key, it is more /// efficient to open the key once with SHRegOpenUSKey and then use SHRegWriteUSValue to write the data. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregsetusvaluea LSTATUS SHRegSetUSValueA( LPCSTR // pszSubKey, LPCSTR pszValue, DWORD dwType, const void *pvData, DWORD cbData, DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "96559f8c-8527-4924-928e-f27049069407")] public static extern Win32Error SHRegSetUSValue(string pszSubKey, string pszValue, REG_VALUE_TYPE dwType, IntPtr pvData, uint cbData, SHREGSET dwFlags); /// /// Writes a value to a registry subkey in a user-specific subtree (HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE). /// /// /// Type: HUSKEY /// /// A handle to a currently open registry subkey. The subkey must have been opened with the KEY_SET_VALUE access right. For more /// information, see Registry Key Security and Access Rights. /// /// This handle can be obtained through the SHRegOpenUSKey function. /// /// /// TBD /// /// /// Type: DWORD /// /// The type of the data to be stored in the value specified by pszValue. One of the following registry value types defined in /// Winnt.h and Wdm.h. /// /// REG_NONE (0x00000000) /// REG_SZ (0x00000001) /// REG_EXPAND_SZ (0x00000002) /// REG_BINARY (0x00000003) /// REG_DWORD (0x00000004) /// REG_DWORD_LITTLE_ENDIAN (0x00000004) /// REG_DWORD_BIG_ENDIAN (0x00000005) /// REG_LINK (0x00000006) /// REG_MULTI_SZ (0x00000007) /// REG_RESOURCE_LIST (0x00000008) /// REG_FULL_RESOURCE_DESCRIPTOR (0x00000009) /// REG_RESOURCE_REQUIREMENTS_LIST (0x0000000A) /// REG_QWORD (0x0000000B) /// REG_QWORD_LITTLE_ENDIAN (0x0000000B) /// /// /// Type: const void* /// /// A pointer to the data to be set for the value specified by pszValue. For string-based types, such as REG_SZ, the string must be /// null-terminated. With the REG_MULTI_SZ data type, the string must be terminated with two null characters. A backslash in a path /// must be preceded by another backslash as an escape character. For example, specify "C:\mydir\myfile" to store the string "C:\mydir\myfile". /// /// /// /// Type: DWORD /// /// The size, in bytes, of the data pointed to by the pvData parameter. If the data is of type REG_SZ, REG_EXPAND_SZ, or /// REG_MULTI_SZ, cbData must include the size of the terminating null character or characters. /// /// /// /// Type: DWORD /// Flags that indicate the subtree to which the data should be written. One or more of the following values: /// SHREGSET_HKCU (0x00000001) /// /// Write to HKEY_CURRENT_USER only if a value of the name specified in pszValue does not currently exist under the specified subkey. /// /// SHREGSET_FORCE_HKCU (0x00000002) /// Write to HKEY_CURRENT_USER. If a value of the name specified in pszValue already exists, it will be overwritten. /// SHREGSET_HKLM (0x00000004) /// /// Write to HKEY_LOCAL_MACHINE only if a value of the name specified in pszValue does not currently exist under the specified subkey.. /// /// SHREGSET_FORCE_HKLM (0x00000008) /// Write to HKEY_LOCAL_MACHINE. If a value of the name specified in pszValue already exists, it will be overwritten. /// SHREGSET_DEFAULT (0x00000006) /// Equivalent to ( SHREGSET_FORCE_HKCU | SHREGSET_HKLM). /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful; otherwise, a nonzero error code defined in Winerror.h. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// /// /// /// To use SHRegWriteUSValue, you must first open the key with SHRegOpenUSKey. Once the key is opened, you can use /// SHRegWriteUSValue as many times as necessary. /// /// If you only need to write a single value, you should use SHRegSetUSValue, which both opens the key and writes the value. /// /// If you need to write more than one value on the same key, multiple calls to SHRegWriteUSValue are usually more efficient /// than SHRegSetUSValue, because the key is only opened once. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shregwriteusvaluea LSTATUS SHRegWriteUSValueA( HUSKEY // hUSKey, LPCSTR pszValue, DWORD dwType, const void *pvData, DWORD cbData, DWORD dwFlags ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "f94569c6-415b-4263-bab4-8a5baca47901")] public static extern Win32Error SHRegWriteUSValue(HUSKEY hUSKey, string pszValue, REG_VALUE_TYPE dwType, IntPtr pvData, uint cbData, SHREGSET dwFlags); /// /// Releases a thread reference before the thread procedure returns. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shreleasethreadref LWSTDAPI SHReleaseThreadRef( ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "7f3fd09b-baad-4019-a060-c68727aee61f")] public static extern HRESULT SHReleaseThreadRef(); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Sends a message to all top-level windows in the system. /// /// /// Type: UINT /// The message to send. /// /// /// Type: WPARAM /// Additional message-specific information. /// /// /// Type: LPARAM /// Additional message-specific information. /// /// /// Type: LRESULT /// The return value is not meaningful. /// /// /// /// SHSendMessageBroadcast is equivalent to SendMessage with HWND_BROADCAST. To avoid causing the Shell to become /// unresponsive in the case where there could be a window in the system that is not responding to messages, use SHSendMessageBroadcast. /// /// /// SHSendMessageBroadcast is not exported by name. SHSendMessageBroadcastA is exported from Shlwapi.dll as ordinal /// 432. SHSendMessageBroadcastW is exported from Shlwapi.dll as ordinal 433. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shsendmessagebroadcasta LRESULT SHSendMessageBroadcastA( // UINT uMsg, WPARAM wParam, LPARAM lParam ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "98671f0f-2386-486f-ac96-14dd44c776c6")] public static extern IntPtr SHSendMessageBroadcast(uint uMsg, IntPtr wParam, IntPtr lParam); /// /// /// Stores a per-thread reference to a Component Object Model (COM) object. This allows the caller to control the thread's lifetime /// so that it can ensure that Windows won't shut down the thread before the caller is ready. /// /// /// /// Type: IUnknown* /// A pointer to the IUnknown of the object for which you want to store a reference. This value can be NULL. /// /// /// Type: HRESULT /// If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code. /// /// /// Use SHGetThreadRef to retrieve the IUnknown pointer. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shsetthreadref LWSTDAPI SHSetThreadRef( IUnknown *punk ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "1d0d70ca-a0e6-4620-9a01-8d4986990b9c")] public static extern HRESULT SHSetThreadRef([MarshalAs(UnmanagedType.IUnknown)] object punk); /// /// Sets the value of a registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// /// The address of a null-terminated string that specifies the name of the subkey with which a value is associated. This can be /// NULL or a pointer to an empty string. In this case, the value is added to the key identified by the hkey parameter. /// /// /// /// Type: LPCTSTR /// The address of a null-terminated string that specifies the value. This value can be NULL. /// /// /// Type: DWORD /// Type of data to be stored. This parameter must be the REG_SZ type. For more information, see Registry Data Types. /// /// /// Type: LPCVOID /// Pointer to a buffer that contains the data to set for the specified value. This value can be NULL. /// /// /// Type: DWORD /// /// Length, in bytes, of the buffer pointed to by the pvData parameter. If the data is a null-terminated string, this length includes /// the terminating null character. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful; otherwise, a nonzero error code defined in Winerror.h. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shsetvaluea LSTATUS SHSetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, DWORD dwType, LPCVOID pvData, DWORD cbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "6cd5b7fd-8fb9-4c24-9670-20c23ca709bf")] public static extern Win32Error SHSetValue(HKEY hkey, string pszSubKey, string pszValue, REG_VALUE_TYPE dwType, IntPtr pvData, uint cbData); /// /// Sets the value of a registry key. /// /// /// Type: HKEY /// A handle to the currently open key, or any of the following predefined values. /// HKEY_CLASSES_ROOT /// HKEY_CURRENT_CONFIG /// HKEY_CURRENT_USER /// HKEY_LOCAL_MACHINE /// HKEY_PERFORMANCE_DATA /// HKEY_USERS /// /// /// Type: LPCTSTR /// /// The address of a null-terminated string that specifies the name of the subkey with which a value is associated. This can be /// NULL or a pointer to an empty string. In this case, the value is added to the key identified by the hkey parameter. /// /// /// /// Type: LPCTSTR /// The address of a null-terminated string that specifies the value. This value can be NULL. /// /// /// Type: DWORD /// Type of data to be stored. This parameter must be the REG_SZ type. For more information, see Registry Data Types. /// /// /// Type: LPCVOID /// Pointer to a buffer that contains the data to set for the specified value. This value can be NULL. /// /// /// Type: DWORD /// /// Length, in bytes, of the buffer pointed to by the pvData parameter. If the data is a null-terminated string, this length includes /// the terminating null character. /// /// /// /// Type: LSTATUS /// /// Returns ERROR_SUCCESS if successful; otherwise, a nonzero error code defined in Winerror.h. You can use the FormatMessage /// function with the FORMAT_MESSAGE_FROM_SYSTEM flag to retrieve a generic description of the error. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shsetvaluea LSTATUS SHSetValueA( HKEY hkey, LPCSTR // pszSubKey, LPCSTR pszValue, DWORD dwType, LPCVOID pvData, DWORD cbData ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "6cd5b7fd-8fb9-4c24-9670-20c23ca709bf")] public static extern Win32Error SHSetValue(HKEY hkey, string pszSubKey, string pszValue, REG_VALUE_TYPE dwType, SafeAllocatedMemoryHandle pvData, uint cbData); /// /// Checks a bind context to see if it is safe to bind to a particular component object. /// /// /// Type: IBindCtx* /// A pointer to an IBindCtx interface that specifies the bind context you want to check. This value can be NULL. /// /// /// Type: const CLSID* /// /// A pointer to a variable that specifies the CLSID of the object being tested to see if it must be skipped. Typically, this /// is the CLSID of the object that IShellFolder::BindToObject is about to create. /// /// /// /// Type: BOOL /// Returns TRUE if the object specified by pclsid must be skipped, or FALSE otherwise. /// /// /// /// This function can be used to avoid infinite cycles in namespace binding. For example, a folder shortcut that refers to a folder /// above it in the namespace tree can produce an infinitely recursive loop. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shskipjunction BOOL SHSkipJunction( IBindCtx *pbc, const // CLSID *pclsid ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "73af64a4-57eb-43db-91bb-75fe7134ad28")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHSkipJunction(IBindCtx pbc, in Guid pclsid); /// /// Makes a copy of a string in newly allocated memory. /// /// /// Type: LPCTSTR /// A pointer to the null-terminated string to be copied. /// /// /// Type: LPTSTR* /// /// A pointer to an allocated Unicode string that contains the result. SHStrDup allocates memory for this string with /// CoTaskMemAlloc. You should free the string with CoTaskMemFree when it is no longer needed. /// /// In the case of failure, this value is NULL. /// /// /// Type: HRESULT /// Returns S_OK if successful, or a COM error value otherwise. /// /// /// This function will take either Unicode or ANSI strings as input, but the copied string is always Unicode. /// /// This function uses CoTaskMemAlloc to allocate memory for the copied string. You must free this memory with CoTaskMemFree when it /// is no longer needed. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shstrdupa LWSTDAPI SHStrDupA( LPCSTR psz, LPWSTR *ppwsz ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "6f014fb4-7637-48a8-9bec-d3278c46a6d8")] public static extern HRESULT SHStrDup(string psz, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoTaskMemStringMarshaler), MarshalCookie = "Auto")] out string ppwsz); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Removes the mnemonic marker from a string. /// /// /// Type: LPTSTR* /// A pointer to the null-terminated string that contains the mnemonic marker. /// /// /// Type: TCHAR /// Returns the mnemonic character, if one was found. Otherwise, returns 0. /// /// /// The term "mnemonic" is misspelled in the function name. /// The function supports the following mnemonic formats. /// /// /// Input String /// Output String /// Mnemonic Character /// Remarks /// /// /// "Str&ing" /// "String" /// 'i' /// None. /// /// /// "String (&S)" /// "String" /// 'S' /// Supported only by the Unicode version of this function. Requires Windows XP or later. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shstripmneumonica CHAR SHStripMneumonicA( LPSTR pszMenu ); [DllImport(Lib.Shlwapi, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("shlwapi.h", MSDNShortId = "25479814-825a-4af2-8751-b35cf39bbb80")] public static extern char SHStripMneumonic(StringBuilder pszMenu); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Converts a string from the Unicode code page to the ANSI code page. /// /// /// Type: PCWSTR /// A pointer to the null-terminated Unicode string to be converted to ANSI. /// /// /// Type: PSTR /// /// A pointer to a buffer that, when this function returns successfully, receives the converted characters. The buffer must be large /// enough to contain the number of CHAR characters specified by the cchBuf parameter, including room for a terminating null character. /// /// /// /// Type: int /// /// The number of CHAR values that can be contained by the buffer pointed to by pszDst. The value assigned to parameter must /// be greater than zero. /// /// /// /// Type: int /// /// Returns the number of CHAR values written to the output buffer, including the terminating null character. Returns 0 if unsuccessful. /// /// /// /// /// Security Warning: Using this function incorrectly can compromise the security of your application. For example, if pszDst /// buffer is not large enough to contain the number of characters specified by cchBuf, a buffer overrun can occur. Buffer overruns /// can cause a denial of service attack against an application if an access violation occurs. In the worst case, a buffer overrun /// might allow an attacker to inject executable code into your process, especially if pszDst is a stack-based buffer. In addition, /// the output string is silently truncated if it is too large for the buffer. This can cause canonicalization or other security vulnerabilities. /// /// /// If the pszDst buffer is not large enough to contain the entire converted output string, the string is truncated to fit the /// buffer. There is no way to detect that the return string has been truncated. The string will always be null-terminated, even if /// it has been truncated. This function takes care to not truncate between the lead and trail bytes of a DBCS character pair. In /// that case, only cchBuf-1 characters are returned. /// /// If the pwszSrc and pszDst buffers overlap, the function's behavior is undefined. /// /// Note Do not assume that the function has not changed any of the characters in the output buffer that follow the string's /// terminating null character. The contents of the output buffer following the string's terminating null character are undefined, up /// to and including the last character in the buffer. /// /// SHTCharToAnsi is defined to be the same as SHUnicodeToAnsi. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shunicodetoansi int SHUnicodeToAnsi( PCWSTR pwszSrc, PSTR // pszDst, int cchBuf ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "f0db3976-9956-418f-8432-7755b140050f")] public static extern int SHUnicodeToAnsi([MarshalAs(UnmanagedType.LPWStr)] string pwszSrc, [MarshalAs(UnmanagedType.LPStr)] StringBuilder pszDst, int cchBuf); /// /// /// [This function is available through Windows XP and Windows Server 2003. It might be altered or unavailable in subsequent versions /// of Windows.] /// /// Copies a Unicode string. /// /// /// Type: PCWSTR /// A pointer to a null-terminated Unicode string to be copied to the output buffer. /// /// /// Type: PWSTR /// /// A pointer to an output buffer to receive the copied characters. The buffer must be large enough to contain the number of /// WCHAR characters specified by cwchBuf, including room for a terminating null character. /// /// /// /// Type: int /// /// The number of WCHAR characters that can be contained by the buffer pointed to by pwzDst parameter. This parameter must be /// greater than zero. /// /// /// /// Type: int /// /// Returns the number of WCHAR characters written to the output buffer, including the terminating null character. Returns 0 /// if unsuccessful. /// /// /// /// /// Security Warning: Using this function incorrectly can compromise the security of your application. For example, if pwzDst /// buffer is not large enough to contain the number of characters specified by cwchBuf, a buffer overrun can occur. Buffer overruns /// can cause a denial of service attack against an application if an access violation occurs. In the worst case, a buffer overrun /// might allow an attacker to inject executable code into your process, especially if pwzDst is a stack-based buffer. When copying /// an entire string, note that sizeof returns the number of bytes, which is not the correct value to use for the cwchBuf parameter. /// Instead, use sizeof(pwzDst)/sizeof(WCHAR). Note that this technique assumes that pwzDst is an array, not a pointer. Note also /// that the function silently truncates the output string if the buffer is not large enough. This can result in canonicalization or /// other security vulnerabilities. /// /// /// If the pwzDst buffer is not large enough to contain the entire converted output string, the string is truncated to fit the /// buffer. There is no way to detect that the return string has been truncated. The string will always be null-terminated, even if /// it has been truncated. This ensures that no more than cwchBuf characters are copied to pwzDst. No attempt is made to avoid /// truncating the string in the middle of a Unicode surrogate pair. /// /// If the pwzSrc and pwzDst buffers overlap, the function's behavior is undefined. /// /// Note Do not assume that the function has not changed any of the characters in the output buffer that follow the string's /// terminating null character. The contents of the output buffer following the string's terminating null character are undefined, up /// to and including the last character in the buffer. /// /// SHTCharToUnicode is defined to be the same as SHUnicodeToUnicode. /// SHUnicodeToTChar is defined to be the same as SHUnicodeToUnicode. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shunicodetounicode int SHUnicodeToUnicode( PCWSTR pwzSrc, // PWSTR pwzDst, int cwchBuf ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("shlwapi.h", MSDNShortId = "1a208c2d-e627-4aac-9a28-b579c734a2a8")] public static extern int SHUnicodeToUnicode(string pwzSrc, StringBuilder pwzDst, int cwchBuf); /// /// /// [ SHUnlockShared is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions.] /// /// Unlocks memory locked by SHLockShared. /// /// /// Type: void* /// A pointer to the shared memory block returned by SHLockShared. /// /// /// Type: BOOL /// /// If the function succeeds, the return value is TRUE and all modified pages within the specified range are written to the /// disk with low priority. If the function fails, the return value is FALSE. To get extended error information, call GetLastError. /// /// /// /// Call SHFreeShared to free the memory block. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-shunlockshared BOOL SHUnlockShared( void *pvData ); [DllImport(Lib.Shlwapi, SetLastError = true, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "8ecbf62b-fd0d-4a8d-bd55-42c0c3f64390")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SHUnlockShared(IntPtr pvData); /// /// /// [ WhichPlatform is available for use in the operating systems specified in the Requirements section. It may be altered or /// unavailable in subsequent versions.] /// /// Retrieves a value that indicates the type of Shell32.dll that the platform contains. /// /// /// Type: UINT /// /// /// Return code /// Description /// /// /// PLATFORM_UNKNOWN /// The function was unable to determine the Shell32.dll version. /// /// /// PLATFORM_IE3 /// Obsolete: Use PLATFORM_BROWSERONLY. /// /// /// PLATFORM_BROWSERONLY /// The Shell32.dll version is browser-only, with no new shell. /// /// /// PLATFORM_INTEGRATED /// The platform contains an integrated shell. /// /// /// /// /// This function always returns PLATFORM_INTEGRATED because Windows XP comes with an integrated shell. /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-whichplatform UINT WhichPlatform( ); [DllImport(Lib.Shlwapi, SetLastError = false, ExactSpelling = true)] [PInvokeData("shlwapi.h", MSDNShortId = "14af733b-81b4-40a2-b93b-6f387b181f12")] public static extern SHELLPLATFORM WhichPlatform(); /// Provides a handle to a user specific registry key. [StructLayout(LayoutKind.Sequential)] public struct HUSKEY : IHandle { private IntPtr handle; /// Initializes a new instance of the struct. /// An object that represents the pre-existing handle to use. public HUSKEY(IntPtr preexistingHandle) => handle = preexistingHandle; /// Returns an invalid handle by instantiating a object with . public static HUSKEY NULL => new HUSKEY(IntPtr.Zero); /// Gets a value indicating whether this instance is a null handle. public bool IsNull => handle == IntPtr.Zero; /// Performs an explicit conversion from to . /// The handle. /// The result of the conversion. public static explicit operator IntPtr(HUSKEY h) => h.handle; /// Performs an implicit conversion from to . /// The pointer to a handle. /// The result of the conversion. public static implicit operator HUSKEY(IntPtr h) => new HUSKEY(h); /// Implements the operator !=. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator !=(HUSKEY h1, HUSKEY h2) => !(h1 == h2); /// Implements the operator ==. /// The first handle. /// The second handle. /// The result of the operator. public static bool operator ==(HUSKEY h1, HUSKEY h2) => h1.Equals(h2); /// public override bool Equals(object obj) => obj is HUSKEY h ? handle == h.handle : false; /// public override int GetHashCode() => handle.GetHashCode(); /// public IntPtr DangerousGetHandle() => handle; } /// /// Used by the QISearch function to describe a single interface. /// /// /// /// Note Prior to Windows Vista, QITAB was not declared in a public header file. To use it in those cases, you must use /// define it yourself as it is given here. Under Windows Vista, QITAB is included in Shlwapi.h and this is not necessary. /// /// /// To mark the end of a QITAB table, set the piid member to NULL and the dwOffset member to 0. See the /// QISearch function for an example of how to use this structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/ns-shlwapi-qitab typedef struct QITAB { const IID *piid; DWORD // dwOffset; } *LPQITAB; [PInvokeData("shlwapi.h", MSDNShortId = "3a055773-6e53-45e1-8936-011a8b2b8b16")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct QITAB { /// /// Type: const IID* /// A pointer to the IID of the interface represented by this structure. /// public IntPtr piid; /// /// Type: int /// The offset, in bytes, from the base of the object to the start of the interface. /// public uint dwOffset; } /// Provides a for that is disposed using . public class SafeHUSKEY : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeHUSKEY(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeHUSKEY() : base() { } /// Performs an implicit conversion from to . /// The safe handle instance. /// The result of the conversion. public static implicit operator HUSKEY(SafeHUSKEY h) => h.handle; /// protected override bool InternalReleaseHandle() => SHRegCloseUSKey(this).Succeeded; } } }