Structured Storage using VB.Net

D

Dave

Has anyone out there managed to create a structured storage file using pure
VB.Net? Specifically; with the API function StgCreateStorageEx? If so,
could you post a working example here please. One that can be pasted into a
VB.Net project and run.

Thanks
Dave
 
H

Herfried K. Wagner [MVP]

* "Dave said:
Has anyone out there managed to create a structured storage file using pure
VB.Net? Specifically; with the API function StgCreateStorageEx? If so,
could you post a working example here please. One that can be pasted into a
VB.Net project and run.

You will find some information on how to use this function with .NET
here (there is no VB.NET sample, but maybe the code will give you an
idea on how to implement that in VB.NET or in an MC++ or C# component):

<http://groups.google.com/groups?ie=UTF-8&q=group:*dotnet*+StgCreateStorageEx>
 
D

Dave

Thank you Herfried

I'm sure its possible to successfully call the function in C# or C++ in the
Net environment. What I'm not sure of is, if its even possible using VB7. In
VB7 the function always returns a STG_E_INVALIDPOINTER error no matter how
its definition is set up. That means the function is being called ok but
that it doesn't like what its been passed as arguments.

Dave
 
H

Herfried K. Wagner [MVP]

* "Dave said:
I'm sure its possible to successfully call the function in C# or C++ in the
Net environment. What I'm not sure of is, if its even possible using VB7. In
VB7 the function always returns a STG_E_INVALIDPOINTER error no matter how
its definition is set up. That means the function is being called ok but
that it doesn't like what its been passed as arguments.

Which declaration do you use? Maybe it's simpler to implement the
functionality in a MC++ or C# component that can be used by the VB.NET
application (if you are using VS.NET Professional or better).
 
J

Jay B. Harlow [MVP - Outlook]

Herfried,
Dave posted his declaration yesterday in a long thread him & I had titled
"Pointer to a Pointer in VB".

He had some minor issues in his declaration that I pointed out, however
there is something else wrong that I did not immediately identify.

I suggested he waits until Monday and get help in the
microsoft.public.dotnet.framework.interop newsgroup as that is where the
people best able to help him hang out, and Monday he will have a better
chance of getting more experts on line.

I also referred him to Adam Nathan's book ".NET and COM - The Complete
Interoperability Guide" from SAMS press. As it actually has the definitions
printed in it, albeit in C#. However the book does have a chapter or to on
how to define the functions in both C# & VB.NET so converting the
definitions back & forth should be "easy".

Hope this helps
Jay
 
H

Herfried K. Wagner [MVP]

* "Jay B. Harlow said:
Dave posted his declaration yesterday in a long thread him & I had titled
"Pointer to a Pointer in VB".

Thank you for the information. I didn't follow this thread...
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
It seems to me that it needs to stand "down the hall" in the
microsoft.public.dotnet.framework.interop newsgroup, however I realize you
don't feel that way.

Good luck

Jay
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
I got the following StgCreateStorageEx to work, which is based on the one of
your earlier posts.

#Region " Structured Storage definitions "

' Storage instantiation modes
Public Enum STGM As Integer
DIRECT = &H0L
TRANSACTED = &H10000L
SIMPLE = &H8000000L

READ = &H0L
WRITE = &H1L
READWRITE = &H2L

SHARE_DENY_NONE = &H40L
SHARE_DENY_READ = &H30L
SHARE_DENY_WRITE = &H20L
SHARE_EXCLUSIVE = &H10L

PRIORITY = &H40000L
DELETEONRELEASE = &H4000000L
NOSCRATCH = &H100000L

CREATE = &H1000L
CONVERT = &H20000L
FAILIFTHERE = &H0L

NOSNAPSHOT = &H200000L
DIRECT_SWMR = &H400000L

End Enum

Public Enum STGFMT As Integer
STORAGE = 0
NATIVE = 1
FILE = 3
ANY = 4
DOCFILE = 5
End Enum

<PreserveSig()> _
Declare Auto Function StgCreateStorageEx Lib "ole32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pwcsName As String, _
ByVal grfMode As STGM, _
ByVal stgfmt As STGFMT, _
ByVal grfAttrs As Int32, _
ByVal pStgOptions As IntPtr, _
ByVal reserved As IntPtr, _
<[In]()> ByRef riid As Guid, _
<MarshalAs(UnmanagedType.IUnknown)> ByRef ppObjectOpen As Object) As
Integer

#End Region

Public Shared Sub Main()
Dim IID_IPropertySetStorage As New
Guid("0000013A-0000-0000-C000-000000000046")

Dim hr As Integer
Dim pPropSetStg As Object
hr = StgCreateStorageEx("WriteRead.stg", _
STGM.CREATE Or STGM.SHARE_EXCLUSIVE Or
STGM.READWRITE, _
STGFMT.STORAGE, _
0, IntPtr.Zero, IntPtr.Zero, _
IID_IPropertySetStorage, _
pPropSetStg)

End Sub

Notice that I changed pStgOptions to be an IntPtr and pass IntPtr.Zero
(effectively making it a C++ NULL). I do not have a working sample using an
actual STGOPTIONS structure.

To actually use pPropSetStg you will need to have the IStorage interface
properly defined and cast the pPropSetStg variable to a variable of
IStorage.

Hope this helps
Jay
 
D

Dave

Jay

You have indeed come up with the solution. Or at least 90-95% of it anyway.
I modified my code using your suggestion and the call did in fact result in
the creation of a Structured Storage file (with a root storage) in it.

The only fly in the ointment is that even though the call worked the
pPropSetStg paramater remains as Null. This should be expected though as the
code is responsible for setting this 'pointer' to something, while the API
builds the IStructure.

I will work this some more.

As an aside, there is a message in Interop called "How To: Port HRESULT
GetCurrentSample( [out,retval] IMediaSample ** ppSample );" which is related
to this ** pointer business.

Dave

PS: I will send you an email. All is forgiven.
_________________________________________



Jay B. Harlow said:
Dave,
I got the following StgCreateStorageEx to work, which is based on the one of
your earlier posts.

#Region " Structured Storage definitions "

' Storage instantiation modes
Public Enum STGM As Integer
DIRECT = &H0L
TRANSACTED = &H10000L
SIMPLE = &H8000000L

READ = &H0L
WRITE = &H1L
READWRITE = &H2L

SHARE_DENY_NONE = &H40L
SHARE_DENY_READ = &H30L
SHARE_DENY_WRITE = &H20L
SHARE_EXCLUSIVE = &H10L

PRIORITY = &H40000L
DELETEONRELEASE = &H4000000L
NOSCRATCH = &H100000L

CREATE = &H1000L
CONVERT = &H20000L
FAILIFTHERE = &H0L

NOSNAPSHOT = &H200000L
DIRECT_SWMR = &H400000L

End Enum

Public Enum STGFMT As Integer
STORAGE = 0
NATIVE = 1
FILE = 3
ANY = 4
DOCFILE = 5
End Enum

<PreserveSig()> _
Declare Auto Function StgCreateStorageEx Lib "ole32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pwcsName As String, _
ByVal grfMode As STGM, _
ByVal stgfmt As STGFMT, _
ByVal grfAttrs As Int32, _
ByVal pStgOptions As IntPtr, _
ByVal reserved As IntPtr, _
<[In]()> ByRef riid As Guid, _
<MarshalAs(UnmanagedType.IUnknown)> ByRef ppObjectOpen As Object) As
Integer

#End Region

Public Shared Sub Main()
Dim IID_IPropertySetStorage As New
Guid("0000013A-0000-0000-C000-000000000046")

Dim hr As Integer
Dim pPropSetStg As Object
hr = StgCreateStorageEx("WriteRead.stg", _
STGM.CREATE Or STGM.SHARE_EXCLUSIVE Or
STGM.READWRITE, _
STGFMT.STORAGE, _
0, IntPtr.Zero, IntPtr.Zero, _
IID_IPropertySetStorage, _
pPropSetStg)

End Sub

Notice that I changed pStgOptions to be an IntPtr and pass IntPtr.Zero
(effectively making it a C++ NULL). I do not have a working sample using an
actual STGOPTIONS structure.

To actually use pPropSetStg you will need to have the IStorage interface
properly defined and cast the pPropSetStg variable to a variable of
IStorage.

Hope this helps
Jay

Dave said:
Has anyone out there managed to create a structured storage file using pure
VB.Net? Specifically; with the API function StgCreateStorageEx? If so,
could you post a working example here please. One that can be pasted
into
a
VB.Net project and run.

Thanks
Dave
 
J

Jay B. Harlow [MVP - Outlook]

Dave,
If you need the pStgOptions structure I would probably overload the Declare.
One takes the Intptr and one takes the pStgOptions structure. As the
pStgOptions is only needed if you are using STGFMT_DOCFILE (see win32 API
for full info).

Hope this helps
Jay

Dave said:
Jay

You have indeed come up with the solution. Or at least 90-95% of it anyway.
I modified my code using your suggestion and the call did in fact result in
the creation of a Structured Storage file (with a root storage) in it.

The only fly in the ointment is that even though the call worked the
pPropSetStg paramater remains as Null. This should be expected though as the
code is responsible for setting this 'pointer' to something, while the API
builds the IStructure.

I will work this some more.

As an aside, there is a message in Interop called "How To: Port HRESULT
GetCurrentSample( [out,retval] IMediaSample ** ppSample );" which is related
to this ** pointer business.

Dave

PS: I will send you an email. All is forgiven.
_________________________________________



Dave,
I got the following StgCreateStorageEx to work, which is based on the
one
of
your earlier posts.

#Region " Structured Storage definitions "

' Storage instantiation modes
Public Enum STGM As Integer
DIRECT = &H0L
TRANSACTED = &H10000L
SIMPLE = &H8000000L

READ = &H0L
WRITE = &H1L
READWRITE = &H2L

SHARE_DENY_NONE = &H40L
SHARE_DENY_READ = &H30L
SHARE_DENY_WRITE = &H20L
SHARE_EXCLUSIVE = &H10L

PRIORITY = &H40000L
DELETEONRELEASE = &H4000000L
NOSCRATCH = &H100000L

CREATE = &H1000L
CONVERT = &H20000L
FAILIFTHERE = &H0L

NOSNAPSHOT = &H200000L
DIRECT_SWMR = &H400000L

End Enum

Public Enum STGFMT As Integer
STORAGE = 0
NATIVE = 1
FILE = 3
ANY = 4
DOCFILE = 5
End Enum

<PreserveSig()> _
Declare Auto Function StgCreateStorageEx Lib "ole32.dll" ( _
<MarshalAs(UnmanagedType.LPWStr)> ByVal pwcsName As String, _
ByVal grfMode As STGM, _
ByVal stgfmt As STGFMT, _
ByVal grfAttrs As Int32, _
ByVal pStgOptions As IntPtr, _
ByVal reserved As IntPtr, _
<[In]()> ByRef riid As Guid, _
<MarshalAs(UnmanagedType.IUnknown)> ByRef ppObjectOpen As
Object)
As
Integer

#End Region

Public Shared Sub Main()
Dim IID_IPropertySetStorage As New
Guid("0000013A-0000-0000-C000-000000000046")

Dim hr As Integer
Dim pPropSetStg As Object
hr = StgCreateStorageEx("WriteRead.stg", _
STGM.CREATE Or STGM.SHARE_EXCLUSIVE Or
STGM.READWRITE, _
STGFMT.STORAGE, _
0, IntPtr.Zero, IntPtr.Zero, _
IID_IPropertySetStorage, _
pPropSetStg)

End Sub

Notice that I changed pStgOptions to be an IntPtr and pass IntPtr.Zero
(effectively making it a C++ NULL). I do not have a working sample using an
actual STGOPTIONS structure.

To actually use pPropSetStg you will need to have the IStorage interface
properly defined and cast the pPropSetStg variable to a variable of
IStorage.

Hope this helps
Jay

into
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top