namespace Vanara.PInvoke;
/// Interfaces and methods from Url.dll.
public static partial class Url
{
/// Flags used by IUniformResourceLocator::InvokeCommand.
[PInvokeData("Intshcut.h")]
[Flags]
public enum IURL_INVOKECOMMAND_FLAGS
{
///
/// Interaction with the user is allowed and the hwndParent member of this structure is valid. If this is not set, interaction
/// with the user is not allowed and the hwndParent member is ignored.
///
IURL_INVOKECOMMAND_FL_ALLOW_UI = 0x0001,
///
/// Default verb for the Internet Shortcut's protocol should be used and the pcszVerb member is ignored. If this bit is not set,
/// the verb is specified by pcszVerb.
///
IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB = 0x0002,
/// Wait for the DDE conversation to terminate before returning.
IURL_INVOKECOMMAND_FL_DDEWAIT = 0x0004,
/// pass SEE_MASK_ASYNCOK to ShellExec
IURL_INVOKECOMMAND_FL_ASYNCOK = 0x0008,
/// Record launch with UA system
IURL_INVOKECOMMAND_FL_LOG_USAGE = 0x0010,
}
/// Flags used by IUniformResourceLocator::SetUrl.
[PInvokeData("Intshcut.h")]
[Flags]
public enum IURL_SETURL_FLAGS
{
///
/// If the protocol scheme is not specified in pcszURL, the system automatically chooses a scheme and adds it to the URL.
///
IURL_SETURL_FL_GUESS_PROTOCOL = 0x0001, // Guess protocol if missing
/// If the protocol scheme is not specified in pcszURL, the system adds the default protocol scheme to the URL.
IURL_SETURL_FL_USE_DEFAULT_PROTOCOL = 0x0002, // Use default protocol if missing
}
/// Bit flags that specify how the URL string is to be translated.
[PInvokeData("intshcut.h", MSDNShortId = "2f089f5a-4d7c-4bb7-961c-5c6e3e73c7b7")]
[Flags]
public enum TRANSLATEURL_IN_FLAGS
{
///
/// If the protocol scheme is not specified in the pcszURL parameter of TranslateURL, the system automatically chooses a scheme
/// and adds it to the URL.
///
TRANSLATEURL_FL_GUESS_PROTOCOL = 0x0001,
///
/// If the protocol scheme is not specified in the pcszURL parameter of TranslateURL, the system adds the default protocol to
/// the URL.
///
TRANSLATEURL_FL_USE_DEFAULT_PROTOCOL = 0x0002,
}
/// The bit flags that specify the behavior of .
[PInvokeData("intshcut.h", MSDNShortId = "3158e819-f131-4f57-8516-998955100377")]
[Flags]
public enum URLASSOCIATIONDIALOG_IN_FLAGS
{
/// Use the default file name (that is, "Internet Shortcut").
URLASSOCDLG_FL_USE_DEFAULT_NAME = 0x0001,
///
/// Register the selected application as the handler for the protocol specified in pcszURL. The application is registered only
/// if this flag is set and the user indicates that a persistent association is desired.
///
URLASSOCDLG_FL_REGISTER_ASSOC = 0x0002
}
/// This interface provides methods that retrieve, set, and run commands on an object's URL.
[PInvokeData("Intshcut.h")]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("CABB0DA0-DA57-11CF-9974-0020AFD79762"), CoClass(typeof(InternetShortcut))]
public interface IUniformResourceLocator
{
/// Sets an object's URL.
///
/// Address of a zero-terminated string that contains the URL to set. The protocol scheme may be included as part of the URL.
///
/// The dw in flags.
void SetUrl([MarshalAs(UnmanagedType.LPWStr)] string pcszUrl, IURL_SETURL_FLAGS dwInFlags = 0);
/// Retrieves an object's URL.
///
/// Address of an LPSTR that will be filled with a pointer to the object's URL. Because this method allocates memory for the
/// string, you must create and instance of an IMalloc interface and free the memory using IMalloc::Free when it is no longer needed.
///
void GetUrl([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoTaskMemStringMarshaler))] out string ppszUrl);
/// Runs a command on an object's URL.
/// Address of a URLINVOKECOMMANDINFO structure that contains command information for the function.
void InvokeCommand(in URLINVOKECOMMANDINFO purlici);
}
/// Determines whether the system is connected to the Internet.
///
/// Type: DWORD
/// The input flags for the function. This must be set to zero.
///
///
/// Type: BOOL
///
/// Returns TRUE if the local system is not currently connected to the Internet. Returns FALSE if the local system is
/// connected to the Internet or if no attempt has yet been made to connect to the Internet.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/intshcut/nf-intshcut-inetisoffline INTSHCUTAPI BOOL InetIsOffline( DWORD
// dwFlags );
[DllImport(Lib.Url, SetLastError = false, ExactSpelling = true)]
[PInvokeData("intshcut.h", MSDNShortId = "e0afac1c-c083-4b60-a30f-5dfc1a4b8fd3")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InetIsOffline(uint dwFlags = 0);
///
/// Runs the unregistered MIME content type dialog box.
/// Note Windows XP Service Pack 2 (SP2) or later: This function is no longer supported.
///
///
/// Type: HWND
/// A handle to the parent window of any posted child windows.
///
///
/// Type: DWORD
///
/// A bit flag value that specifies if an association is to be registered. The bit flag is the value MIMEASSOCDLG_FL_REGISTER_ASSOC
/// (0x0001). If this bit is set, the selected application is registered as the handler for the given MIME type. If this bit is
/// clear, no association is registered.
///
/// An application is registered only if this flag is set and the user indicates that a persistent association is to be made.
/// Registration is impossible if the string at pcszFile does not contain an extension.
///
///
/// Type: PCTSTR
///
/// The address of a null-terminated string that contains the name of the target file. This file must conform to the content type
/// described by the pcszMIMEContentType parameter.
///
///
///
/// Type: PCTSTR
/// The address of a null-terminated string that contains the unregistered content type.
///
///
/// Type: PTSTR
///
/// A pointer to a buffer that, when this function returns successfully, receives the path of the application specified by the user.
///
///
///
/// Type: UINT
/// Size of pszAppBuf, in characters.
///
///
/// Type: HRESULT
/// Note As of Windows XP SP2, this function is not supported and returns E_NOTIMPL in all situations.
///
/// In supported systems, returns S_OK if the content type was successfully associated with the extension. In this case, the
/// extension is associated as the default for the content type, and pszAppBuf points to the string that contains the path of the
/// specified application. The function returns S_FALSE if nothing was registered. Otherwise, the return value will be one of the following:
///
///
///
/// Return code
/// Description
///
/// -
/// E_ABORT
/// The user canceled the operation.
///
/// -
/// E_FLAGS
/// The flag combination passed in dwInFlags is invalid.
///
/// -
/// E_OUTOFMEMORY
/// There was insufficient memory available to complete the operation.
///
/// -
/// E_POINTER
/// One of the input pointers is invalid.
///
///
///
///
/// This function does not validate the syntax of the input content type string at pcszMIMEContentType. A successful return value
/// does not indicate that the specified MIME content type is valid.
///
// https://docs.microsoft.com/en-us/windows/win32/api/intshcut/nf-intshcut-mimeassociationdialoga INTSHCUTAPI HRESULT
// MIMEAssociationDialogA( HWND hwndParent, DWORD dwInFlags, PCSTR pcszFile, PCSTR pcszMIMEContentType, PSTR pszAppBuf, UINT
// ucAppBufLen );
[DllImport(Lib.Url, SetLastError = false, CharSet = CharSet.Auto)]
[PInvokeData("intshcut.h", MSDNShortId = "0f8ee95a-3f95-47ee-822b-740ba134cd3c")]
[Obsolete]
public static extern HRESULT MIMEAssociationDialog(HWND hwndParent, uint dwInFlags, string pcszFile, string pcszMIMEContentType, StringBuilder pszAppBuf, uint ucAppBufLen);
/// Applies common translations to a given URL string, creating a new URL string.
///
/// Type: PCTSTR
/// The address of the URL string to be translated.
///
///
/// Type: DWORD
/// The bit flags that specify how the URL string is to be translated. This value can be a combination of the following:
/// TRANSLATEURL_FL_GUESS_PROTOCOL
///
/// If the protocol scheme is not specified in the pcszURL parameter to TranslateURL, the system automatically chooses a
/// scheme and adds it to the URL.
///
/// TRANSLATEURL_FL_USE_DEFAULT_PROTOCOL
///
/// If the protocol scheme is not specified in the pcszURL parameter to TranslateURL, the system adds the default protocol to
/// the URL.
///
///
///
/// Type: PTSTR*
///
/// A pointer variable that receives the pointer to the newly created, translated URL string, if any. The ppszTranslatedURL
/// parameter is valid only if the function returns S_OK.
///
///
///
/// Type: HRESULT
///
/// Returns S_OK upon success, or S_FALSE if the URL did not require translation. If an error occurs, the function returns one of
/// the following values.
///
///
///
/// Return code
/// Description
///
/// -
/// E_FLAGS
/// The flag combination passed in dwInFlags is invalid.
///
/// -
/// E_OUTOFMEMORY
/// There was insufficient memory to complete the operation.
///
/// -
/// E_POINTER
/// One of the input pointers is invalid.
///
///
///
///
/// This function does not validate the input URL string. A successful return value does not indicate that the URL strings are valid URLs.
///
// https://docs.microsoft.com/en-us/windows/win32/api/intshcut/nf-intshcut-translateurla INTSHCUTAPI HRESULT TranslateURLA( PCSTR
// pcszURL, DWORD dwInFlags, PSTR *ppszTranslatedURL );
[DllImport(Lib.Url, SetLastError = false, EntryPoint = "TranslateURLW")]
[PInvokeData("intshcut.h", MSDNShortId = "2f089f5a-4d7c-4bb7-961c-5c6e3e73c7b7")]
public static extern HRESULT TranslateURL([MarshalAs(UnmanagedType.LPWStr)] string pcszURL, TRANSLATEURL_IN_FLAGS dwInFlags, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(CoTaskMemStringMarshaler))] out string ppszTranslatedURL);
///
///
/// Invokes the unregistered URL protocol dialog box. This dialog box allows the user to select an application to associate with a
/// previously unknown protocol.
///
/// Note Windows XP Service Pack 2 (SP2) or later: This function is no longer supported.
///
///
/// Type: HWND
/// A handle to the parent window.
///
///
/// Type: DWORD
/// The bit flags that specify the behavior of the function. This value can be a combination of the following:
/// URLASSOCDLG_FL_USE_DEFAULT_NAME
/// Use the default file name (that is, "Internet Shortcut").
/// URLASSOCDLG_FL_REGISTER_ASSOC
///
/// Register the selected application as the handler for the protocol specified in pcszURL. The application is registered only if
/// this flag is set and the user indicates that a persistent association is desired.
///
///
///
/// Type: PTCSTR
/// The address of a constant zero-terminated string that contains the file name to associate with the URLs protocol.
///
///
/// Type: PTCSTR
/// The address of a constant zero-terminated string that contains the URL with an unknown protocol.
///
///
/// Type: PTSTR
/// The address of a buffer that receives the path of the application specified by the user.
///
///
/// Type: UINT
/// The size of pszAppBuf, in characters.
///
///
/// Type: HRESULT
/// Note As of Windows XP SP2, this function not supported and returns E_NOTIMPL in all situations.
///
/// In supported systems, returns S_OK if the application is registered with the URL protocol, or S_FALSE if nothing is registered.
/// For example, the function returns S_FALSE when the user elects to perform a one-time execution via the selected application.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/intshcut/nf-intshcut-urlassociationdialoga INTSHCUTAPI HRESULT
// URLAssociationDialogA( HWND hwndParent, DWORD dwInFlags, PCSTR pcszFile, PCSTR pcszURL, PSTR pszAppBuf, UINT ucAppBufLen );
[DllImport(Lib.Url, SetLastError = false, EntryPoint = "URLAssociationDialogW")]
[PInvokeData("intshcut.h", MSDNShortId = "3158e819-f131-4f57-8516-998955100377")]
[Obsolete]
public static extern HRESULT URLAssociationDialog(HWND hwndParent, URLASSOCIATIONDIALOG_IN_FLAGS dwInFlags, [MarshalAs(UnmanagedType.LPWStr)] string pcszFile, [MarshalAs(UnmanagedType.LPWStr)] string pcszURL, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszAppBuf, uint ucAppBufLen);
/// Contains information for use with the IUniformResourceLocator::InvokeCommand method.
[PInvokeData("Intshcut.h")]
[StructLayout(LayoutKind.Sequential)]
public struct URLINVOKECOMMANDINFO
{
private static readonly uint size = (uint)Marshal.SizeOf(typeof(URLINVOKECOMMANDINFO));
/// Size of this structure, in bytes.
public uint dwcbSize;
/// Flag value that specifies how the IUniformResourceLocator::InvokeCommand method will execute.
public IURL_INVOKECOMMAND_FLAGS dwFlags;
/// Handle to the parent window. If dwFlags is set to IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB, this member is ignored.
public HWND hwndParent;
///
/// Address of a zero-terminated string that contains the verb to be invoked by IUniformResourceLocator::InvokeCommand. If
/// dwFlags is set to IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB, this member is ignored.
///
[MarshalAs(UnmanagedType.LPWStr)]
public string? pcszVerb;
/// Initializes a new instance of the struct.
/// The verb to be invoked by IUniformResourceLocator::InvokeCommand.
/// Handle to the parent window.
public URLINVOKECOMMANDINFO(string? verb = null, HWND? parentHwnd = null)
{
dwcbSize = size;
dwFlags = (verb is null ? 0 : IURL_INVOKECOMMAND_FLAGS.IURL_INVOKECOMMAND_FL_USE_DEFAULT_VERB) | (parentHwnd is null ? 0 : IURL_INVOKECOMMAND_FLAGS.IURL_INVOKECOMMAND_FL_ALLOW_UI);
hwndParent = parentHwnd.GetValueOrDefault();
pcszVerb = verb;
}
/// Gets a default instance of this structure with the size field set appropriately.
public static readonly URLINVOKECOMMANDINFO Default = new() { dwcbSize = size };
}
/// CoClass for IUniformResourceLocator.
[PInvokeData("Intshcut.h")]
[ComImport, Guid("FBF23B40-E3F0-101B-8488-00AA003E56F8"), ClassInterface(ClassInterfaceType.None)]
public class InternetShortcut { }
}