By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

Structured Storage using VB.Net

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
* "Dave" <ww*@com.com> scripsit:
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%3A*dotnet*+StgCreateStorageEx>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2

P: n/a
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
Nov 20 '05 #3

P: n/a
* "Dave" <ww*@com.com> scripsit:
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).

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
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

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oa*************@TK2MSFTNGP11.phx.gbl...
* "Dave" <ww*@com.com> scripsit:
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).

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #5

P: n/a
* "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> scripsit:
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...

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
The original question still stands.
Nov 20 '05 #7

P: n/a
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

"Dave" <ww*@com.com> wrote in message
news:iK******************@twister01.bloor.is.net.c able.rogers.com...
The original question still stands.

Nov 20 '05 #8

P: n/a
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" <ww*@com.com> wrote in message
news:Ce*******************@news01.bloor.is.net.cab le.rogers.com...
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

Nov 20 '05 #9

P: n/a
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 [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:ul****************@TK2MSFTNGP10.phx.gbl...
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" <ww*@com.com> wrote in message
news:Ce*******************@news01.bloor.is.net.cab le.rogers.com...
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


Nov 20 '05 #10

P: n/a
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" <ww*@com.com> wrote in message
news:8x*******************@news01.bloor.is.net.cab le.rogers.com...
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 [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:ul****************@TK2MSFTNGP10.phx.gbl...
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" <ww*@com.com> wrote in message
news:Ce*******************@news01.bloor.is.net.cab le.rogers.com...
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



Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.