Gurus, can you please take a peek at my IOleItemContainer wrapper?

R

Robin Tucker

I'm trying to implement an IOleItemContainer wrapper and have written the
following (below) code to do it. Sometimes I get confused about my byval's
and byref's however. Anyway, the method I am trying to call ( GetObject)
fails with a "A null reference pointer was passed to the stub." message. I
am calling the method like this (any ideas? Probably my interface
definition is totaly fubar...).

Dim theOleItemContainer As COM.IOleItemContainer
Dim theBindCtx As COM.IBindCtx
Dim theDataObject As IDataObject
Dim theGuid As New Guid
Dim hResult As Integer

' CreateBindCtx is imported from ole32.dll
hResult = COM.BindContext.CreateBindCtx(0, theBindCtx)

' "theFile" is the path to an object that supportes IOleItemContainer and
IDataObject
theOleItemContainer = CType(GetObject(theFile), COM.IOleItemContainer)

' Fails with hResult "A null reference pointer was passed to the stub"

hResult = theOleItemContainer.GetObject("Visual Image", _

COM.BINDSPEED.BINDSPEED_IMMEDIATE, _

theBindCtx, _
New
Guid("0000010E-0000-0000-C000-000000000046"), _ ' IDataObject

theDataObject)

' /////////////////////////////////////////////////////////////////////////
' // IOleItemContainer
' /////////////////////////////////////////////////////////////////////////

<ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("0000011C-0000-0000-C000-000000000046")> _
Public Interface IOleItemContainer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function ParseDisplayName(ByRef pbc As IBindCtx,
<MarshalAs(UnmanagedType.LPWStr)> ByRef pszDisplayName As String, ByRef
pchEaten As Integer, ByRef ppmkOut As IMoniker) As Integer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function EnumObjects(ByVal grfFlags As Integer, ByRef ppenum As
IEnumUnknown) As Integer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function LockContainer(ByVal fLock As Integer) As Integer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function GetObject(<MarshalAs(UnmanagedType.LPWStr)> ByRef pszItem As
String, ByVal dwSpaceNeeded As Integer, ByRef pbc As IBindCtx, ByVal
riid As Guid, ByRef ppvObject As IntPtr) As Integer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function GetObjectStorage(<MarshalAs(UnmanagedType.LPWStr)> ByVal
pszItem As String, ByRef pbc As IBindCtx, ByVal riid As Guid, ByRef
ppvStorage As IntPtr) As Integer

'
/////////////////////////////////////////////////////////////////////////
<PreserveSig()> _
Function IsRunning(<MarshalAs(UnmanagedType.LPStr)> ByVal pszItem As
String) As Integer
End Interface
 
M

Mattias Sjögren

Robin,
Dim theDataObject As IDataObject ....
hResult = theOleItemContainer.GetObject("Visual Image", _

COM.BINDSPEED.BINDSPEED_IMMEDIATE, _

theBindCtx, _
New
Guid("0000010E-0000-0000-C000-000000000046"), _ ' IDataObject

theDataObject) ....
<PreserveSig()> _
Function GetObject(<MarshalAs(UnmanagedType.LPWStr)> ByRef pszItem As
String, ByVal dwSpaceNeeded As Integer, ByRef pbc As IBindCtx, ByVal
riid As Guid, ByRef ppvObject As IntPtr) As Integer


Does this even compile? Passing a variable of type IDataObject to the
last parameter which is an IntPtr shouldn't work.

Anyway, I think this signature should work better

<PreserveSig()> _
Function GetObject(<MarshalAs(UnmanagedType.LPWStr)> ByVal pszItem As
String, ByVal dwSpaceNeeded As Integer, ByVal pbc As IBindCtx, ByRef
riid As Guid, ByRef ppvObject As IntPtr) As Integer

or

...., ByRef ppvObject As IDataObject) As Integer

if that's more convenient.



Mattias
 
R

Robin Tucker

You genius. It worked fine.

Thankyou.

Mattias Sjögren said:
Robin,



Does this even compile? Passing a variable of type IDataObject to the
last parameter which is an IntPtr shouldn't work.

Anyway, I think this signature should work better

<PreserveSig()> _
Function GetObject(<MarshalAs(UnmanagedType.LPWStr)> ByVal pszItem As
String, ByVal dwSpaceNeeded As Integer, ByVal pbc As IBindCtx, ByRef
riid As Guid, ByRef ppvObject As IntPtr) As Integer

or

..., ByRef ppvObject As IDataObject) As Integer

if that's more convenient.



Mattias
 

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