CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Access violation reading location 0x00000000

  1. #1
    Join Date
    Apr 2016
    Posts
    1

    Access violation reading location 0x00000000

    Call Stack:
    > msvcr80d.dll!memcpy(unsigned char * dst=0x01ddfd20, unsigned char * src=0x00000000, unsigned long count=8) Line 318 Asm
    Members.exe!CQueue::Pull() Line 47 + 0x18 bytes C++
    Members.exe!CThreadSend::Run() Line 42 + 0xb bytes C++
    Members.exe!ThreadProc(void * ipContext=0x00709be0) Line 19 + 0xe bytes C++

    char* CQueue::Pull()
    {
    //critical open
    EnterCriticalSection(&m_cs);
    char* pData = NULL;
    if(QueueSize() > 0)
    {
    MSG_Packet msgPacket;
    ==> memcpy(&msgPacket,m_ArrData.GetAt(0),sizeof(MSG_Packet));
    pData = new char[sizeof(MSG_Packet) + msgPacket.nSize];
    memcpy(pData,m_ArrData.GetAt(0),sizeof(MSG_Packet)+msgPacket.nSize);
    delete[] m_ArrData.GetAt(0);
    m_ArrData.RemoveAt(0);
    }
    LeaveCriticalSection(&m_cs);
    //critical close
    return pData;
    }

    void CThreadSend::Run()
    {
    char* pData = NULL;
    while(TRUE)
    {
    if(m_pQueue->QueueSize() <= 0)
    {
    Sleep(50);
    continue;
    }

    ==> pData = m_pQueue->Pull();

    int nPacketSize = 0;
    int buffOffset = 0;
    nPacketSize = GetSizePackage(pData);
    do
    {
    int nbytesend = m_pSocketGeneral->SendMessage(pData + buffOffset,nPacketSize);
    buffOffset += nbytesend;
    nPacketSize -= nbytesend;
    } while (nPacketSize>0);
    delete[] pData;
    pData = NULL;
    }
    }

    definition m_ArrData: CArray<char*,char*> m_ArrData;

    I get Access violation reading location 0x00000000. plz help me.

    Thanks.

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Access violation reading location 0x00000000

    Try this:
    m_ArrData.Add(new char[sizeof(MSG_Packet)]);
    memcpy(&msgPacket,m_ArrData.GetAt(0),sizeof(MSG_Packet));
    Last edited by zerver; April 11th, 2016 at 10:18 AM.
    Nobody cares how it works as long as it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)