Access violation???

Discussion in 'C++' started by ofranko, Jan 7, 2009.

  1. ofranko

    ofranko Guest

    i get the following exception. i have no idea where to begin from.
    could someone point me to the solution?


    Unhandled exception at 0x5c5aa3d7 (msvcr90d.dll) in
    addWithObjects1.exe: 0xC0000005: Access violation writing location
    0x012888a0.




    class TheDate
    {
    public:
    TheDate(char initialDateBuffer[9]);
    ~TheDate();
    char *GetDateBuffer();
    void SetDateBuffer(char dateBuffer[9]);
    //void DisplayDate(char theDateBuffer[9]);

    private:
    char theDateBuffer[9];
    };

    TheDate::TheDate(char initialDateBuffer[9])
    {
    strncpy_s( theDateBuffer,9, initialDateBuffer,9);
    }

    TheDate::~TheDate()
    {
    }

    char *TheDate::GetDateBuffer()
    {
    cout <<"GetDateBuffer()\n";
    return theDateBuffer;
    }

    void TheDate::SetDateBuffer(char dateBuffer[9])
    {
    _strdate_s( dateBuffer,9);//gets system date

    strncpy_s( theDateBuffer,9,dateBuffer ,9 );
    }
     
    ofranko, Jan 7, 2009
    #1
    1. Advertising

  2. ofranko

    ofranko Guest

    On Jan 7, 7:57 am, ofranko <> wrote:
    > i get the following exception.   i have no idea where to begin from.
    > could someone point me to the solution?
    >
    > Unhandled exception at 0x5c5aa3d7 (msvcr90d.dll) in
    > addWithObjects1.exe: 0xC0000005: Access violation writing location
    > 0x012888a0.
    >
    > class TheDate
    >                 {
    >                 public:
    >                         TheDate(char initialDateBuffer[9]);
    >                         ~TheDate();
    >                         char *GetDateBuffer();
    >                         void SetDateBuffer(char dateBuffer[9]);
    >                         //void DisplayDate(char theDateBuffer[9]);
    >
    >                 private:
    >                         char  theDateBuffer[9];
    >                 };
    >
    >         TheDate::TheDate(char  initialDateBuffer[9])
    >                 {
    >                  strncpy_s( theDateBuffer,9, initialDateBuffer,9);
    >                 }
    >
    >         TheDate::~TheDate()
    >                 {
    >                 }
    >
    >         char *TheDate::GetDateBuffer()
    >         {
    >                 cout <<"GetDateBuffer()\n";
    >                 return  theDateBuffer;
    >                 }
    >
    >         void TheDate::SetDateBuffer(char dateBuffer[9])
    >                 {
    >            _strdate_s( dateBuffer,9);//gets system date
    >
    >                  strncpy_s( theDateBuffer,9,dateBuffer ,9 );
    >                 }


    problem seems to be related to this fx... at _RESET_STRING(buffer,
    sizeInChars);


    int month, day, year;
    SYSTEMTIME dt; /* Win32 time structure */

    _VALIDATE_RETURN_ERRCODE( ( buffer != NULL && sizeInChars >
    0 ), EINVAL )
    _RESET_STRING(buffer, sizeInChars);
    _VALIDATE_RETURN_ERRCODE( (sizeInChars >= 9), ERANGE )

    GetLocalTime(&dt);
    month = dt.wMonth;
    day = dt.wDay;
    year = dt.wYear % 100; /* change year into 0-99 value
    */
     
    ofranko, Jan 7, 2009
    #2
    1. Advertising

  3. ofranko

    ofranko Guest

    On Jan 7, 9:11 am, Victor Bazarov <> wrote:
    > ofranko wrote:
    > > [..]
    > > problem seems to be related to this fx...  at  _RESET_STRING(buffer,
    > > sizeInChars);

    >
    > >         int month, day, year;
    > >         SYSTEMTIME dt;                  /* Win32 time structure */

    >
    > >         _VALIDATE_RETURN_ERRCODE( ( buffer != NULL && sizeInChars >
    > > 0 ), EINVAL )
    > >         _RESET_STRING(buffer, sizeInChars);
    > >         _VALIDATE_RETURN_ERRCODE( (sizeInChars >= 9), ERANGE )

    >
    > >         GetLocalTime(&dt);
    > >         month = dt.wMonth;
    > >         day = dt.wDay;
    > >         year = dt.wYear % 100;          /* change year into 0-99 value
    > > */

    >
    > What is '_RESET_STRING'?  Looks like a macro of sorts.  It's not part of
    > the C++ language proper or the Standard library, so you're going to have
    > to explain to us what it does before we can help you.  An alternative is
    > to ask in the newsgroup for your compiler if those things are facilities
    > supplied by it.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    i'm sorry for not explaining better... i don't know what it does..
    it's a C++ fx related to _strdate_s (i'm guessing) i stepped threw the
    code and was brought to this point... i was, just, hoping some one had
    seen it before..
    that aside, i'm trying diff approach with std::string and without the
    char*.... i am hoping this will be more straight forward... i was
    using that approach yesterday and someone convinced me i was way
    off.... can you direct me to an article or method to get system date
    in a win32 c++ console app.

    fyi - this is my first c++ program using oop ... i'm in an online
    class just starting c++ . ... i am sorry if i ask foolish questions...
    ty for your help ..
     
    ofranko, Jan 7, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news
    Replies:
    0
    Views:
    434
  2. F. Prefect
    Replies:
    5
    Views:
    1,067
    Steven Cheng[MSFT]
    Oct 10, 2004
  3. Doug Trammell

    JNI Access Violation in jvm.dll

    Doug Trammell, Mar 4, 2004, in forum: Java
    Replies:
    5
    Views:
    8,175
    Chris Uppal
    Mar 5, 2004
  4. Allen
    Replies:
    9
    Views:
    405
  5. Steven Reddie

    Catching access violation exceptions

    Steven Reddie, Sep 29, 2003, in forum: C++
    Replies:
    15
    Views:
    1,331
    Alexander Terekhov
    Sep 30, 2003
Loading...

Share This Page