Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(IsWindows)' != 'true' ">
<Compile Remove="WindowsTaskbarJumpList\*.cs" />
</ItemGroup>

<ItemGroup>
<Compile Remove="singleshell\installer\EngineInstaller.cs" />
<Compile Remove="singleshell\installer\MshHostMshSnapin.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace Microsoft.PowerShell
{
internal static class ComInterfaces
{
[DllImport("kernel32.dll", SetLastError = true, EntryPoint = "GetStartupInfoA")]
internal static extern void GetStartupInfo(out StartUpInfo lpStartupInfo);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct StartUpInfo
{
public Int32 cb;
public string lpReserved;
public string lpDesktop;
public string lpTitle;
public Int32 dwX;
public Int32 dwY;
public Int32 dwXSize;
public Int32 dwYSize;
public Int32 dwXCountChars;
public Int32 dwYCountChars;
public Int32 dwFillAttribute;
public Int32 dwFlags;
public Int16 wShowWindow;
public Int16 cbReserved2;
public IntPtr lpReserved2;
public IntPtr hStdInput;
public IntPtr hStdOutput;
public IntPtr hStdError;
}

[ComImport]
[Guid("00021401-0000-0000-C000-000000000046")]
[ClassInterface(ClassInterfaceType.None)]
internal class CShellLink { }

[ComImport]
[Guid("000214F9-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IShellLinkW
{
void GetPath(
[Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile,
int cchMaxPath,
IntPtr pfd,
uint fFlags);
void GetIDList(out IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription(
[Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile,
int cchMaxName);
void SetDescription(
[MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory(
[Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir,
int cchMaxPath
);
void SetWorkingDirectory(
[MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments(
[Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs,
int cchMaxPath);
void SetArguments(
[MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotKey(out short wHotKey);
void SetHotKey(short wHotKey);
void GetShowCmd(out uint iShowCmd);
void SetShowCmd(uint iShowCmd);
void GetIconLocation(
[Out(), MarshalAs(UnmanagedType.LPWStr)] out StringBuilder pszIconPath,
int cchIconPath,
out int iIcon);
void SetIconLocation(
[MarshalAs(UnmanagedType.LPWStr)] string pszIconPath,
int iIcon);
void SetRelativePath(
[MarshalAs(UnmanagedType.LPWStr)] string pszPathRel,
uint dwReserved);
void Resolve(IntPtr hwnd, uint fFlags);
void SetPath(
[MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}

/// <summary>
/// A property store.
/// </summary>
[ComImport]
[Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IPropertyStore
{
/// <summary>
/// Gets the number of properties contained in the property store.
/// </summary>
/// <param name="propertyCount"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HResult GetCount([Out] out uint propertyCount);

/// <summary>
/// Get a property key located at a specific index.
/// </summary>
/// <param name="propertyIndex"></param>
/// <param name="key"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HResult GetAt([In] uint propertyIndex, out PropertyKey key);

/// <summary>
/// Gets the value of a property from the store.
/// </summary>
/// <param name="key"></param>
/// <param name="pv"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HResult GetValue([In] ref PropertyKey key, [Out] PropVariant pv);

/// <summary>
/// Sets the value of a property in the store.
/// </summary>
/// <param name="key"></param>
/// <param name="pv"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), PreserveSig]
HResult SetValue([In] ref PropertyKey key, [In] PropVariant pv);

/// <summary>
/// Commits the changes.
/// </summary>
/// <returns></returns>
[PreserveSig]
[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
HResult Commit();
}

[ComImport()]
[Guid("6332DEBF-87B5-4670-90C0-5E57B408A49E")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ICustomDestinationList
{
void SetAppID(
[MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
[PreserveSig]
HResult BeginList(
out uint cMaxSlots,
ref Guid riid,
[Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);
[PreserveSig]
HResult AppendCategory(
[MarshalAs(UnmanagedType.LPWStr)] string pszCategory,
[MarshalAs(UnmanagedType.Interface)] IObjectArray poa);
void AppendKnownCategory(
[MarshalAs(UnmanagedType.I4)] KnownDestinationCategory category);
[PreserveSig]
HResult AddUserTasks(
[MarshalAs(UnmanagedType.Interface)] IObjectArray poa);
void CommitList();
void GetRemovedDestinations(
ref Guid riid,
[Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);
void DeleteList(
[MarshalAs(UnmanagedType.LPWStr)] string pszAppID);
void AbortList();
}

internal enum KnownDestinationCategory
{
Frequent = 1,
Recent
}

[ComImport()]
[Guid("92CA9DCD-5622-4BBA-A805-5E9F541BD8C9")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IObjectArray
{
void GetCount(out uint cObjects);
void GetAt(
uint iIndex,
ref Guid riid,
[Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);
}

[ComImport()]
[Guid("5632B1A4-E38A-400A-928A-D4CD63230295")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IObjectCollection
{
// IObjectArray
[PreserveSig]
void GetCount(out uint cObjects);
[PreserveSig]
void GetAt(
uint iIndex,
ref Guid riid,
[Out(), MarshalAs(UnmanagedType.Interface)] out object ppvObject);

// IObjectCollection
void AddObject(
[MarshalAs(UnmanagedType.Interface)] object pvObject);
void AddFromArray(
[MarshalAs(UnmanagedType.Interface)] IObjectArray poaSource);
void RemoveObject(uint uiIndex);
void Clear();
}

[ComImport]
[Guid("45e2b4ae-b1c3-11d0-b92f-00a0c90312e1"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IShellLinkDataListW
{
[PreserveSig]
Int32 AddDataBlock(IntPtr pDataBlock);

[PreserveSig]
Int32 CopyDataBlock(UInt32 dwSig, out IntPtr ppDataBlock);

[PreserveSig]
Int32 RemoveDataBlock(UInt32 dwSig);

void GetFlags(out uint pdwFlags);
void SetFlags(uint dwFlags);
}

[DllImport("ole32.Dll")]
static internal extern HResult CoCreateInstance(ref Guid clsid,
[MarshalAs(UnmanagedType.IUnknown)] object inner,
uint context,
ref Guid uuid,
[MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.PowerShell
{
/// <summary>
/// HRESULT Wrapper
/// </summary>
internal enum HResult
{
/// <summary>
/// S_OK
/// </summary>
Ok = 0x0000,

/// <summary>
/// S_FALSE
/// </summary>
False = 0x0001,

/// <summary>
/// E_INVALIDARG
/// </summary>
InvalidArguments = unchecked((int)0x80070057),

/// <summary>
/// E_OUTOFMEMORY
/// </summary>
OutOfMemory = unchecked((int)0x8007000E),

/// <summary>
/// E_NOINTERFACE
/// </summary>
NoInterface = unchecked((int)0x80004002),

/// <summary>
/// E_FAIL
/// </summary>
Fail = unchecked((int)0x80004005),

/// <summary>
/// E_ELEMENTNOTFOUND
/// </summary>
ElementNotFound = unchecked((int)0x80070490),

/// <summary>
/// TYPE_E_ELEMENTNOTFOUND
/// </summary>
TypeElementNotFound = unchecked((int)0x8002802B),

/// <summary>
/// NO_OBJECT
/// </summary>
NoObject = unchecked((int)0x800401E5),

/// <summary>
/// Win32 Error code: ERROR_CANCELLED
/// </summary>
Win32ErrorCanceled = 1223,

/// <summary>
/// ERROR_CANCELLED
/// </summary>
Canceled = unchecked((int)0x800704C7),

/// <summary>
/// The requested resource is in use
/// </summary>
ResourceInUse = unchecked((int)0x800700AA),

/// <summary>
/// The requested resources is read-only.
/// </summary>
AccessDenied = unchecked((int)0x80030005)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.PowerShell
{
/// <summary>
/// Represents the OLE struct PROPVARIANT.
/// This class is intended for internal use only.
/// </summary>
/// <remarks>
/// Originally sourced from http://blogs.msdn.com/adamroot/pages/interop-with-propvariants-in-net.aspx
/// and modified to add ability to set values
/// </remarks>
[StructLayout(LayoutKind.Explicit)]
internal sealed class PropVariant : IDisposable
{
// This is actually a VarEnum value, but the VarEnum type requires 4 bytes instead of the expected 2.
[FieldOffset(0)]
ushort _valueType;

[FieldOffset(8)]
IntPtr _ptr;

/// <summary>
/// Set a string value
/// </summary>
internal PropVariant(string value)
{
if (value == null)
{
throw new ArgumentException("PropVariantNullString", "value");
}

#pragma warning disable CS0618 // Type or member is obsolete (might get deprecated in future versions
_valueType = (ushort)VarEnum.VT_LPWSTR;
#pragma warning restore CS0618 // Type or member is obsolete (might get deprecated in future versions
_ptr = Marshal.StringToCoTaskMemUni(value);
}

/// <summary>
/// Disposes the object, calls the clear function.
/// </summary>
public void Dispose()
{
PropVariantNativeMethods.PropVariantClear(this);

GC.SuppressFinalize(this);
}

/// <summary>
/// Finalizer
/// </summary>
~PropVariant()
{
Dispose();
}

private class PropVariantNativeMethods
{
[DllImport("Ole32.dll", PreserveSig = false)]
internal extern static void PropVariantClear([In, Out] PropVariant pvar);
}
}
}
Loading