[ 求助 ]:c#中关于调用HttpQueryInfo的错误,崩溃了!

weishejay 2006-08-22 05:43:10
小菜这两天正编一个下载程序,用到了上述函数时怎么也弄不对。

这是函数定义:
public static extern bool HttpQueryInfo(IntPtr hRequest, int dwInfoLevel, [Out] byte[] lpvBuffer,ref int lpdwBufferLength,ref int lpdwIndex);

这是函数使用:
hqueryinfo=HttpQueryInfo(hquest,HTTP_QUERY_CONTENT_LENGTH ,lpvbuffer,ref lpdwBufferLength ,ref lpdwIndex);


好像是第三个参数的问题,然后就不明白了,请教高手。
...全文
332 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
weishejay 2006-08-23
  • 打赏
  • 举报
回复
那么请问lpszAcceptTypes 对应应该是ref byte[],在应用的时候,怎样表示可以接受任何类型 “*/*“?
Knight94 2006-08-23
  • 打赏
  • 举报
回复
dword: uint
weishejay 2006-08-23
  • 打赏
  • 举报
回复
多谢楼上,那么这个参数在使用的时候应该是long 还是 ref long?
还有前边一个参数lpAcceptTypes在c#中应该表示成什么类型呢?
万分感谢!
Knight94 2006-08-23
  • 打赏
  • 举报
回复
ref:
http://www.vkarlsen.no/lvk.net/doc/LVK.Interop.WinInet.HttpOpenRequest.html

others:
http://www.vkarlsen.no/lvk.net/doc/LVK.Interop.WinInet.html
dlzhangln 2006-08-23
  • 打赏
  • 举报
回复
顶了
weishejay 2006-08-23
  • 打赏
  • 举报
回复

这是我的函数定义:

[DllImport("wininet.dll", CharSet = CharSet.Auto)]

public static extern IntPtr HttpOpenRequest(IntPtr hConnect,string lpszVerb,

string lpszObjectName,string lpszVersion,string lpszReferer, [In]StringBuilder

lpszAcceptType,uint dwFlags,int dwContext);

这是我的函数使用:

URLFILE = HttpOpenRequest(hconnect, "GET", "/mp3/6897.mp3", "HTTP/1.1", null, filetype, INTERNET_FLAG_RELOAD, 0);

其中,StringBuider filetype = new StringBuiler( "*/*" );
const uint INTERNET_FLAG_RELOAD =0x80000000;

但是还是提示错误 :未处理accessviolationexception
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

拜托了。
Knight94 2006-08-23
  • 打赏
  • 举报
回复
to lpszAcceptTypes

LPCTSTR* lpszAcceptTypes:[In]StringBuilder lpszAcceptTypes

//Call
StringBuider strTypes = new StringBuiler( "*/*" );
Knight94 2006-08-23
  • 打赏
  • 举报
回复
to 那么请问lpszAcceptTypes 对应应该是ref byte[],在应用的时候,怎样表示可以接受任何类型 “*/*“?

BOOL HttpQueryInfo(
HINTERNET hRequest,
DWORD dwInfoLevel,
LPVOID lpvBuffer,
LPDWORD lpdwBufferLength,
LPDWORD lpdwIndex
);

c#:
[DllImport(...)]
public extend static bool HttpQueryInfo(
IntPtr hRequest,
uint dwInfoLevel,
[Out]byte[] lpvBuffer,
ref uint lpdwBufferLength,
ref uint lpdwIndex
);
weishejay 2006-08-23
  • 打赏
  • 举报
回复
渔翁兄还在否,能否解答一下
Knight94 2006-08-22
  • 打赏
  • 举报
回复
INTERNET_FLAG_RELOAD = 0x80000000
weishejay 2006-08-22
  • 打赏
  • 举报
回复
唉,一言难尽,老师要求用api,谁敢不听。
顺便请教一下,HttpOpenRequest函数中,如果dwFlags参数要用INTERNET_FLAG_RELOAD,这个参数应该等于多少?
Knight94 2006-08-22
  • 打赏
  • 举报
回复
Call api?
ref:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/httpqueryinfo.asp
http://www.pcvc.net/category/content.asp?sendid=276

In .net, you can use webclient class or socket class instead.
gezichong 2006-08-22
  • 打赏
  • 举报
回复
帮顶
csShooter 2006-08-22
  • 打赏
  • 举报
回复
为啥不用WebClint类呢

110,524

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧