Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

IInternetProtocol's Read method (pulling my hair out)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
biogates@yahoo.com - 13 Dec 2004 16:15 GMT
I'm writing a small app in C# and I managed to let the browser call my
IInternetProtocol's Start and Read methods.
Problem is: I can't pass the data back to IE.

I have tried various signatures for Read, including:

public int Read(
IntPtr pv,
int cb,
out IntPtr pcbRead
);

public int Read(
byte[] pv,
int cb,
out uint pcbRead
);

and all the combinations in between.
IE keeps saying "Action cancelled" or nothing at all (blank page).

Read returns 0 if further data is available, 1 if data is over, and
it's prepared to get further notifications after data is finished.

I can't really figure out how I should stuff data in pv and pcbRead, so
they result back in IE.
If someone can give out any clues, any help would be greatly
appreciated.

Mirco
Nicholas Paldino [.NET/C# MVP] - 13 Dec 2004 16:21 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.