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 StgIsStorageFil e,
StgCreateStorag e 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_INVALIDP OINTER)) when calling CopyTo.
Here's my code (VS2005):
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Collecti ons;
using System.Runtime. InteropServices ;
using System.Runtime. InteropServices .ComTypes;
using System.IO;
using ComTypes = System.Runtime. InteropServices .ComTypes;
namespace SSE
{
class SSProcessor
{
[DllImport("ole3 2.dll")]
static extern int
StgIsStorageFil e([MarshalAs(Unman agedType.LPWStr )]
string pwcsName);
[DllImport("ole3 2.dll")]
static extern int
StgCreateDocfil e([MarshalAs(Unman agedType.LPWStr )]
string pwcsName, STGM grfMode, uint reserved, out IStorage
ppstgOpen);
[DllImport("ole3 2.dll")]
static extern int StgOpenStorage(
[MarshalAs(Unman agedType.LPWStr )] string pwcsName
, IStorage pstgPriority
, STGM grfMode
, IntPtr snbExclude
, uint reserved
, out IStorage ppstgOpen);
private ArrayList fileList = new ArrayList();
public SSProcessor(Arr ayList _fileList)
{
SetFileList(_fi leList);
}
private void SetFileList(Arr ayList _fileList)
{
fileList = _fileList;
}
public void CullFiles()
{
int count = 0;
foreach (FileSystemInfo file in fileList)
{
try
{
StgIsStorageFil e(file.FullName );
count++;
}
catch
{
fileList.Remove At(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_EXCL USIVE = 0x00000010,
STGM_PRIORITY = 0x00040000,
STGM_CREATE = 0x00001000,
STGM_CONVERT = 0x00020000,
STGM_FAILIFTHER E = 0x00000000,
STGM_DIRECT = 0x00000000,
STGM_TRANSACTED = 0x00010000,
STGM_NOSCRATCH = 0x00100000,
STGM_NOSNAPSHOT = 0x00200000,
STGM_SIMPLE = 0x08000000,
STGM_DIRECT_SWM R = 0x00400000,
STGM_DELETEONRE LEASE = 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_ONLYIFCURR ENT = 2,
STGC_DANGEROUSL YCOMMITMERELYTO DISKCACHE = 4,
STGC_CONSOLIDAT E = 8
}
public enum STATFLAG : uint
{
STATFLAG_DEFAUL T = 0,
STATFLAG_NONAME = 1
}
//public enum STGMOVE : uint
//{
// STGMOVE_MOVE = 0,
// STGMOVE_COPY = 1
//}
[ComImport]
[Guid("0000000d-0000-0000-C000-000000000046")]
[InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface IEnumSTATSTG
{
// The user needs to allocate an STATSTG array whose size
is celt.
[PreserveSig]
uint
Next(
uint celt,
//[MarshalAs(Unman agedType.LPArra y), Out]
ComTypes.STATST G rgelt,
out uint pceltFetched
);
void Skip(uint celt);
void Reset();
[return: MarshalAs(Unman agedType.Interf ace)]
IEnumSTATSTG Clone();
}
[ComImport]
[Guid("0000000b-0000-0000-C000-000000000046")]
[InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
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.FILETI ME pctime,
/* [unique][in] */ ComTypes.FILETI ME patime,
/* [unique][in] */ ComTypes.FILETI ME pmtime);
void SetClass(
/* [in] */ Guid clsid);
void SetStateBits(
/* [in] */ uint grfStateBits,
/* [in] */ uint grfMask);
void Stat(
/* [out] */ out ComTypes.STATST G pstatstg,
/* [in] */ STATFLAG grfStatFlag);
}
public void ProcessFiles()
{
IStorage stg;
IStorage stg_new;
ComTypes.STATST G s = new ComTypes.STATST G();
foreach (FileSystemInfo file in fileList)
{
StgCreateDocfil e(file.FullName + "_new",
STGM.STGM_READW RITE | STGM.STGM_SHARE _EXCLUSIVE,
0, out stg_new);
StgOpenStorage( file.FullName, null, STGM.STGM_READW RITE
| STGM.STGM_SHARE _EXCLUSIVE,
IntPtr.Zero, 0, out stg);
stg.Stat(out s, STATFLAG.STATFL AG_DEFAULT);
// stg_new.SetClas s(s.clsid);
stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}
}
}
} 2 6226
Pretty much I'm just wondering if this is the correct way to use
CopyTo:
public void ProcessFiles()
{
IStorage stg;
IStorage stg_new;
ComTypes.STATST G s = new ComTypes.STATST G();
foreach (FileSystemInfo file in fileList)
{
StgCreateDocfil e(file.FullName + "_new",
STGM.STGM_READW RITE | STGM.STGM_SHARE _EXCLUSIVE,
0, out stg_new);
StgOpenStorage( file.FullName, null, STGM.STGM_READW RITE
| STGM.STGM_SHARE _EXCLUSIVE,
IntPtr.Zero, 0, out stg);
stg.Stat(out s, STATFLAG.STATFL AG_DEFAULT);
// stg_new.SetClas s(s.clsid);
stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}
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.STATST G s = new ComTypes.STATST G();
foreach (FileSystemInfo file in fileList)
{
StgCreateDocfil e(file.FullName + "_new",
STGM.STGM_READW RITE | STGM.STGM_SHARE _EXCLUSIVE,
0, out stg_new);
StgOpenStorage( file.FullName, null, STGM.STGM_READW RITE
| STGM.STGM_SHARE _EXCLUSIVE,
IntPtr.Zero, 0, out stg);
stg.Stat(out s, STATFLAG.STATFL AG_DEFAULT);
// stg_new.SetClas s(s.clsid);
stg.CopyTo(0, s.clsid, IntPtr.Zero, stg_new);
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 with the message
Invalid Pointer error.
My only guesses are that somehow my Interface declaration
|
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. Please help.
Ram
|
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 designed to run under COM+.
This page works fine, unless I get fancy and hit my browser's refresh button
quickly, as a test. Then, what I see happen is the transactions pile up and
my ASP.Net "current requests" do the same. This happens even with two...
|
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 one day):
\\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During
Execution: 7
\\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
|
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 :
>************************************************************************
> <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _
> Public Function HelloWorld() As
> <System.Xml.Serialization.SoapElementAttribute("return")> String
| |
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. Do I just need to create a storage and set the
path of the file to that storage? Kind of confused with the msdn
documentation.
Can someone clarify. Thanks
|
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 across a problem I can't really explain:
When deleting an object from an IStorage, the space it used up will not
be freed, but rather marked as unused and overwritten the next time you
add an object to the storage.
This is obviously working as...
|
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 into 4 parts and am still having trouble uploading it. What am I doing wrong?
|
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 glitches in the massive, complex machines
they use to smash atoms.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |