mirror of https://github.com/dahall/Vanara.git
Completed testing and fixes for url.dll in Vanara.PInvoke.Shell32.
parent
73bebac442
commit
92227c8afd
|
@ -6,7 +6,7 @@ using Vanara.InteropServices;
|
|||
namespace Vanara.PInvoke
|
||||
{
|
||||
/// <summary>Interfaces and methods from Url.dll.</summary>
|
||||
public static partial class IntShcut
|
||||
public static partial class Url
|
||||
{
|
||||
/// <summary>Flags used by IUniformResourceLocator::InvokeCommand.</summary>
|
||||
[PInvokeData("Intshcut.h")]
|
||||
|
@ -92,7 +92,7 @@ namespace Vanara.PInvoke
|
|||
/// Address of a zero-terminated string that contains the URL to set. The protocol scheme may be included as part of the URL.
|
||||
/// </param>
|
||||
/// <param name="dwInFlags">The dw in flags.</param>
|
||||
void SetUrl([MarshalAs(UnmanagedType.LPWStr)] string pcszUrl, IURL_SETURL_FLAGS dwInFlags);
|
||||
void SetUrl([MarshalAs(UnmanagedType.LPWStr)] string pcszUrl, IURL_SETURL_FLAGS dwInFlags = 0);
|
||||
|
||||
/// <summary>Retrieves an object's URL.</summary>
|
||||
/// <param name="ppszUrl">
|
||||
|
@ -325,6 +325,8 @@ namespace Vanara.PInvoke
|
|||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct URLINVOKECOMMANDINFO
|
||||
{
|
||||
private static readonly uint size = (uint)Marshal.SizeOf(typeof(URLINVOKECOMMANDINFO));
|
||||
|
||||
/// <summary>Size of this structure, in bytes.</summary>
|
||||
public uint dwcbSize;
|
||||
|
||||
|
@ -341,8 +343,19 @@ namespace Vanara.PInvoke
|
|||
[MarshalAs(UnmanagedType.LPWStr)]
|
||||
public string pcszVerb;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="URLINVOKECOMMANDINFO"/> struct.</summary>
|
||||
/// <param name="verb">The verb to be invoked by IUniformResourceLocator::InvokeCommand.</param>
|
||||
/// <param name="parentHwnd">Handle to the parent window.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>Gets a default instance of this structure with the size field set appropriately.</summary>
|
||||
public static readonly URLINVOKECOMMANDINFO Default = new URLINVOKECOMMANDINFO { dwcbSize = (uint)Marshal.SizeOf(typeof(URLINVOKECOMMANDINFO)) };
|
||||
public static readonly URLINVOKECOMMANDINFO Default = new URLINVOKECOMMANDINFO { dwcbSize = size };
|
||||
}
|
||||
|
||||
/// <summary>CoClass for IUniformResourceLocator.</summary>
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -36,6 +38,7 @@
|
|||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="UrlTests.cs" />
|
||||
<Compile Include="ExplorerTests.cs" />
|
||||
<Compile Include="KnownFolderIdExtTests.cs" />
|
||||
<Compile Include="IconTests.cs" />
|
||||
|
@ -52,6 +55,10 @@
|
|||
<Project>{842D436F-598C-47D7-B5AA-12399F8CCFE9}</Project>
|
||||
<Name>Vanara.PInvoke.Kernel32</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\Ole\Vanara.PInvoke.Ole.csproj">
|
||||
<Project>{BBE4A7D6-0B24-4F58-9726-E05F358C1256}</Project>
|
||||
<Name>Vanara.PInvoke.Ole</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\Shared\Vanara.PInvoke.Shared.csproj">
|
||||
<Project>{a5e519e9-feba-4fe3-93a5-b8269bef72f4}</Project>
|
||||
<Name>Vanara.PInvoke.Shared</Name>
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Vanara.InteropServices;
|
||||
using static Vanara.PInvoke.Ole32;
|
||||
using static Vanara.PInvoke.Url;
|
||||
|
||||
namespace Vanara.PInvoke.Tests
|
||||
{
|
||||
[TestFixture, Apartment(System.Threading.ApartmentState.STA)]
|
||||
public class UrlTests
|
||||
{
|
||||
const string url = "http://docs.microsoft.com/";
|
||||
private static readonly Guid FMTID_InternetSite = new Guid("000214a1-0000-0000-c000-000000000046");
|
||||
|
||||
[Test]
|
||||
public void IUniformResourceLocatorTest()
|
||||
{
|
||||
using var tmp = new TempFile();
|
||||
|
||||
// WRite it out
|
||||
var iUrl = new IUniformResourceLocator();
|
||||
Assert.That(() => iUrl.SetUrl(url), Throws.Nothing);
|
||||
IPersistFile ipf = null;
|
||||
Assert.That(ipf = iUrl as IPersistFile, Is.Not.Null);
|
||||
Assert.That(() => ipf.Save(tmp.FullName, false), Throws.Nothing);
|
||||
|
||||
// Validate file
|
||||
var fi = new System.IO.FileInfo(tmp.FullName);
|
||||
Assert.That(fi.Length, Is.GreaterThan(10));
|
||||
|
||||
// Read it back
|
||||
var iUrl2 = new IUniformResourceLocator();
|
||||
IPersistFile ipf2 = null;
|
||||
Assert.That(ipf2 = iUrl2 as IPersistFile, Is.Not.Null);
|
||||
Assert.That(() => ipf2.Load(tmp.FullName, 0), Throws.Nothing);
|
||||
var url2 = string.Empty;
|
||||
Assert.That(() => iUrl2.GetUrl(out url2), Throws.Nothing);
|
||||
Assert.That(url2, Is.EqualTo(url));
|
||||
|
||||
// Open it
|
||||
Assert.That(() => iUrl2.InvokeCommand(new URLINVOKECOMMANDINFO("open")), Throws.Nothing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InetIsOfflineTest()
|
||||
{
|
||||
Assert.That(InetIsOffline(), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TranslateURLTest()
|
||||
{
|
||||
Assert.That(TranslateURL(url, TRANSLATEURL_IN_FLAGS.TRANSLATEURL_FL_GUESS_PROTOCOL, out var newUrl), ResultIs.Successful);
|
||||
Assert.That(url, Is.EqualTo(newUrl));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue