代码改变世界

Microsoft.Win32.Ole32

2012-09-22 16:35  落魄的鸡  阅读(183)  评论(0)    收藏  举报
  1 namespace Microsoft.Win32
  2 {
  3     public class Ole32
  4     {
  5         [Serializable, StructLayout(LayoutKind.Sequential)]
  6         public struct FILETIME
  7         {
  8             public uint dwLowDateTime;
  9             public uint dwHighDateTime;
 10         }
 11 
 12         [Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode), BestFitMapping(false)]
 13         public struct WIN32_FIND_DATAW
 14         {
 15             public uint dwFileAttributes;
 16             public FILETIME ftCreationTime;
 17             public FILETIME ftLastAccessTime;
 18             public FILETIME ftLastWriteTime;
 19             public uint nFileSizeHigh;
 20             public uint nFileSizeLow;
 21             public uint dwReserved0;
 22             public uint dwReserved1;
 23             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
 24             public string cFileName;
 25             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]
 26             public string cAlternateFileName;
 27         }
 28 
 29         [ComImport]
 30         [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 31         [Guid("000214F9-0000-0000-C000-000000000046")]
 32         public interface IShellLinkW
 33         {
 34             [PreserveSig]
 35             int GetPath(StringBuilder pszFile, int ch, [In, Out]ref WIN32_FIND_DATAW pfd, uint fFlags);
 36 
 37             [PreserveSig]
 38             int GetIDList([Out] out IntPtr ppidl);
 39 
 40             [PreserveSig]
 41             int SetIDList([In] ref IntPtr pidl);
 42 
 43             [PreserveSig]
 44             int GetDescription(StringBuilder pszName, int cch);
 45 
 46             [PreserveSig]
 47             int SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
 48 
 49             [PreserveSig]
 50             int GetWorkingDirectory(StringBuilder pszDir, int cch);
 51 
 52             [PreserveSig]
 53             int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
 54 
 55             [PreserveSig]
 56             int GetArguments(StringBuilder pszArgs, int cch);
 57 
 58             [PreserveSig]
 59             int SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
 60 
 61             [PreserveSig]
 62             int GetHotkey([Out] out ushort pwHotkey);
 63 
 64             [PreserveSig]
 65             int SetHotkey(ushort wHotkey);
 66 
 67             [PreserveSig]
 68             int GetShowCmd([Out] out int piShowCmd);
 69 
 70             [PreserveSig]
 71             int SetShowCmd(int iShowCmd);
 72 
 73             [PreserveSig]
 74             int GetIconLocation(StringBuilder pszIconPath, int cch, [Out] out int piIcon);
 75 
 76             [PreserveSig]
 77             int SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
 78 
 79             [PreserveSig]
 80             int SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, uint dwReserved);
 81 
 82             [PreserveSig]
 83             int Resolve(IntPtr hwnd, uint fFlags);
 84 
 85             [PreserveSig]
 86             int SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
 87         }
 88 
 89         public enum CLSCTX : uint
 90         {
 91             INPROC_SERVER = 0x1,
 92             INPROC_HANDLER = 0x2,
 93             LOCAL_SERVER = 0x4,
 94             INPROC_SERVER16 = 0x8,
 95             REMOTE_SERVER = 0x10,
 96             INPROC_HANDLER16 = 0x20,
 97             RESERVED1 = 0x40
 98         }
 99 
100         public static Guid CLSID_ShellLink = new Guid("00021401-0000-0000-C000-000000000046");
101 
102         public static Guid IID_IShellLink = new Guid("000214F9-0000-0000-C000-000000000046");
103 
104         [DllImport("ole32.dll", ExactSpelling = true)]
105         public static extern int CoCreateInstance([In]ref Guid rclsid, IntPtr pUnkOuter, CLSCTX dwClsContext, [In]ref Guid riid, [Out] out IntPtr ppv);
106 
107     }
108 }