473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Trouble with Istorage

Hello, I've read quite a bit about implementing this interface in .NET
and believe I have a good start. I am able to use StgIsStorageFile,
StgCreateStorage and StgOpenStorage.

I am now attempting to create a new storage file and then use CopyTo to
copy the contents of a different opened storage file into the new file.
I am getting an error: Invalid pointer error. (Exception from HRESULT:
0x80030009 (STG_E_INVALIDPOINTER)) when calling CopyTo.

Here's my code (VS2005):

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.IO;
using ComTypes = System.Runtime.InteropServices.ComTypes;

namespace SSE
{
class SSProcessor
{
[DllImport("ole32.dll")]
static extern int
StgIsStorageFile([MarshalAs(UnmanagedType.LPWStr)]
string pwcsName);

[DllImport("ole32.dll")]
static extern int
StgCreateDocfile([MarshalAs(UnmanagedType.LPWStr)]
string pwcsName, STGM grfMode, uint reserved, out IStorage
ppstgOpen);

[DllImport("ole32.dll")]
static extern int StgOpenStorage(
[MarshalAs(UnmanagedType.LPWStr)] string pwcsName
, IStorage pstgPriority
, STGM grfMode
, IntPtr snbExclude
, uint reserved
, out IStorage ppstgOpen);

private ArrayList fileList = new ArrayList();

public SSProcessor(ArrayList _fileList)
{
SetFileList(_fileList);
}

private void SetFileList(ArrayList _fileList)
{
fileList = _fileList;
}

public void CullFiles()
{
int count = 0;

foreach (FileSystemInfo file in fileList)
{
try
{
StgIsStorageFile(file.FullName);
count++;
}
catch
{
fileList.RemoveAt(count);
//add code to log non-storagefile items
}
}
}

//public enum STGTY : uint
//{
// STGTY_STORAGE = 1,
// STGTY_STREAM = 2,
// STGTY_LOCKBYTES = 3,
// STGTY_PROPERTY = 4
//}

public enum STGM : uint
{
STGM_READ = 0x00000000,
STGM_WRITE = 0x00000001,
STGM_READWRITE = 0x00000002,
STGM_SHARE_DENY_NONE = 0x00000040,
STGM_SHARE_DENY_READ = 0x00000030,
STGM_SHARE_DENY_WRITE = 0x00000020,
STGM_SHARE_EXCLUSIVE = 0x00000010,
STGM_PRIORITY = 0x00040000,
STGM_CREATE = 0x00001000,
STGM_CONVERT = 0x00020000,
STGM_FAILIFTHERE = 0x00000000,
STGM_DIRECT = 0x00000000,
STGM_TRANSACTED = 0x00010000,
STGM_NOSCRATCH = 0x00100000,
STGM_NOSNAPSHOT = 0x00200000,
STGM_SIMPLE = 0x08000000,
STGM_DIRECT_SWMR = 0x00400000,
STGM_DELETEONRELEASE = 0x04000000,
}

//public enum STGFMT : uint
//{
// STGFMT_STORAGE = 0,
// STGFMT_FILE = 3,
// STGFMT_ANY = 4,
// STGFMT_DOCFILE = 5
//}

public enum STGC : uint
{
STGC_DEFAULT = 0,
STGC_OVERWRITE = 1,
STGC_ONLYIFCURRENT = 2,
STGC_DANGEROUSLYCOMMITMERELYTODISKCACHE = 4,
STGC_CONSOLIDATE = 8
}

public enum STATFLAG : uint
{
STATFLAG_DEFAULT = 0,
STATFLAG_NONAME = 1
}

//public enum STGMOVE : uint
//{
// STGMOVE_MOVE = 0,
// STGMOVE_COPY = 1
//}

[ComImport]
[Guid("0000000d-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IEnumSTATSTG
{
// The user needs to allocate an STATSTG array whose size
is celt.
[PreserveSig]
uint
Next(
uint celt,
//[MarshalAs(UnmanagedType.LPArray), Out]
ComTypes.STATSTG rgelt,
out uint pceltFetched
);

void Skip(uint celt);

void Reset();

[return: MarshalAs(UnmanagedType.Interface)]
IEnumSTATSTG Clone();
}

[ComImport]
[Guid("0000000b-0000-0000-C000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IStorage
{
void CreateStream(
/* [string][in] */ string pwcsName,
/* [in] */ STGM grfMode,
/* [in] */ uint reserved1,
/* [in] */ uint reserved2,
/* [out] */ out IStream ppstm);

void OpenStream(
/* [string][in] */ string pwcsName,
/* [unique][in] */ IntPtr reserved1,
/* [in] */ STGM grfMode,
/* [in] */ uint reserved2,
/* [out] */ out IStream ppstm);

void CreateStorage(
/* [string][in] */ string pwcsName,
/* [in] */ STGM grfMode,
/* [in] */ uint reserved1,
/* [in] */ uint reserved2,
/* [out] */ out IStorage ppstg);

void OpenStorage(
/* [string][unique][in] */ string pwcsName,
/* [unique][in] */ IStorage pstgPriority,
/* [in] */ STGM grfMode,
/* [unique][in] */ IntPtr snbExclude,
/* [in] */ uint reserved,
/* [out] */ out IStorage ppstg);

void CopyTo(
/* [in] */ uint ciidExclude,
/* [size_is][unique][in] */ Guid rgiidExclude,
/* [unique][in] */ IntPtr snbExclude,
/* [unique][in] */ IStorage pstgDest);

void MoveElementTo(
/* [string][in] */ string pwcsName,
/* [unique][in] */ IStorage pstgDest,
/* [string][in] */ string pwcsNewName,
/* [in] */ uint grfFlags);

void Commit(
/* [in] */ STGC grfCommitFlags);

void Revert();

void EnumElements(
/* [in] */ uint reserved1,
/* [size_is][unique][in] */ IntPtr reserved2,
/* [in] */ uint reserved3,
/* [out] */ out IEnumSTATSTG ppenum);

void DestroyElement(
/* [string][in] */ string pwcsName);

void RenameElement(
/* [string][in] */ string pwcsOldName,
/* [string][in] */ string pwcsNewName);

void SetElementTimes(
/* [string][unique][in] */ string pwcsName,
/* [unique][in] */ ComTypes.FILETIME pctime,
/* [unique][in] */ ComTypes.FILETIME patime,
/* [unique][in] */ ComTypes.FILETIME pmtime);

void SetClass(
/* [in] */ Guid clsid);

void SetStateBits(
/* [in] */ uint grfStateBits,
/* [in] */ uint grfMask);

void Stat(
/* [out] */ out ComTypes.STATSTG pstatstg,
/* [in] */ STATFLAG grfStatFlag);
}

public void ProcessFiles()
{
IStorage stg;
IStorage stg_new;

ComTypes.STATSTG s = new ComTypes.STATSTG();

foreach (FileSystemInfo file in fileList)
{
StgCreateDocfile(file.FullName + "_new",
STGM.STGM_READWRITE | STGM.STGM_SHARE_EXCLUSIVE,
0, out stg_new);
StgOpenStorage(file.FullName, null, STGM.STGM_READWRITE
| STGM.STGM_SHARE_EXCLUSIVE,
IntPtr.Zero, 0, out stg);

stg.Stat(out s, STATFLAG.STATFLAG_DEFAULT);

// stg_new.SetClass(s.clsid);

stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}
}
}
}

Aug 8 '06 #1
2 6172
Pretty much I'm just wondering if this is the correct way to use
CopyTo:

public void ProcessFiles()
{
IStorage stg;
IStorage stg_new;

ComTypes.STATSTG s = new ComTypes.STATSTG();

foreach (FileSystemInfo file in fileList)
{
StgCreateDocfile(file.FullName + "_new",
STGM.STGM_READWRITE | STGM.STGM_SHARE_EXCLUSIVE,
0, out stg_new);
StgOpenStorage(file.FullName, null, STGM.STGM_READWRITE

| STGM.STGM_SHARE_EXCLUSIVE,
IntPtr.Zero, 0, out stg);

stg.Stat(out s, STATFLAG.STATFLAG_DEFAULT);
// stg_new.SetClass(s.clsid);
stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}

Aug 8 '06 #2
I've been working on a team that is working on the exact same problem.
We've managed to get this working by instantiating the IStorage Class
just as you did below. Let me know if you'd like me to forward our
in-house expert on Structured Storage.
airs wrote:
Pretty much I'm just wondering if this is the correct way to use
CopyTo:

public void ProcessFiles()
{
IStorage stg;
IStorage stg_new;

ComTypes.STATSTG s = new ComTypes.STATSTG();

foreach (FileSystemInfo file in fileList)
{
StgCreateDocfile(file.FullName + "_new",
STGM.STGM_READWRITE | STGM.STGM_SHARE_EXCLUSIVE,
0, out stg_new);
StgOpenStorage(file.FullName, null, STGM.STGM_READWRITE

| STGM.STGM_SHARE_EXCLUSIVE,
IntPtr.Zero, 0, out stg);

stg.Stat(out s, STATFLAG.STATFLAG_DEFAULT);
// stg_new.SetClass(s.clsid);
stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}
Aug 10 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Darren Mann | last post by:
Hello, I've written a wrapper for IStorage and I know the majority of the code is working fine. The only issue is with EnumElements. When its called the function itself throws a COM Exception...
0
by: Ram | last post by:
I need to serialise COM object members. Cannot be directly done through serialise() attribute, Has anybody worked with IStorage for storing in c#? How to get the IStorage and IStream Interface....
1
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
0
by: tonylc | last post by:
This is relating to the whole concept of burning a CD and using IJolietDiscMaster to use AddData(). If I just need to set IStorage to a specific file so that I can set it in the staging area. ...
6
by: KWienhold | last post by:
I'm currently working on a project in C# (VS 2003 SP1, .Net 1.1) that utilizes IStream/IStorage COM-Elements. Up to now I have gotten everything to work to my satisfaction, but now I have come...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.