Hello everyone,
I've been implementing the IRichEditOleCallback interface as a class and
setting this in my rich edit control's CreateRichEditOleCallback protected
method. The interface definition I'm using is as follows - only the
relevant member is listed for brevity:

 <ComImport(), CLSCompliant(False), Guid("0000000b-0000-0000-C000-
000000000046"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
    Friend Interface IStorage
        <PreserveSig()> Function CreateStream Etc
        <PreserveSig()> Function OpenStream Etc
        <PreserveSig()> Function CreateStorage(<MarshalAs
(UnmanagedType.LPWStr)> ByVal pwcsName As String, ByVal grfMode As Stgm,
ByVal reserved1 As UInteger, ByVal reserved2 As UInteger, <Out(), MarshalAs
(UnmanagedType.Interface)> ByRef ppStg As IStorage) As Integer
        Etc
    End Interface

In my IRichEditOleCallback callback object I have the following:

Private 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 UInt32, ByVal
pStgOptions As IntPtr, ByVal reserved As IntPtr, <InAttribute()> ByRef
riid As Guid, ByRef ppObjectOpen As Object) As Integer

This object uses the above to create a file-based storage for use by the
COM objects within the richtextbox:

''' <summary> Creates a temporary storage file for storing COM objects
embedded within this control instance. </summary>
        Friend Function Storage() As IStorage
            Dim pResult As Integer = 0
            Dim pStorageObject As Object = Nothing
            Dim pIID_IStorage As Guid = New Guid("0000000b-0000-0000-C000-
000000000046")
            If mStorage Is Nothing Then
                Try
                    ' Create and open a new compound file storage object
using a temporarily created file.
                    pResult = StgCreateStorageEx("C:\TestStorage",
Stgm.STGM_Create Or Stgm.STGM_ShareExclusive Or Stgm.STGM_ReadWrite,
StgFmt.STGFMT_Storage, 0, IntPtr.Zero, IntPtr.Zero, pIID_IStorage,
pStorageObject)
                    If (pResult <> S_OK) OrElse (pStorageObject Is
Nothing) Then
                        Throw New Win32Exception("Unable to create
compound file storage object.")
                    Else
                        mStorage = CType(pStorageObject, IStorage)
                    End If
                Finally
                    If pStorageObject IsNot Nothing Then
                        Marshal.ReleaseComObject(pStorageObject)
                    End If
                End Try
            End If
            Return mStorage
        End Function

Then within the GetNewStorage member of the IRichEditOleCallback interface
I planned on returning a suitably named sub storage within this storage
file as follows - here mParent refers to the parent RichTextBox control
and RichEditOle refers to its IRichEditOle interface which I've
successfully wrapped:
Private Function GetNewStorage(ByRef lplpstg As IStorage) As Integer
Implements IRichEditOleCallback.GetNewStorage
            Trace.WriteLine("GetNewStorage")
            Dim pResult As Integer = Storage.CreateStorage("Object" &
mParent.RichEditOle.GetObjectCount, Stgm.STGM_Create Or
Stgm.STGM_ReadWrite Or Stgm.STGM_ShareExclusive, 0, 0, lplpstg)
            Return pResult
        End Function

The call to StgCreateStorageEx works correctly and a storage file is
created under C:\TestStorage. The problem occurs with how to get the
interface pointer returned via the ppObjectOpen parameter. According to
the platform SDK this parameter is defined as:

void** ppObjectOpen
[out] A pointer to an interface pointer variable that receives a pointer
for an interface on the new storage object (sounds like an Abbott and
Costello movie); contains NULL if operation failed.

Because it has two levels of indirection, I defined it as a reference
object passed by reference.

Note that the remainder of the IRichEditOleCallback class appears to work
correctly, eg for example I can drag and drop one part of the control's
contents to another point within the control, also events defined within
each interface member are raised within the parent richtextbox control
when they should be. I just cannot get the GetNewStorage member working -
this is the most critical member of this interface. Without it, when I
open a file containing say embedded images then the images will not be
displayed at all.

So my question is - How do I get to the IStorage pointer returned by
StgCreateStorageEx?

Any help is much appreciated.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to