- 요약
AfxParseURL()을 이용하여 URL을 파싱할 수 있다. - 본문
AfxParseURL()은 URL을 파싱하기위한 MFC 함수입니다. 사용법은 AfxParseURL의 인자로 URL의 문자열을 입력하면 서버와 프로토콜과 포트를 파싱해서 넘겨줍니다.BOOL AFXAPI AfxParseURL( LPCTSTR pstrURL, DWORD& dwServiceType, CString& strServer, CString& strObject, INTERNET_PORT& nPort );
여기까지만 하면 너무 허전하죠… 그래서 MFC를 쓰지않는 프로그램에서는 이런 기능을 구현하기 위해 MFC소스를 분석해 보겠습니다.
BOOL AFXAPI AfxParseURL(LPCTSTR pstrURL, DWORD& dwServiceType, CString& strServer, CString& strObject, INTERNET_PORT& nPort) { dwServiceType = AFX_INET_SERVICE_UNK; ASSERT(pstrURL != NULL); if (pstrURL == NULL) return FALSE; URL_COMPONENTS urlComponents; memset(&urlComponents, 0, sizeof(URL_COMPONENTS)); urlComponents.dwStructSize = sizeof(URL_COMPONENTS); urlComponents.dwHostNameLength = INTERNET_MAX_URL_LENGTH; urlComponents.lpszHostName = strServer.GetBuffer(INTERNET_MAX_URL_LENGTH+1); /* ④ */ urlComponents.dwUrlPathLength = INTERNET_MAX_URL_LENGTH; urlComponents.lpszUrlPath =