Click here to Skip to main content
15,886,774 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Listbox and display bitmaps Pin
ibtt115-Mar-07 10:36
ibtt115-Mar-07 10:36 
QuestionLVN_ITEMCHANGED and LVS_OWNERDATA issues Pin
Jim Crafton12-Mar-07 10:31
Jim Crafton12-Mar-07 10:31 
AnswerRe: LVN_ITEMCHANGED and LVS_OWNERDATA issues Pin
Ravi Bhavnani12-Mar-07 10:55
professionalRavi Bhavnani12-Mar-07 10:55 
GeneralRe: LVN_ITEMCHANGED and LVS_OWNERDATA issues Pin
Jim Crafton12-Mar-07 11:57
Jim Crafton12-Mar-07 11:57 
Questioninpout32.dll write issue Pin
69 Bay12-Mar-07 10:00
69 Bay12-Mar-07 10:00 
AnswerRe: inpout32.dll write issue Pin
69 Bay12-Mar-07 11:26
69 Bay12-Mar-07 11:26 
QuestionPROP_SM_CXDLG Pin
lucy12-Mar-07 9:54
lucy12-Mar-07 9:54 
QuestionCInternetSession Questions. Pin
Mike Doner12-Mar-07 8:29
Mike Doner12-Mar-07 8:29 
Hi all...

I'm doing some development which queries a PC network by making requests to a file on the host system through HTTP. I'm experimenting with CInternetSession & CHttpFile, and some of the examples of each on this site.

I have a few questions/problems:

1) Is there a way I can easily determine the MAC address of the PC I'm connectedly to?

2) I'm encountering lock-up when the hardware becomes disconnected from the network midway through the CHttpFile->Read() operation. This function hangs infinitely. Is there a timeout you can set for this?

I countered this problem with the
WebGrab Example


Here is a snippet:

BOOL CWebGrab::GetFile ( LPCTSTR szURL, CString& strBuffer, LPCTSTR szAgentName /*=NULL*/, CWnd* pWnd /*=NULL*/ )<br />
{<br />
  //  TRACE1("URL is %s\n", szURL);<br />
	m_rawHeaders ="";<br />
	m_infoStatusCode=0;<br />
	strBuffer.Empty();<br />
<br />
    if (!m_pSession && !Initialise(szAgentName, pWnd))<br />
        return FALSE;<br />
<br />
    if (pWnd)<br />
        m_pSession->SetStatusWnd(pWnd);<br />
<br />
    //m_pSession->SetStatus("Downloading file...");<br />
<br />
    DWORD dwCount = 0;<br />
    CHttpFile* pFile = NULL;<br />
    try<br />
    {<br />
        pFile = (CHttpFile*) m_pSession->OpenURL(szURL, 1,<br />
                                                 INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE<br />
                                                 //| INTERNET_OPEN_FLAG_USE_EXISTING_CONNECT |<br />
                                                 //| INTERNET_FLAG_RELOAD<br />
                                                 );<br />
    <br />
		<br />
	}<br />
    catch (CInternetException* e)<br />
    {<br />
        TCHAR   szCause[255];<br />
        e->GetErrorMessage(szCause, 255);<br />
        m_pSession->SetStatus(szCause);<br />
        // e->ReportError();<br />
        e->Delete();<br />
        delete pFile;<br />
        pFile = NULL;<br />
        return FALSE;<br />
    }<br />
    <br />
    COleDateTime startTime = COleDateTime::GetCurrentTime();<br />
    LPSTR pBuf = NULL;<br />
    if (pFile)<br />
    {<br />
        pBuf = (LPSTR) ::GlobalAlloc(GMEM_FIXED, BUFFER_SIZE+1);<br />
        if (!pBuf)<br />
        {<br />
            pFile->Close();<br />
            delete pFile;<br />
            return FALSE;<br />
        }<br />
<br />
        BYTE buffer[BUFFER_SIZE+1];<br />
        try {<br />
            UINT nRead = 0;<br />
            DWORD size;<br />
            dwCount = 0;<br />
            do<br />
            {<br />
                nRead = pFile->Read(buffer, BUFFER_SIZE); - LOCKS HERE waiting for the rest of the bytes.<br />
<br />
                if (nRead > 0)<br />
                {<br />
                    buffer[nRead] = 0;<br />
<br />
                    LPTSTR ptr = strBuffer.GetBufferSetLength(dwCount + nRead + 1);<br />
                    memcpy(ptr+dwCount, buffer, nRead);<br />
<br />
                    dwCount += nRead;<br />
                    strBuffer.ReleaseBuffer(dwCount+1);<br />
<br />
                    COleDateTimeSpan elapsed = COleDateTime::GetCurrentTime() - startTime;<br />
                    double dSecs = elapsed.GetTotalSeconds();<br />
                    if (dSecs > 0.0)<br />
					{<br />
                        m_transferRate = (double)dwCount / 1024.0 / dSecs;<br />
						m_pSession->SetStatus("Read %d bytes (%0.1f Kb/s)", <br />
                                             dwCount, m_transferRate );<br />
						<br />
					}<br />
					else<br />
					{<br />
                        m_pSession->SetStatus("Read %d bytes", dwCount);<br />
						m_transferRate = dwCount;<br />
					}<br />
                }<br />
            }<br />
            while (nRead > 0);<br />
        }<br />
        catch (CFileException *e)<br />
        {<br />
            TCHAR   szCause[255];<br />
            e->GetErrorMessage(szCause, 255);<br />
			m_ErrorMessage = szCause;<br />
            m_pSession->SetStatus(szCause);<br />
            //e->ReportError();<br />
            e->Delete();<br />
            delete pFile;<br />
            ::GlobalFree(pBuf);	// mem leak fix by Niek Albers <br />
            return FALSE;<br />
        }<br />
        pFile->QueryInfoStatusCode(m_infoStatusCode);       <br />
		pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS ,m_rawHeaders);<br />
        pFile->Close();<br />
	  ::GlobalFree(pBuf);	// mem leak fix by Niek Albers <br />
        delete pFile;<br />
    }<br />
<br />
    m_pSession->SetStatus("");<br />
<br />
    return TRUE;<br />
}


Anybody have any suggestions?
Mike
AnswerRe: CInternetSession Questions. Pin
Ravi Bhavnani12-Mar-07 11:02
professionalRavi Bhavnani12-Mar-07 11:02 
AnswerRe: CInternetSession Questions. Pin
led mike12-Mar-07 11:31
led mike12-Mar-07 11:31 
AnswerRe: CInternetSession Questions. Pin
Mark Salsbery12-Mar-07 11:56
Mark Salsbery12-Mar-07 11:56 
Questiontimer-urgent Pin
prathuraj12-Mar-07 6:35
prathuraj12-Mar-07 6:35 
AnswerRe: timer-urgent Pin
Maximilien12-Mar-07 6:41
Maximilien12-Mar-07 6:41 
AnswerRe: timer-urgent Pin
David Crow12-Mar-07 7:08
David Crow12-Mar-07 7:08 
AnswerRe: timer-urgent Pin
led mike12-Mar-07 7:59
led mike12-Mar-07 7:59 
GeneralRe: timer-urgent Pin
Mark Salsbery12-Mar-07 8:12
Mark Salsbery12-Mar-07 8:12 
GeneralRe: timer-urgent Pin
led mike12-Mar-07 8:49
led mike12-Mar-07 8:49 
GeneralRe: timer-urgent Pin
Mark Salsbery12-Mar-07 8:55
Mark Salsbery12-Mar-07 8:55 
AnswerRe: timer-urgent Pin
ThatsAlok12-Mar-07 19:49
ThatsAlok12-Mar-07 19:49 
Questiondynamic pictureBox creation Pin
sarah_malik12-Mar-07 6:35
sarah_malik12-Mar-07 6:35 
AnswerRe: dynamic pictureBox creation Pin
Hamid_RT12-Mar-07 6:57
Hamid_RT12-Mar-07 6:57 
GeneralRe: dynamic pictureBox creation Pin
sarah_malik12-Mar-07 7:13
sarah_malik12-Mar-07 7:13 
GeneralRe: dynamic pictureBox creation Pin
Maximilien12-Mar-07 8:39
Maximilien12-Mar-07 8:39 
GeneralRe: dynamic pictureBox creation Pin
sarah_malik12-Mar-07 11:58
sarah_malik12-Mar-07 11:58 
Questiontimer Pin
deeps_cute12-Mar-07 6:07
deeps_cute12-Mar-07 6:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.