ILockbytes ReadAt Function

  • Thread starter Thread starter Christian Sebler
  • Start date Start date
C

Christian Sebler

Hello
I have this Problem.
I implements the Interface ILockbytes (IStorage).
Take a look:

Public Function GetData(ByVal inILockBytes As ILockBytes)
Try
Dim statss As System.Runtime.InteropServices.STATSTG
inILockBytes.Stat(statss, 0)

!!This Works fine!!
Debug.WriteLine(statss.pwcsName)

!!This Works too!!
Debug.WriteLine(statss.cbSize.ToString)

!!This Works too!!
Debug.WriteLine(statss.type.ToString)

Dim sizee As Int32 = statss.cbSize

Dim nybytes As Byte() = New Byte(sizee) {}

Dim newptr As IntPtr = Marshal.AllocCoTaskMem(sizee)

!!This fails!!
reads = inILockBytes.ReadAt(0, newptr, sizee)

Marshal.Copy(newptr, nybytes, 0, sizee)

Marshal.FreeCoTaskMem(newptr)
....................

Have anywhere an Solution or an Sample or something else?

Christian
 
Christian,
!!This fails!!
reads = inILockBytes.ReadAt(0, newptr, sizee)

How does it fail? Do you get an exception, and if so what HRESULT does
it have? If you don't get an exception, what's the value of reads
after the call?



Mattias
 
Sorry no response.

It crash only. I think there is no response because it is
inILockBytes.ReadAt is unmanage code.

Sometime I get this Message:

System.NullReferenceException: The Objectref is not linked to
Objectinstance.

at System.Runtime.InteropServices.Marshal.CopyBytesToManaged(Int32 source,
Byte[] destination, Int32 startIndex, Int32 length)

at System.Runtime.InteropServices.Marshal.Copy(IntPtr source, Byte[]
destination, Int32 startIndex, Int32 length)

Thanks

Christian
 
Christian,

Did you declare the ILockBytes interface yourself? If so, can you post
the declaration?



Mattias
 
Back
Top