C++ Legacy Application

IDH 21 Reputation points
2020-12-09T16:48:14.773+00:00

Hi,

I have this legacy C++ application, compiled using VS 2015. The application has been installed on a number of sites where it functions as expected. It has been installed on a site in Libya where it has severe issues:

1) On startup, the app loads a CArchive file which produces a "Out of memory" error. This file is < 2Kb. If I delete this file, the app will load fully.

2) There are a number of other definition files that are also CArchive files. I can select a file, and click "Ok" and I get the message "Failed to open document".

I can get around these issues by creating the files on the target system although they may not be fully representative to be of any practical use.

3) I need to select a data source used by the application. The list of supported external devices is in a pull-down list. The list is displayed correctly, I can select an option but when I click "Ok" I get the error

"The parameter is incorrect".

The target machine is 64bit WIndows 7 4Gb memory. The application is 32-bit C++ app.

I have tried the app on 3 systems in Libya, one being WIn 10 64 bit, and each one gives the "Out of memory".

I'm at my wits end on this issue, if someone can offer any advice, it would be most appreciated.

Many thanks

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,640 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 5,051 Reputation points Microsoft Employee
    2021-03-01T09:37:07.147+00:00

    Hi

    1,Firstly, the “Out of memory” error is caused by ‘CMemoryException’ thrown at:

    ReadWeatherStationFile()  
      
                      --> m_AWS.Serialize(ar)  
      
                           --> CObList::Serialize(CArchive& ar)  
      
                                --> ar >> newData -- _AFX_INLINE CArchive& AFXAPI operator>>(CArchive& ar, CObject*& pOb){ pOb = ar.ReadObject(NULL); return ar; }  
      
                                     --> CArchive::ReadObject(const CRuntimeClass* pClassRefRequested)  
      
                                           --> pOb = pClassRef ->CreateObject() //Fail to CreateObject here, pOb is null, so AfxThroMemoryException() is called.  
    

    2,Next, go further to investigate why “CreateObject()” is failed. In the Constructor of ‘WeatherStation’, CTime(1970,1,1,0,0,0) brings the original error. For CTime function itself, it’s OK to pass 1970,1,1,0,0,0 since the lower limit for the function is 1/1/1970 12:00:00 AM GMT, any time ranging from midnight, January 1, 1970 through December 31, 3000 Universal Coordinated Time (UTC) is OK. Whilst, CTime will call _mktime64, it is impacted by different time zones.

    After an adjustment to UTC, _mktime32 handles dates from midnight, January 1, 1970, to 23:59:59 January 18, 2038, UTC. _mktime64 handles dates from midnight, January 1, 1970 to 23:59:59, December 31, 3000. This adjustment may cause these functions to return -1 (cast to time_t, __time32_t or __time64_t) even though the date you specify is within range. For example, if you are in Cairo, Egypt, which is two hours ahead of UTC, two hours will first be subtracted from the date you specify in timeptr; this may now put your date out of range.

    3, Thus, you should determine the parameters of CTime by considering the time difference. For example, my time zone is UTC+8h, so I should call CTime(1970,1,1,8,0,0,0).

    72992-314.png

    Modify the parameters of CTime by considering the time difference. For example, my time zone is UTC+8h, so I should call CTime(1970,1,1,8,0,0,0).

    Then the m_time value returned by _mktime64 would be 0 rather than -1, the error would disappear, CreateObject() would success and then the Xyrix application can run successfully!

    72820-315.png

    72920-316.png

    72944-317.png

    I suggest you could also try to use CTime(1970,1,2,0,0,0,0), and then deal with the time difference according to the time zone later.

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.