Mirco,
Part of the problem is the interface definition. There are two things
you need to do. The first is to use the PreserveSig attribute, so that it
will take the return value as an HRESULT. Your method (on the interface)
should look like this:
[PreserveSig]
[return:MarshalAs(UnmanagedType.Error)]
int Read(
IntPtr pv,
[MarshalAs(UnmanagedType.U4)] cb,
[MarshalAs(UnmanagedType.U4)] ref pcbRead);
Notice the ref on the last parameter as well. This should work once you
define it this way.
Hope this helps.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
> I'm writing a small app in C# and I managed to let the browser call my
> IInternetProtocol's Start and Read methods.
[quoted text clipped - 26 lines]
>
> Mirco
biogates@yahoo.com - 14 Dec 2004 12:08 GMT
Nicholas,
Thank you for replying to my post.
Indeed I think that was part of the problem, I followed your advice,
but still no luck with passing data back to IE.
I suspect there's a problem in the way I handle IntPtr and byte[].
Can you find something wrong with something even as simple as this?
public int Read(
IntPtr pv,
uint cb,
ref uint pcbRead
)
{
...
string str = "This is a silly attempt";
for (int k = 0; k < str.Length; k++)
{
((byte *)pv.ToPointer())[k] = (byte)(str[k]);
}
}
Thanks,
Mirco
> Mirco,
>
[quoted text clipped - 49 lines]
> >
> > Mirco