Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open non compund file in IStorage

Status
Not open for further replies.

tacbse2001

IS-IT--Management
Jan 12, 2005
2
US
Hi,
I have succeeded in opening a non compound file into IStorage. But unlike the compound files, my file does not have a CLASSID assigned to it. I am trying to load the Stream from the file into a IPersistStream but I get the error that the CLASS IS NOT REGISTERED. This is becoz the file, Storage and Stream none have a CLASSID assigned to them. How are non compound files handled for this. Is a class id explicitly supposed to be assigned if so what is the value and how is it done. Im a newbie to this so please explain steps. Thanks in advance.
 
Using IStorage/IStream doesn't make sense if it isn't a compound file (aka structured storage) aka you're working with.

Or am I stupidely missing something?


/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Well, I have a VC++ Parser available that I need to modify and use. It is reading only structured files to parse. Now the applications that will be writing these files may not necessarily be structured files. I have loaded a non compound file into IStorage successfully and I have access to the Stream as well..The only trouble im having is with CLASS IDs as stated above I can post my code too to explain more. But I wanted to know that since regular files also exist why is it so rare to open them as structured files? Or is an application working with structured files only supposed to open files that it has written?
 
Ahh, ok. I've been into that territory, ie treating regular files and streams in a SSF (structured storage file) similary.

My solution was to make a generic file interface that's derived into 2 classes one accessing regular files (simply by using CFile) and one accessing streams in a SSF.

Rougly something like this:
Code:
// Generic file interface
class FileI
{
public:
  static std::auto_ptr<FileI> create(LPCTSTR fileName);

  virtual void read(void* data, unsigned int len) = 0;
  virtual void open(Mode mode /* read|write|etc...*/)=0;
  // etc ...
};

class RegularFile : public FileI
{
  // Implement and override the various virtuals
  // ...
private:
  CFile mFile;
};

class CompoundStream : public FileI
{
  // Implement and override the various virtuals
  // ...
};

// Usage
{
  // ...
  std::auto_ptr<FileI> file = FileI::create(someName);
  // Don't care/know what type of file it really is.
  file->open(FileI::read);
  file->read(someBuffer, bufLen);
  file->close();
  // ...
}

The key to it all was the static create function, where a filename like
"C:\SomeFolder\someFile.txt"
would return a RegularFile associated with someFile.txt and a filename like
"C:\SomeFolder\someFile.dat>SomeStorage>SomeStream.txt"
would return a CompoundStream associated with the SomeStream.txt of the SSF someFile.dat.

The '>' char was used to determine how it should be treated ('>' is not allowed in regular filenams)

Reason for auto_ptr: So that create can return something new:ed without caller having to explicitly delete.

>since regular files also exist why is it so rare to open them as structured files?

Because they are infact not structured storage files?

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top