Compound file access

  • Thread starter Thread starter Todd Webb
  • Start date Start date
T

Todd Webb

I would like to talk to the COM implementation of
Structured Storage from C#. I would like a C# equivalent
of StgCreateStorageEx.

I expected to find support in the stdole Primary Interop
Assembly, but I have not been able to find it.
 
Todd,

You will have to declare StgCreateStorageEx yourself, and use COM
interop to declare the interfaces you need. The declaration of
StgCreateStorageEx is as follows:

[DllImport("ole32.dll")]
public static extern int StgCreateStorageEx(
[MarshalAs(UnmanagedType.LPWStr)]
string pwcsName,
[MarshalAs(UnmanagedType.U4)]
int grfMode,
int stgfmt,
[MarshalAs(UnmanagedType.U4)]
int grfAttrs,
IntPtr pStgOptions,
IntPtr reserved2,
ref Guid riid,
[MarshalAs(UnmanagedType.Interface)]
ref Object ppObjectOpen);

You will have to marshal the pStgOptions parameter yourself, as it can
accept null.

Hope this helps.
 
Todd,

I've had the same problem, and a colleague helped me get to the same
solution that Nicholas has given. Before your message appeared on the list
today, I posted a similar note, asking why this subject hasn't been
addressed by the C# staff, since the file format itself is used internally
by almost all the current Microsoft products. You might check out the
thread 'OLE Structured Storage' to see if there's any meaningful reply.
Nicholas Paldino said:
Todd,

You will have to declare StgCreateStorageEx yourself, and use COM
interop to declare the interfaces you need. The declaration of
StgCreateStorageEx is as follows:

[DllImport("ole32.dll")]
public static extern int StgCreateStorageEx(
[MarshalAs(UnmanagedType.LPWStr)]
string pwcsName,
[MarshalAs(UnmanagedType.U4)]
int grfMode,
int stgfmt,
[MarshalAs(UnmanagedType.U4)]
int grfAttrs,
IntPtr pStgOptions,
IntPtr reserved2,
ref Guid riid,
[MarshalAs(UnmanagedType.Interface)]
ref Object ppObjectOpen);

You will have to marshal the pStgOptions parameter yourself, as it can
accept null.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Todd Webb said:
I would like to talk to the COM implementation of
Structured Storage from C#. I would like a C# equivalent
of StgCreateStorageEx.

I expected to find support in the stdole Primary Interop
Assembly, but I have not been able to find it.
 
Back
Top