mirror of https://github.com/dahall/Vanara.git
Bug fixes and cleanup for PROPVARIANT
parent
c5467dfb7e
commit
d90bc7ec42
File diff suppressed because it is too large
Load Diff
|
@ -184,7 +184,7 @@ namespace Vanara.PInvoke
|
|||
/// <summary>An unsigned integer.</summary>
|
||||
[CorrespondingType(typeof(uint))]
|
||||
VT_UINT = 23,
|
||||
/// <summary>The vt void</summary>
|
||||
/// <summary>A C-style void.</summary>
|
||||
[CorrespondingType(typeof(IntPtr))]
|
||||
VT_VOID = 24,
|
||||
/// <summary>A C-style void.</summary>
|
||||
|
@ -232,7 +232,7 @@ namespace Vanara.PInvoke
|
|||
/// <summary>A clipboard format.</summary>
|
||||
[CorrespondingType(typeof(CLIPDATA))]
|
||||
VT_CF = 71,
|
||||
/// <summary>A class ID.</summary>
|
||||
/// <summary>A class ID (GUID).</summary>
|
||||
[CorrespondingType(typeof(Guid))]
|
||||
VT_CLSID = 72,
|
||||
/// <summary>A stream with a GUID version.</summary>
|
||||
|
|
|
@ -299,6 +299,20 @@ namespace Vanara.PInvoke
|
|||
[PInvokeData("propvarutil.h", MSDNShortId = "c958f823-f820-4b0b-86ed-84ad18befbd1")]
|
||||
public static extern HRESULT InitPropVariantFromResource(HINSTANCE hinst, uint id, [In, Out] PROPVARIANT ppropvar);
|
||||
|
||||
/// <summary>Initializes the property variant from string.</summary>
|
||||
/// <param name="psz">Pointer to a buffer that contains the source Unicode string.</param>
|
||||
/// <param name="ppropvar">When this function returns, contains the initialized PROPVARIANT structure.</param>
|
||||
/// <returns>If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.</returns>
|
||||
[PInvokeData("propvarutil.h", MSDNShortId = "cee95d17-532d-8e34-a392-a04778f9bc00")]
|
||||
public static HRESULT InitPropVariantFromString(string psz, [In, Out] PROPVARIANT ppropvar)
|
||||
{
|
||||
PropVariantClear(ppropvar);
|
||||
if (psz is null) return HRESULT.E_INVALIDARG;
|
||||
ppropvar._ptr = Marshal.StringToCoTaskMemUni(psz);
|
||||
ppropvar.vt = VARTYPE.VT_LPWSTR;
|
||||
return HRESULT.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Initializes a PROPVARIANT structure from a specified string. The string is parsed as a semi-colon delimited list (for example: "A;B;C").
|
||||
|
|
|
@ -101,6 +101,7 @@ namespace Vanara.PInvoke.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[TestCase(VARTYPE.VT_CF, "pclipdata")]
|
||||
[TestCase(VARTYPE.VT_ARRAY | VARTYPE.VT_VARIANT, "parray")]
|
||||
[TestCase(VARTYPE.VT_BLOB, "blob")]
|
||||
[TestCase(VARTYPE.VT_BSTR, "bstrVal")]
|
||||
|
@ -112,7 +113,6 @@ namespace Vanara.PInvoke.Tests
|
|||
[TestCase(VARTYPE.VT_BYREF | VARTYPE.VT_ERROR, "pscode")]
|
||||
[TestCase(VARTYPE.VT_BYREF | VARTYPE.VT_UNKNOWN, "ppunkVal")]
|
||||
[TestCase(VARTYPE.VT_BYREF | VARTYPE.VT_VARIANT, "pvarVal")]
|
||||
//[TestCase(VARTYPE.VT_CF, "pclipdata")]
|
||||
[TestCase(VARTYPE.VT_CY, "cyVal")]
|
||||
[TestCase(VARTYPE.VT_CLSID, "puuid")]
|
||||
[TestCase(VARTYPE.VT_DATE, "date")]
|
||||
|
@ -124,17 +124,17 @@ namespace Vanara.PInvoke.Tests
|
|||
[TestCase(VARTYPE.VT_STORAGE, "pStorage")]
|
||||
[TestCase(VARTYPE.VT_STREAM, "pStream")]
|
||||
[TestCase(VARTYPE.VT_UNKNOWN, "punkVal")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_BSTR, "cabstr")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_CF, "caclipdata")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_CLSID, "cauuid")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_CY, "cacy")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_DATE, "cadate")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_ERROR, "cascode")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_FILETIME, "cafiletime")]
|
||||
//[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_LPSTR, "calpstr")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_LPWSTR, "calpwstr")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_VARIANT, "capropvar")]
|
||||
[TestCase(VARTYPE.VT_VERSIONED_STREAM, "pVersionedStream")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_BSTR, "cabstr")]
|
||||
[TestCase(VARTYPE.VT_VECTOR | VARTYPE.VT_LPSTR, "calpstr")]
|
||||
public void PROPVARIANTOtherPropsTest(VARTYPE vt, string prop)
|
||||
{
|
||||
object value;
|
||||
|
@ -145,16 +145,18 @@ namespace Vanara.PInvoke.Tests
|
|||
{
|
||||
var isa = value.GetType().IsArray;
|
||||
Assert.That(pv.vt, Is.EqualTo(vt));
|
||||
var pvVal = pv.Value;
|
||||
if (isa)
|
||||
Assert.That(pv.Value, Is.EquivalentTo((IEnumerable)value));
|
||||
Assert.That(pvVal, Is.EquivalentTo((IEnumerable)value));
|
||||
else
|
||||
Assert.That(pv.Value, Is.EqualTo(value));
|
||||
Assert.That(pvVal, Is.EqualTo(value));
|
||||
var pi = pv.GetType().GetProperty(prop);
|
||||
Assert.That(pi, Is.Not.Null);
|
||||
var piVal = pi.GetValue(pv);
|
||||
if (isa)
|
||||
Assert.That(pi.GetValue(pv), Is.EquivalentTo((IEnumerable)value));
|
||||
Assert.That(piVal, Is.EquivalentTo((IEnumerable)value));
|
||||
else
|
||||
Assert.That(pi.GetValue(pv), Is.EqualTo(value));
|
||||
Assert.That(piVal, Is.EqualTo(value));
|
||||
}
|
||||
}, Throws.Nothing);
|
||||
}
|
||||
|
@ -262,8 +264,9 @@ namespace Vanara.PInvoke.Tests
|
|||
return new Win32Error(5);
|
||||
case VARTYPE.VT_FILETIME:
|
||||
return new DateTime(1999, 12, 31, 23, 59, 59).ToFileTimeStruct();
|
||||
case VARTYPE.VT_BSTR:
|
||||
case VARTYPE.VT_BYREF | VARTYPE.VT_BSTR:
|
||||
return Marshal.StringToBSTR("string");
|
||||
case VARTYPE.VT_BSTR:
|
||||
case VARTYPE.VT_LPSTR:
|
||||
case VARTYPE.VT_LPWSTR:
|
||||
return "string";
|
||||
|
|
Loading…
Reference in New Issue