aduadu

aduadu

0个粉丝

98

问答

0

专栏

45

资料

aduadu  发布于  2010-07-19 15:15:27
采纳率 0%
98个问答
4281

windows mobile下GPRS自动拨号

 
#define  GOOGLEWEBPAGE _T("/DevDivFile.xml")
#define STLOG_WRITE(a) MessageBox(NULL,a,NULL,0)
void DestroyConnection( HANDLE hConnect )
{
// If a connection exists, destroy it
if(NULL != hConnect )
{
ConnMgrReleaseConnection(hConnect, FALSE);
}
}

int CreateConnection( HANDLE *phConnection )
{
HRESULT            hResult;
//        HANDLE             phConnection;
DWORD              dwStatus;
DWORD              dwResult;

CONNMGR_DESTINATION_INFO cdi;
int i;

for(i = 0; SUCCEEDED(ConnMgrEnumDestinations(i, &cdi)); i++)
{
if (0 == wcscmp(cdi.szDescription, _T("WAP")))
break;
}

hResult = ConnMgrEnumDestinations(i, &cdi);
if (FAILED(hResult))
return FALSE;

CONNMGR_CONNECTIONINFO ConnInfo;
ZeroMemory( &ConnInfo, sizeof( ConnInfo ) );
ConnInfo.cbSize = sizeof( ConnInfo );
ConnInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
ConnInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
ConnInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP | CONNMGR_FLAG_PROXY_WAP | CONNMGR_FLAG_PROXY_SOCKS4 | CONNMGR_FLAG_PROXY_SOCKS5;
ConnInfo.bExclusive = FALSE;
ConnInfo.bDisabled = FALSE;
ConnInfo.guidDestNet = cdi.guid;

STLOG_WRITE(_T("ConnectToHttpServer\n") );


hResult = ConnMgrEstablishConnectionSync( &ConnInfo, phConnection, 60000, &dwStatus );
if ( hResult != S_OK )
{
STLOG_WRITE(_T("ConnMgrEstablishConnection is error\n") );
dwResult = GetLastError();
return S_FALSE;
}
else
{
// do something
}

return S_OK;
}

BOOL ConnectToHttpGetServer( LPCTSTR lpszServerName, LPCTSTR lpszObjectName )
{
BOOL   bResult;
DWORD  dwResult;
HANDLE hConnection;
DWORD  dwWritten;
LPTSTR szReadBuffer;
DWORD  dwNumberOfBytesRead;
int    nContentLength;
DWORD  dwTotalRead;

hConnection          = NULL;
bResult              = FALSE;
nContentLength       = 0;
dwNumberOfBytesRead  = 0;
dwTotalRead          = 0;
dwWritten            = 0;

if( CreateConnection( &hConnection ) != S_OK )
return FALSE;

HINTERNET hInternet  = InternetOpen( _T("DevDiv"), INTERNET_OPEN_TYPE_PROXY, _T("10.0.0.172"), NULL, 0);
if ( hInternet == NULL )
{
STLOG_WRITE(_T("InternetOpen is error\n") );
dwResult = GetLastError();
return bResult;
}

HINTERNET hInternetConnect = InternetConnect( hInternet, lpszServerName, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1 );
if ( hInternetConnect == NULL )
{
STLOG_WRITE(_T("InternetConnect is error\n") );
dwResult = GetLastError();
return bResult;
}

//TCHAR   szAccept[]   =   L"*/*";   //we   accept   everything...  
//LPTSTR  AcceptTypes[2]={0};   
//AcceptTypes[0]=szAccept;


HINTERNET hRequest = HttpOpenRequest(hInternetConnect,_T("GET"),lpszObjectName, L"HTTP/1.1",NULL,(LPCTSTR *)NULL,0,1);
if   (!hRequest)   
{   
dwResult = GetLastError();
STLOG_WRITE(_T("HttpOpenRequest is error\n") );
return bResult;
}

BOOL bSuccess = HttpSendRequest(hRequest, NULL, 0, NULL, 0 );
if ( !bSuccess )
{
STLOG_WRITE(_T("HttpSendRequestEx is error\n") );
dwResult = GetLastError();  
return bResult;
}


TCHAR szHeader[ 1000 ];
ZeroMemory( szHeader, sizeof( szHeader ) );
DWORD dwHeaderLength = sizeof( szHeader );
// HTTP_QUERY_RAW_HEADERS
BOOL bQuery=HttpQueryInfo(hRequest, HTTP_QUERY_CONTENT_LENGTH, szHeader, &dwHeaderLength, NULL);
if ( !bQuery )
{
STLOG_WRITE(_T("HttpQueryInfo is error\n") );
dwResult = GetLastError();
return bResult;
}

nContentLength = _wtoi( szHeader );

HANDLE        hFile = CreateFile( GOOGLEWEBPAGE, GENERIC_READ|GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
if ( hFile == INVALID_HANDLE_VALUE )
{        
dwResult = GetLastError();
return bResult;
}

szReadBuffer = (LPTSTR) malloc( 1024 );
ZeroMemory(szReadBuffer, 1024 );

while( TRUE )
{
bResult = InternetReadFile(hRequest, szReadBuffer, 1024, &dwNumberOfBytesRead);
if ( bResult )
{
if ( dwTotalRead == nContentLength && dwNumberOfBytesRead == 0 )
{
bResult = TRUE;
break;

}
else
{
SetFilePointer ( hFile, 0, NULL, FILE_END );
WriteFile( hFile,(LPBYTE)szReadBuffer, dwNumberOfBytesRead, &dwWritten, NULL );
dwTotalRead = dwTotalRead + dwNumberOfBytesRead;
}
}
else
{
bResult = FALSE;
break;
}
}

CloseHandle(hFile);
free(szReadBuffer);

InternetCloseHandle( hInternetConnect );
InternetCloseHandle( hInternet );
DestroyConnection( hConnection );
STLOG_WRITE(_T("\n") );
return bResult;
}
fromwww.devdiv.net
我来回答
回答0个
时间排序
认可量排序
易百纳技术社区暂无数据
或将文件直接拖到这里
悬赏:
E币
网盘
* 网盘链接:
* 提取码:
悬赏:
E币

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
+ 添加网盘链接/附件

Markdown 语法

  • 加粗**内容**
  • 斜体*内容*
  • 删除线~~内容~~
  • 引用> 引用内容
  • 代码`代码`
  • 代码块```编程语言↵代码```
  • 链接[链接标题](url)
  • 无序列表- 内容
  • 有序列表1. 内容
  • 缩进内容
  • 图片![alt](url)
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

易百纳技术社区