本文整理汇总了C#中System.Runtime.InteropServices.ComTypes.STGMEDIUM类的典型用法代码示例。如果您正苦于以下问题:C# STGMEDIUM类的具体用法?C# STGMEDIUM怎么用?C# STGMEDIUM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
STGMEDIUM类属于System.Runtime.InteropServices.ComTypes命名空间,在下文中一共展示了STGMEDIUM类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetFileList
/// <summary>
/// Gets the file list.
/// </summary>
/// <param name="this">The IDataObject instance.</param>
/// <returns>The file list in the data object.</returns>
public static List<string> GetFileList(this IDataObject @this)
{
// Create the format object.
var formatEtc = new FORMATETC();
// Set up the format object, based on CF_HDROP.
formatEtc.cfFormat = (short)CLIPFORMAT.CF_HDROP;
formatEtc.ptd = IntPtr.Zero;
formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
formatEtc.lindex = -1;
formatEtc.tymed = TYMED.TYMED_HGLOBAL;
// Get the data.
// ReSharper disable RedundantAssignment
var storageMedium = new STGMEDIUM();
// ReSharper restore RedundantAssignment
@this.GetData(ref formatEtc, out storageMedium);
var fileList = new List<string>();
// Things can get risky now.
try
{
// Get the handle to the HDROP.
var hDrop = storageMedium.unionmember;
if (hDrop == IntPtr.Zero)
throw new ArgumentException("Failed to get the handle to the drop data.");
// Get the count of the files in the operation.
var fileCount = Shell32.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);
// Go through each file.
for (uint i = 0; i < fileCount; i++)
{
// Storage for the file name.
var fileNameBuilder = new StringBuilder(MaxPath);
// Get the file name.
var result = Shell32.DragQueryFile(hDrop, i, fileNameBuilder, (uint)fileNameBuilder.Capacity);
// If we have a valid result, add the file name to the list of files.
if (result != 0)
fileList.Add(fileNameBuilder.ToString());
}
}
finally
{
Ole32.ReleaseStgMedium(ref storageMedium);
}
return fileList;
}
开发者ID:JamesLinus,项目名称:sharpshell,代码行数:58,代码来源:IDataObjectExtensions.cs
示例2: UIntPtr
void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref FORMATETC formatetc, out STGMEDIUM medium)
{
if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id)
m_lindex = formatetc.lindex;
medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();
if (GetTymedUseable(formatetc.tymed)) {
if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(NativeMethods.CFSTR_FILECONTENTS).Id) {
if ((formatetc.tymed & TYMED.TYMED_ISTREAM) != TYMED.TYMED_NULL) {
medium.tymed = TYMED.TYMED_ISTREAM;
// medium.unionmember = Marshal.GetComInterfaceForObject(GetFileContents(this.m_SelectedItems, formatetc.lindex), typeof(IStreamWrapper));
medium.unionmember = NativeMethods.VirtualAlloc(IntPtr.Zero, new UIntPtr(1), NativeMethods.MEM_COMMIT, NativeMethods.PAGE_READWRITE);
if (medium.unionmember == IntPtr.Zero) {
throw new OutOfMemoryException();
}
try {
((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
return;
} catch {
NativeMethods.VirtualFree(medium.unionmember, new UIntPtr(1), NativeMethods.MEM_DECOMMIT);
medium.unionmember = IntPtr.Zero;
throw;
}
}
} else {
if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != TYMED.TYMED_NULL) {
medium.tymed = TYMED.TYMED_HGLOBAL;
medium.unionmember = NativeMethods.GlobalAlloc(NativeMethods.GHND | NativeMethods.GMEM_DDESHARE, 1);
if (medium.unionmember == IntPtr.Zero) {
throw new OutOfMemoryException();
}
try {
((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
return;
} catch {
NativeMethods.GlobalFree(new HandleRef((STGMEDIUM)medium, medium.unionmember));
medium.unionmember = IntPtr.Zero;
throw;
}
}
}
medium.tymed = formatetc.tymed;
((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
} else {
Marshal.ThrowExceptionForHR(NativeMethods.DV_E_TYMED);
}
}
开发者ID:MTGUli,项目名称:TREExplorer,代码行数:49,代码来源:ClassDataObjectEx.cs
示例3: Convert
public static object Convert(string format, ref STGMEDIUM medium)
{
if (medium.unionmember != IntPtr.Zero)
{
if (medium.tymed == TYMED.TYMED_HGLOBAL)
{
return ConvertHandle(format, new HandleRef(format, medium.unionmember));
}
if (medium.tymed == TYMED.TYMED_ISTREAM)
{
return ConvertStream(format, new HandleRef(format, medium.unionmember));
}
if (medium.tymed == TYMED.TYMED_GDI)
{
return ConvertBitmap(new HandleRef(format, medium.unionmember));
}
}
return null;
}
开发者ID:sbambach,项目名称:ATF,代码行数:19,代码来源:OleConverter.cs
示例4: OutOfMemoryException
void System.Runtime.InteropServices.ComTypes.IDataObject.GetData(ref System.Runtime.InteropServices.ComTypes.FORMATETC formatetc, out System.Runtime.InteropServices.ComTypes.STGMEDIUM medium)
{
if (formatetc.cfFormat == (Int16)DataFormats.GetFormat(Win32.NativeMethods.CFSTR_FILECONTENTS).Id)
m_lindex = formatetc.lindex;
medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();
if (GetTymedUseable(formatetc.tymed))
{
if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != TYMED.TYMED_NULL)
{
medium.tymed = TYMED.TYMED_HGLOBAL;
medium.unionmember = Win32.NativeMethods.GlobalAlloc(Win32.NativeMethods.GHND | Win32.NativeMethods.GMEM_DDESHARE, 1);
if (medium.unionmember == IntPtr.Zero)
{
throw new OutOfMemoryException();
}
try
{
((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
return;
}
catch
{
Win32.NativeMethods.GlobalFree(new HandleRef((STGMEDIUM)medium, medium.unionmember));
medium.unionmember = IntPtr.Zero;
throw;
}
}
medium.tymed = formatetc.tymed;
((System.Runtime.InteropServices.ComTypes.IDataObject)this).GetDataHere(ref formatetc, ref medium);
}
else
{
Marshal.ThrowExceptionForHR(Win32.NativeMethods.DV_E_TYMED);
}
}
开发者ID:pvginkel,项目名称:SystemEx,代码行数:36,代码来源:OleDataObject.cs
示例5: STGMEDIUM
void IComDataObject.GetData(ref FORMATETC formatetc, out STGMEDIUM medium) {
Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "GetData");
if (innerData is OleConverter) {
((OleConverter)innerData).OleDataObject.GetData(ref formatetc, out medium);
return;
}
medium = new STGMEDIUM();
if (GetTymedUseable(formatetc.tymed)) {
if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != 0) {
medium.tymed = TYMED.TYMED_HGLOBAL;
medium.unionmember = UnsafeNativeMethods.GlobalAlloc(NativeMethods.GMEM_MOVEABLE
| NativeMethods.GMEM_DDESHARE
| NativeMethods.GMEM_ZEROINIT,
1);
if (medium.unionmember == IntPtr.Zero) {
throw new OutOfMemoryException();
}
try {
((IComDataObject)this).GetDataHere(ref formatetc, ref medium);
}
catch {
UnsafeNativeMethods.GlobalFree(new HandleRef(medium, medium.unionmember));
medium.unionmember = IntPtr.Zero;
throw;
}
}
else {
medium.tymed = formatetc.tymed;
((IComDataObject)this).GetDataHere(ref formatetc, ref medium);
}
}
else {
Marshal.ThrowExceptionForHR(DV_E_TYMED);
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:38,代码来源:DataObject.cs
示例6: GetDataFromOleOther
/// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.OleConverter.GetDataFromOleOther"]/*' />
/// <devdoc>
/// Retrieves the specified format data from the bound IComDataObject, from
/// other sources that IStream and HGLOBAL... this is really just a place
/// to put the "special" formats like BITMAP, ENHMF, etc.
/// </devdoc>
/// <internalonly/>
private Object GetDataFromOleOther(string format) {
Debug.Assert(innerData != null, "You must have an innerData on all DataObjects");
FORMATETC formatetc = new FORMATETC();
STGMEDIUM medium = new STGMEDIUM();
TYMED tymed = (TYMED)0;
if (format.Equals(DataFormats.Bitmap)) {
tymed = TYMED.TYMED_GDI;
}
else if (format.Equals(DataFormats.EnhancedMetafile)) {
tymed = TYMED.TYMED_ENHMF;
}
if (tymed == (TYMED)0) {
return null;
}
formatetc.cfFormat = unchecked((short)(ushort)(DataFormats.GetFormat(format).Id));
formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = tymed;
medium.tymed = tymed;
Object data = null;
if (NativeMethods.S_OK == QueryGetDataUnsafe(ref formatetc)) {
try {
IntSecurity.UnmanagedCode.Assert();
try {
innerData.GetData(ref formatetc, out medium);
}
finally {
CodeAccessPermission.RevertAssert();
}
}
catch {
}
}
if (medium.unionmember != IntPtr.Zero) {
if (format.Equals(DataFormats.Bitmap)
//||format.Equals(DataFormats.Dib))
) {
// as/urt 140870 -- GDI+ doesn't own this HBITMAP, but we can't
// delete it while the object is still around. So we have to do the really expensive
// thing of cloning the image so we can release the HBITMAP.
//
//This bitmap is created by the com object which originally copied the bitmap to tbe
//clipboard. We call Add here, since DeleteObject calls Remove.
System.Internal.HandleCollector.Add(medium.unionmember, NativeMethods.CommonHandles.GDI);
Image clipboardImage = null;
IntSecurity.ObjectFromWin32Handle.Assert();
try
{
clipboardImage = Image.FromHbitmap(medium.unionmember);
}
finally
{
CodeAccessPermission.RevertAssert();
}
if (clipboardImage != null) {
Image firstImage = clipboardImage;
clipboardImage = (Image)clipboardImage.Clone();
SafeNativeMethods.DeleteObject(new HandleRef(null, medium.unionmember));
firstImage.Dispose();
}
data = clipboardImage;
}
/* gpr:
else if (format.Equals(DataFormats.EnhancedMetafile)) {
data = new Metafile(medium.unionmember);
}
*/
}
return data;
}
开发者ID:JianwenSun,项目名称:cc,代码行数:87,代码来源:DataObject.cs
示例7: GetDataIntoOleStructs
/// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.GetDataIntoOleStructs"]/*' />
/// <devdoc>
/// Populates Ole datastructes from a [....] dataObject. This is the core
/// of [....] to OLE conversion.
/// </devdoc>
/// <internalonly/>
private void GetDataIntoOleStructs(ref FORMATETC formatetc,
ref STGMEDIUM medium) {
if (GetTymedUseable(formatetc.tymed) && GetTymedUseable(medium.tymed)) {
string format = DataFormats.GetFormat(formatetc.cfFormat).Name;
if (GetDataPresent(format)) {
Object data = GetData(format);
if ((formatetc.tymed & TYMED.TYMED_HGLOBAL) != 0) {
int hr = SaveDataToHandle(data, format, ref medium);
if (NativeMethods.Failed(hr)) {
Marshal.ThrowExceptionForHR(hr);
}
}
else if ((formatetc.tymed & TYMED.TYMED_GDI) != 0) {
if (format.Equals(DataFormats.Bitmap) && data is Bitmap) {
// save bitmap
//
Bitmap bm = (Bitmap)data;
if (bm != null) {
medium.unionmember = GetCompatibleBitmap(bm); // gpr: Does this get properly disposed?
}
}
}
/* gpr
else if ((formatetc.tymed & TYMED.TYMED_ENHMF) != 0) {
if (format.Equals(DataFormats.EnhancedMetafile)
&& data is Metafile) {
// save metafile
Metafile mf = (Metafile)data;
if (mf != null) {
medium.unionmember = mf.Handle;
}
}
}
*/
else {
Marshal.ThrowExceptionForHR (DV_E_TYMED);
}
}
else {
Marshal.ThrowExceptionForHR (DV_E_FORMATETC);
}
}
else {
Marshal.ThrowExceptionForHR (DV_E_TYMED);
}
}
开发者ID:JianwenSun,项目名称:cc,代码行数:56,代码来源:DataObject.cs
示例8: ParseShellIDListArray
private ShellObject[] ParseShellIDListArray(System.Runtime.InteropServices.ComTypes.IDataObject pDataObj)
{
List<ShellObject> result = new List<ShellObject>();
System.Runtime.InteropServices.ComTypes.FORMATETC format = new System.Runtime.InteropServices.ComTypes.FORMATETC();
System.Runtime.InteropServices.ComTypes.STGMEDIUM medium = new System.Runtime.InteropServices.ComTypes.STGMEDIUM();
format.cfFormat = (short)ExplorerBrowser.RegisterClipboardFormat("Shell IDList Array");
format.dwAspect = System.Runtime.InteropServices.ComTypes.DVASPECT.DVASPECT_CONTENT;
format.lindex = 0;
format.ptd = IntPtr.Zero;
format.tymed = System.Runtime.InteropServices.ComTypes.TYMED.TYMED_HGLOBAL;
pDataObj.GetData(ref format, out medium);
ExplorerBrowser.GlobalLock(medium.unionmember);
try
{
ShellObject parentFolder = null;
int count = Marshal.ReadInt32(medium.unionmember);
int offset = 4;
for (int n = 0; n <= count; ++n)
{
int pidlOffset = Marshal.ReadInt32(medium.unionmember, offset);
int pidlAddress = (int)medium.unionmember + pidlOffset;
if (n == 0)
{
parentFolder = ShellObjectFactory.Create(new IntPtr(pidlAddress));
}
else
{
result.Add(ShellObjectFactory.Create(ExplorerBrowser.CreateItemWithParent(GetIShellFolder(parentFolder.NativeShellItem), new IntPtr(pidlAddress))));
}
offset += 4;
}
}
finally
{
Marshal.FreeHGlobal(medium.unionmember);
}
return result.ToArray();
}
开发者ID:jmbolivar,项目名称:BetterExplorer,代码行数:45,代码来源:ExplorerBrowser.cs
示例9: GetDataFromOleHGLOBAL
/// <include file='doc\DataObject.uex' path='docs/doc[@for="DataObject.OleConverter.GetDataFromOleHGLOBAL"]/*' />
/// <devdoc>
/// Uses HGLOBALs and retrieves the specified format from the bound IComDatabject.
/// </devdoc>
/// <internalonly/>
private Object GetDataFromOleHGLOBAL(string format) {
Debug.Assert(innerData != null, "You must have an innerData on all DataObjects");
FORMATETC formatetc = new FORMATETC();
STGMEDIUM medium = new STGMEDIUM();
formatetc.cfFormat = unchecked((short)(ushort)(DataFormats.GetFormat(format).Id));
formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = TYMED.TYMED_HGLOBAL;
medium.tymed = TYMED.TYMED_HGLOBAL;
object data = null;
if (NativeMethods.S_OK == QueryGetDataUnsafe(ref formatetc)) {
try {
IntSecurity.UnmanagedCode.Assert();
try {
innerData.GetData(ref formatetc, out medium);
}
finally {
CodeAccessPermission.RevertAssert();
}
if (medium.unionmember != IntPtr.Zero) {
data = GetDataFromHGLOBLAL(format, medium.unionmember);
}
}
catch {
}
}
return data;
}
开发者ID:JianwenSun,项目名称:cc,代码行数:39,代码来源:DataObject.cs
示例10: SaveDataToHandle
private int SaveDataToHandle(object data, string format, ref STGMEDIUM medium) {
int hr = NativeMethods.E_FAIL;
if (data is Stream) {
hr = SaveStreamToHandle(ref medium.unionmember, (Stream)data);
}
else if (format.Equals(DataFormats.Text)
|| format.Equals(DataFormats.Rtf)
|| format.Equals(DataFormats.OemText)) {
hr = SaveStringToHandle(medium.unionmember, data.ToString(), false);
}
else if (format.Equals(DataFormats.Html)) {
hr = SaveHtmlToHandle(medium.unionmember, data.ToString());
}
else if (format.Equals(DataFormats.UnicodeText)) {
hr = SaveStringToHandle(medium.unionmember, data.ToString(), true);
}
else if (format.Equals(DataFormats.FileDrop)) {
hr = SaveFileListToHandle(medium.unionmember, (string[])data);
}
else if (format.Equals(CF_DEPRECATED_FILENAME)) {
string[] filelist = (string[])data;
hr = SaveStringToHandle(medium.unionmember, filelist[0], false);
}
else if (format.Equals(CF_DEPRECATED_FILENAMEW)) {
string[] filelist = (string[])data;
hr = SaveStringToHandle(medium.unionmember, filelist[0], true);
}
else if (format.Equals(DataFormats.Dib)
&& data is Image) {
// GDI+ does not properly handle saving to DIB images. Since the
// clipboard will take an HBITMAP and publish a Dib, we don't need
// to support this.
//
hr = DV_E_TYMED; // SaveImageToHandle(ref medium.unionmember, (Image)data);
}
else if (format.Equals(DataFormats.Serializable)
|| data is ISerializable
|| (data != null && data.GetType().IsSerializable)) {
hr = SaveObjectToHandle(ref medium.unionmember, data);
}
return hr;
}
开发者ID:JianwenSun,项目名称:cc,代码行数:42,代码来源:DataObject.cs
示例11: GetMediumFromObject
private static void GetMediumFromObject(object data, out STGMEDIUM medium)
{
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(DataObjectExtensions.ManagedDataStamp.ToByteArray(), 0, Marshal.SizeOf(typeof(Guid)));
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize((Stream)memoryStream, (object)data.GetType());
binaryFormatter.Serialize((Stream)memoryStream, DataObjectExtensions.GetAsSerializable(data));
byte[] buffer = memoryStream.GetBuffer();
IntPtr num = Marshal.AllocHGlobal(buffer.Length);
try
{
Marshal.Copy(buffer, 0, num, buffer.Length);
}
catch
{
Marshal.FreeHGlobal(num);
throw;
}
medium.unionmember = num;
medium.tymed = TYMED.TYMED_HGLOBAL;
medium.pUnkForRelease = (object)null;
}
开发者ID:kingpin2k,项目名称:MCS,代码行数:22,代码来源:DataObjectExtensions.cs
示例12: GetData
public void GetData(ref FORMATETC format, out STGMEDIUM medium)
{
ComDebug.ReportInfo("{0}.IDataObject.GetData({1})", this.GetType().Name, DataObjectHelper.FormatEtcToString(format));
try
{
// Locate the data
foreach (var rendering in Renderings)
{
if ((rendering.format.tymed & format.tymed) > 0
&& rendering.format.dwAspect == format.dwAspect
&& rendering.format.cfFormat == format.cfFormat
&& rendering.renderer != null)
{
// Found it. Return a copy of the data.
medium = new STGMEDIUM();
medium.tymed = rendering.format.tymed & format.tymed;
medium.unionmember = rendering.renderer(medium.tymed);
if (medium.tymed == TYMED.TYMED_ISTORAGE || medium.tymed == TYMED.TYMED_ISTREAM)
medium.pUnkForRelease = Marshal.GetObjectForIUnknown(medium.unionmember);
else
medium.pUnkForRelease = null;
return;
}
}
}
catch (Exception e)
{
ComDebug.ReportError("{0}.IDataObject.GetData threw an exception {1}", this.GetType().Name, e);
throw;
}
ComDebug.ReportInfo("{0}.IDataObject.GetData, no data delivered!", this.GetType().Name);
medium = new STGMEDIUM();
// Marshal.ThrowExceptionForHR(ComReturnValue.DV_E_FORMATETC);
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:37,代码来源:DataObjectBase.cs
示例13: SetData
public void SetData(ref FORMATETC formatIn, ref STGMEDIUM medium, bool release)
{
ComDebug.ReportError("{0}.IDataObject.SetData - NOT SUPPORTED!", this.GetType().Name);
throw new NotSupportedException();
}
开发者ID:Altaxo,项目名称:Altaxo,代码行数:5,代码来源:DataObjectBase.cs
示例14: GetData
// Get this clipboard format out of this data object
public static byte[] GetData(IDataObject oData, string cfFormat)
{
// First, we try using the built-in functionality. Unfortunately, in the TYMED_ISTREAM case
// they forget to seek the stream to zero, and so aren't successful. We'll take care of that
// in a moment.
//
System.IO.Stream stm = (System.IO.Stream)oData.GetData(cfFormat, false);
if (null != stm)
{
stm.Seek(0, System.IO.SeekOrigin.Begin);
int cb = (int)stm.Length;
byte[] rgb = new byte[cb];
int cbRead = stm.Read(rgb, 0, cb);
if (cbRead == cb)
{
// The bug is that the data returned is entirely zero. Let's check.
//
for (int ib=0; ib < cb; ib++)
{
if (rgb[ib] != 0)
return rgb;
}
}
}
//
// Ok, try to see if we can get it on a stream ourselves
//
COMTypes.IDataObject ido = (COMTypes.IDataObject)oData;
COMTypes.FORMATETC formatEtc = new COMTypes.FORMATETC();
COMTypes.STGMEDIUM medium = new COMTypes.STGMEDIUM();
formatEtc.cfFormat = (short)DataFormats.GetFormat(cfFormat).Id;
formatEtc.dwAspect = COMTypes.DVASPECT.DVASPECT_CONTENT;
formatEtc.lindex = -1; // REVIEW: is 0 better?
formatEtc.tymed = COMTypes.TYMED.TYMED_ISTREAM;
//
ido.GetData(ref formatEtc, out medium);
//
if (medium.unionmember != IntPtr.Zero)
{
// Get at the IStream and release the ref in the medium
COMTypes.IStream istm = (COMTypes.IStream)Marshal.GetObjectForIUnknown(medium.unionmember);
Marshal.Release(medium.unionmember);
// How big is the stream?
COMTypes.STATSTG statstg = new COMTypes.STATSTG();
istm.Stat(out statstg, 1);
int cb = (int)statstg.cbSize;
byte[] rgb = new byte[cb];
// Seek the stream to the beginning and read the data
IntPtr pcbRead = Marshal.AllocCoTaskMem(sizeof(int));
istm.Seek(0, 0, IntPtr.Zero);
istm.Read(rgb, cb, pcbRead);
int cbRead = Marshal.ReadInt32(pcbRead);
Marshal.FreeCoTaskMem(pcbRead);
if (cb==cbRead)
return rgb;
}
//
// Can't get the data
//
return null;
}
开发者ID:redshiftrobotics,项目名称:telemetry_Archive,代码行数:65,代码来源:WIN32.cs
示例15: GetSelectedItems
internal static void GetSelectedItems(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID, ref List<String> SelectedItems, ref bool isClickOnEmptyArea)
{
if (pDataObj == IntPtr.Zero && pidlFolder == IntPtr.Zero)
throw new ArgumentException();
else if (pDataObj == IntPtr.Zero)
{
//User Click on Empty Area of a Folder, pDataObj is empty while pidlFolder is the current path
StringBuilder sb = new StringBuilder(260);
if (!NativeMethods.SHGetPathFromIDListW(pidlFolder, sb))
Marshal.ThrowExceptionForHR(WinError.E_FAIL);
else
{
isClickOnEmptyArea = true;
SelectedItems = new List<string>();
SelectedItems.Add(sb.ToString());
}
}
else
{
//User actually select some item, pDataObj is the list while pidlFolder is empty
isClickOnEmptyArea = false;
FORMATETC fe = new FORMATETC();
fe.cfFormat = (short)CLIPFORMAT.CF_HDROP;
fe.ptd = IntPtr.Zero;
fe.dwAspect = DVASPECT.DVASPECT_CONTENT;
fe.lindex = -1;
fe.tymed = TYMED.TYMED_HGLOBAL;
STGMEDIUM stm = new STGMEDIUM();
IDataObject dataObject = (IDataObject)Marshal.GetObjectForIUnknown(pDataObj);
dataObject.GetData(ref fe, out stm);
try
{
IntPtr hDrop = stm.unionmember;
if (hDrop == IntPtr.Zero)
throw new ArgumentException();
uint nFiles = NativeMethods.DragQueryFile(hDrop, UInt32.MaxValue, null, 0);
if (nFiles == 0)
Marshal.ThrowExceptionForHR(WinError.E_FAIL);
SelectedItems = new List<string>();
for (int i = 0; i < nFiles; i++)
{
StringBuilder sb = new StringBuilder(260);
if (NativeMethods.DragQueryFile(hDrop, (uint)i, sb, sb.Capacity) == 0)
Marshal.ThrowExceptionForHR(WinError.E_FAIL);
else
SelectedItems.Add(sb.ToString());
}
}
finally
{
NativeMethods.ReleaseStgMedium(ref stm);
}
}
}
开发者ID:hkmikemak,项目名称:ExplorerExtender,代码行数:61,代码来源:Helper.cs
示例16: InsertEmbeddedAtPosition
private void InsertEmbeddedAtPosition(TextPointer position, IComDataObject data, out UnsafeNativeMethods.TS_TEXTCHANGE change)
{
SecurityHelper.DemandUnmanagedCode();
ITextContainer container;
// Get enhanced metafile handle from IOleDataObject.
FORMATETC formatetc = new FORMATETC();
STGMEDIUM stgmedium = new STGMEDIUM();
formatetc.cfFormat = NativeMethods.CF_ENHMETAFILE;
formatetc.ptd = IntPtr.Zero;
formatetc.dwAspect = DVASPECT.DVASPECT_CONTENT;
formatetc.lindex = -1;
formatetc.tymed = TYMED.TYMED_ENHMF;
stgmedium.tymed = TYMED.TYMED_ENHMF;
data.GetData(ref formatetc, out stgmedium);
if (stgmedium.unionmember == IntPtr.Zero)
{
throw new COMException(SR.Get(SRID.TextStore_BadObjectData), NativeMethods.E_INVALIDARG);
}
IntPtr hbitmap = SystemDrawingHelper.ConvertMetafileToHBitmap(stgmedium.unionmember);
// create a InkInteropObject framework element.
InkInteropObject inkobject = new InkInteropObject(data);
inkobject.Source = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, null);
position = InsertInkAtPosition(position, inkobject, out change);
// Move the selection.
container = this.TextContainer;
TextSelection.SetCaretToPosition(position, LogicalDirection.Backward, /*allowStopAtLineEnd:*/false, /*allowStopNearSpace:*/false);
}
开发者ID:mind0n,项目名称:hive,代码行数:35,代码来源:TextStore.cs
示例17: GetMediumFromObject
/// <summary>
/// Serializes managed data to an HGLOBAL.
/// </summary>
/// <param name="data">The managed data object.</param>
/// <returns>An STGMEDIUM pointing to the allocated HGLOBAL.</returns>
private static void GetMediumFromObject(object data, out STGMEDIUM medium)
{
// We'll serialize to a managed stream temporarily
MemoryStream stream = new MemoryStream();
// Write an indentifying stamp, so we can recognize this as custom
// marshaled data.
stream.Write(ManagedDataStamp.ToByteArray(), 0, Marshal.SizeOf(typeof(Guid)));
// Now serialize the data. Note, if the data is not directly serializable,
// we'll try type conversion. Also, we serialize the type. That way,
// during deserialization, we know which type to convert back to, if
// appropriate.
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, data.GetType());
formatter.Serialize(stream, GetAsSerializable(data));
// Now copy to an HGLOBAL
byte[] bytes = stream.GetBuffer();
IntPtr p = Marshal.AllocHGlobal(bytes.Length);
try
{
Marshal.Copy(bytes, 0, p, bytes.Length);
}
catch
{
// Make sure to free the memory on exceptions
Marshal.FreeHGlobal(p);
throw;
}
// Now allocate an STGMEDIUM to wrap the HGLOBAL
medium.unionmember = p;
medium.tymed = ComTypes.TYMED.TYMED_HGLOBAL;
medium.pUnkForRelease = null;
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:41,代码来源:DataObjectExtensions.cs
示例18: ReleaseStgMedium
private static extern void ReleaseStgMedium(ref STGMEDIUM pmedium);
开发者ID:hbaes,项目名称:updateSystem.NET,代码行数:1,代码来源:DataObjectExtensions.cs
示例19: OnDataChange
/// <summary>
/// Handles DataChanged events from a COM IDataObject.
/// </summary>
/// <param name="format">The data format that had a change.</param>
/// <param name="stgmedium">The data value.</param>
public void OnDataChange(ref FORMATETC format, ref STGMEDIUM stgmedium)
{
// We listen to DropDescription changes, so that we can unset the IsDefault
// drop description flag.
var odd = DropDescriptionHelper.GetDropDescription(m_data);
if (odd != null)
{
DropDescriptionHelper.SetDropDescriptionIsDefault(m_data, false);
}
}
开发者ID:JanDeHud,项目名称:LevelEditor,代码行数:15,代码来源:DragDropExtender.cs
示例20: NotImplementedException
void IComDataObject.SetData(ref FORMATETC pFormatetcIn, ref STGMEDIUM pmedium, bool fRelease) {
Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "SetData");
if (innerData is OleConverter) {
((OleConverter)innerData).OleDataObject.SetData(ref pFormatetcIn, ref pmedium, fRelease);
return;
}
//
throw new NotImplementedException();
}
开发者ID:JianwenSun,项目名称:cc,代码行数:11,代码来源:DataObject.cs
注:本文中的System.Runtime.InteropServices.ComTypes.STGMEDIUM类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论