本文整理汇总了C#中IStorage.CreateStream方法的典型用法代码示例。如果您正苦于以下问题:C# IStorage.CreateStream方法的具体用法?C# IStorage.CreateStream怎么用?C# IStorage.CreateStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IStorage
的用法示例。
在下文中一共展示了IStorage.CreateStream方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateStreams
private void CreateStreams(StoragePart subStore, IStorage subStorage)
{
foreach (var ds in subStore.DataStreams)
{
comTypes.IStream stream;
subStorage.CreateStream(ds.Key, (uint)(STGM.CREATE | STGM.WRITE | STGM.DIRECT | STGM.SHARE_EXCLUSIVE), 0, 0, out stream);
stream.Write(ds.Value, ds.Value.Length, IntPtr.Zero);
}
subStorage.Commit(0);
}
示例2: openStream
/// <summary>
/// Open a file stream, used by FileStreamEx
/// </summary>
internal static void openStream(IStorage parentStorage, string filename, ref FileMode mode, ref FileAccess access, out IntPtr streamPtr, out IStream stream)
{
ShellAPI.STGM grfmode = ShellAPI.STGM.SHARE_DENY_WRITE;
switch (access)
{
case FileAccess.ReadWrite:
grfmode |= ShellAPI.STGM.READWRITE;
break;
case FileAccess.Write:
grfmode |= ShellAPI.STGM.WRITE;
break;
}
switch (mode)
{
case FileMode.Create:
if (FileEx.Exists(filename))
grfmode |= ShellAPI.STGM.CREATE;
break;
case FileMode.CreateNew:
grfmode |= ShellAPI.STGM.CREATE;
break;
}
if (parentStorage != null)
{
if (parentStorage.OpenStream(
filename,
IntPtr.Zero,
grfmode,
0,
out streamPtr) == ShellAPI.S_OK)
{
stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream));
}
else if (access != FileAccess.Read)
{
//Create file if not exists
if (parentStorage.CreateStream(
filename, ShellAPI.STGM.WRITE, 0, 0, out streamPtr) == ShellAPI.S_OK)
{
stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream));
}
else
throw new IOException(String.Format("Can't open stream: {0}", filename));
}
else
throw new IOException(String.Format("Can't open stream: {0}", filename));
}
else
throw new IOException(String.Format("Can't open stream: {0}", filename));
}
示例3: InternalSaveMiniProject
public static void InternalSaveMiniProject(IStorage pStgSave, AltaxoDocument projectToSave, string graphDocumentName)
{
ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject BEGIN");
try
{
Exception saveEx = null;
Ole32Func.WriteClassStg(pStgSave, typeof(GraphDocumentEmbeddedComObject).GUID);
// Store the version of this assembly
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
Version version = assembly.GetName().Version;
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
string text = version.ToString();
byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text);
stream.Write(nameBytes, 0, nameBytes.Length);
}
}
// Store the name of the item
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(graphDocumentName);
stream.Write(nameBytes, 0, nameBytes.Length);
}
// Store the project
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
using (var zippedStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(stream))
{
var zippedStreamWrapper = new Altaxo.Main.ZipOutputStreamWrapper(zippedStream);
var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();
projectToSave.SaveToZippedFile(zippedStreamWrapper, info);
zippedStream.Close();
}
stream.Close();
}
if (null != saveEx)
throw saveEx;
}
catch (Exception ex)
{
ComDebug.ReportError("InternalSaveMiniProject, Exception ", ex);
}
finally
{
Marshal.ReleaseComObject(pStgSave);
}
ComDebug.ReportInfo("GraphDocumentDataObject.InternalSaveMiniProject END");
}
示例4: Save
public void Save(IStorage pStgSave, bool fSameAsLoad)
{
ComDebug.ReportInfo("{0}.IPersistStorage.Save fSameAsLoad={1}", this.GetType().Name, fSameAsLoad);
try
{
Exception saveEx = null;
Ole32Func.WriteClassStg(pStgSave, this.GetType().GUID);
// Store the version of this assembly
{
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
Version version = assembly.GetName().Version;
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoVersion", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
string text = version.ToString();
byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(text);
stream.Write(nameBytes, 0, nameBytes.Length);
}
}
// Store the name of the item
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoGraphName", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(_document.Name);
stream.Write(nameBytes, 0, nameBytes.Length);
}
// Store the project
using (var stream = new ComStreamWrapper(pStgSave.CreateStream("AltaxoProjectZip", (int)(STGM.DIRECT | STGM.READWRITE | STGM.CREATE | STGM.SHARE_EXCLUSIVE), 0, 0), true))
{
_comManager.InvokeGuiThread(() =>
{
saveEx = Current.ProjectService.SaveProject(stream);
}
);
}
_isDocumentDirty = false;
if (null != saveEx)
throw saveEx;
}
catch (Exception ex)
{
ComDebug.ReportError("{0}.IPersistStorage:Save threw an exception: {1}", this.GetType().Name, ex);
}
finally
{
Marshal.ReleaseComObject(pStgSave);
}
}