Still trying to build a RichEdit Class. I want to insert a picture from a file (or from a database record).
I can do it, but the OLE Object is displayed as an icon and below it, the name of the file. When I double click on it, the corresponding application is properly launched.
My question is : I don’t want to display an OLE icon, but the content of the picture file. I used DVASPECT_CONTENT flag in REOBJECT, so I don’t understand why the content is not displayed.
The Delegates to access Interface Methods :
Private Delegate Function d_GetClientSite (pid as Ptr, Byref pClientSite as Ptr) As integer
Private Delegate Function d_InsertObject (pid as ptr, lpreobject As Ptr) As integer
Private Delegate Function d_GetUserClassID (pid as Ptr, ByRef Clsid as GUID) As integer
OLE Insertion Method :
[code]Sub InsertObjectFromFile(f as FolderItem)
Dim mIID_IOleObject As MemoryBlock = COM.IIDFromString("{00000112-0000-0000-C000-000000000046}")
Dim pIID_IOleObject as Ptr = mIID_IOleObject
Dim rc as integer
Declare Function SendMessageP Lib “User32” Alias “SendMessageW” _
( ByVal wnd as Integer, ByVal msg as Integer, ByVal wParam as Integer, lParam as Ptr) as Integer
Declare Sub OLEInitialize Lib “ole32” Alias “OleInitialize” ()
OLEInitialize
’ Get pointers to IRichEditOle interface and to Virtual Methods Table
dim poReo as Ptr
Const EM_GETOLEINTERFACE = WM_USER + 60
rc = SendMessageByrefPtr (me.handle, EM_GETOLEINTERFACE, 0, poReo)
Dim mREO as MemoryBlock = poReo
Dim pReoTable as Ptr = mREO.Ptr(0)
Dim mReoTable as MemoryBlock = pReoTable
’ Delegate Invoke of IRichEditOle Method “GetClientSite” (N° 3)
Dim d2 as New d_GetClientSite (mReoTable.ptr(4*3))
Dim pClientSite as Ptr
rc = d2.Invoke(poReo, pClientSite)
’ Get Storage
Dim lpStorage as Ptr
Declare Function StgCreateDocfile LIB “OLE32.DLL” ALIAS “StgCreateDocfile” _
(pwcsName As ptr, Byval grfMode As Integer, Byval reserved As Integer, Byref lpStorage as Ptr) As Integer
rc = StgCreateDocfile(nil, STGM_CREATE + STGM_READWRITE + STGM_DELETEONRELEASE + STGM_SHARE_EXCLUSIVE,0, lpStorage)
’ Get OLE Object
Dim pOleObj as Ptr
declare function OleCreateFromFile Lib “ole32” alias “OleCreateFromFile” _
(rclsid As integer, lpszFileName As WString, priid As Ptr, renderopt As Integer, rgFormatEtc As ptr, pClientSite As Ptr, pStorage As Ptr, Byref pOleObj As Ptr) as integer
rc = OleCreateFromFile (0, f.NativePath + chr(0), pIID_IOleObject, OLERENDER_DRAW, nil, pClientSite, lpStorage, pOleObj)
Declare Function OleSetContainedObject Lib “ole32.dll” (pUnknown As Ptr, fContained As Boolean) As Integer
rc = OleSetContainedObject (pOleObj, true)
’ Interface IOleObject, get class GUID (N° 15)
Dim mOO as MemoryBlock = pOleObj
Dim p3 as Ptr = mOO.Ptr(0)
Dim m3 as MemoryBlock = p3
Dim dOO as New d_GetUserClassID (m3.ptr(4*15))
Dim Clsid as GUID
rc = dOO.Invoke(pOleObj, Clsid)
Dim Reo as REOBJECT
Reo.cbStruct = Reo.Size
Reo.UUID = Clsid
Reo.dvAspect = DVASPECT_CONTENT
Reo.cp = 0 '(set the insert position)
Reo.dwFlags = REO_DYNAMICSIZE + REO_RESIZABLE
Reo.pStorage = lpStorage
Reo.pOleClientSite = pClientSite
Reo.pOleObject = pOleObj
’ Delegate Invoke of IRichEditOle Method “InsertObject” (N° 7)
dim mbes as New MemoryBlock(Reo.Size)
mbes.StringValue(0, Reo.Size) = Reo.StringValue(true)
Dim p As Ptr = mbes
Dim d3 as New d_InsertObject (mReoTable.ptr(4*7))
rc = d3.Invoke(poReo, p)
declare sub OleUninitialize lib “ole32.dll” alias “OleUninitialize”
OleUninitialize
End Sub[/code]
Other questions :
Are OLEInitialize and OleUninitialize necessary ?
Is OleSetContainedObject necessary ?