Search code examples
c++visual-studio-2008visual-c++windows-ce

First-chance exception at 0x03f7111c in CEDel.exe: 0xC0000005: Access violation writing location 0x002e0364


I am getting a "First-chance exception at 0x03f7111c in CEDel.exe: 0xC0000005: Access violation writing location 0x002e0364." error when running my code. I am currently running in debug mode, and running on an actual Win Mobile CE 6.5.3 device that is plugged into my computer. The top of the stack (that is not disassembly) is pointing to an if statement, and I am not sure what is causing the error. The project was created in MS eMbedded C++ several years ago, and I am porting it to MS Visual Studio 2008.

The code is

CDeviceFuncCursor& curs = tempDeviceFunc.GetCursor();// added for debug checks

if (((wcscmp(_wcsupr(tempDeviceFunc.GetCursor().m_szSection), _wcsupr(INI_SERVERS_SECTION)) == 0) &&    //INI_SERVERS_SECTION == _T("Servers")
    ((wcscmp(_wcsupr(tempDeviceFunc.GetCursor().m_szVariable), _wcsupr(FTP_PRIMARY)) == 0) ||   //FTP_PRIMARY == _T("Primary")
*    (wcscmp(_wcsupr(tempDeviceFunc.GetCursor().m_szVariable), _wcsupr(SERVER_PORT)) == 0))))   //SERVER_PORT == _T("SERVERPORT")
{
    CString csValue = tempDeviceFunc.GetCursor().m_szValue;
    csValue = EncryptData(csValue.GetBuffer(csValue.GetLength()));

    WriteProfileString(tempDeviceFunc.GetCursor().m_szSection, tempDeviceFunc.GetCursor().m_szVariable, csValue.GetBuffer(csValue.GetLength()+1));
}

The line with the * is the one being pointed to by the stack.

at the break point: curs.m_szSection = "APPLICATIONCONTROL", curs.m_szVariable = "AppLanguage", curs.m_szValue == "0"

I am not sure where to look to find the error,


Solution

  • I guess you have a macro

    #define SERVER_PORT _T("SERVERPORT")
    

    in which case _T("SERVERPORT") is a const array.
    You're not allowed to modify it (_wcsupr modifies its argument in-place).

    Replace the macro with a variable:

    TCHAR SERVER_PORT[] = _T("SERVERPORT");