Анализирует строку URL возвращая информацию о ней:
BOOL AFXAPI AfxParseURL ( LPCTSTR pstrURL, // URL DWORD& dwServiceType, // тип сервиса CString& strServer, // сервер CString& strObject, // объект INTERNET_PORT& nPort // порт );
В случае успеха функция вернет ненулевое значение. Типы сервера бывают такие:
AFX_INET_SERVICE_FTP AFX_INET_SERVICE_HTTP AFX_INET_SERVICE_HTTPS AFX_INET_SERVICE_GOPHER AFX_INET_SERVICE_FILE AFX_INET_SERVICE_MAILTO AFX_INET_SERVICE_NEWS AFX_INET_SERVICE_NNTP AFX_INET_SERVICE_TELNET AFX_INET_SERVICE_WAIS AFX_INET_SERVICE_MID AFX_INET_SERVICE_CID AFX_INET_SERVICE_PROSPERO AFX_INET_SERVICE_AFS AFX_INET_SERVICE_UNK
Пример консольного приложения на основе MFC:
// TestUrl.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "TestUrl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif /////////////////////////////////////// // The one and only application object #include "afxinet.h" CWinApp theApp; using namespace std; void Parse(); int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { // TODO: code your application's behavior here CString strHello; strHello.LoadString(IDS_HELLO); cout << (LPCTSTR)strHello << endl; Parse(); } return nRetCode; } void Parse() { DWORD type; CString strServer; CString strObject; INTERNET_PORT np; CString URL="http://www.firststeps.ru/default.htm"; if (AfxParseURL(URL,type,strServer,strObject,np)!=0) { CString result; result="Server - "+strServer+ " Object - " + strObject; AfxMessageBox(result ); } }
А вот и результат: