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

Hybrid View

  1. #1
    Join Date
    Apr 2002
    Location
    Michigan, USA
    Posts
    869

    First Chance Exception CString

    Why would the following line of code cause an exception and how can I fix it? This is with Visual Studio 2013 and it is set to use "Multibyte Character Set".
    This is a very old program that I was updating.

    Code:
    thepath = dadir + "\\*.csv";
    Both dadir and thepath are type CString.

    Prior to this line dadir looks fine when I look at it in the debugger but when I reach this line of code I get


    First-chance exception at 0x0FA08EE1 (mfc120d.dll) in GAQUtilities2014.exe: 0xC0000005: Access violation reading location 0xFEFEFFC6.
    Verere testudinem! (Fear the turtle)

    Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy. -Albert Einstein

    Robots are trying to steal my luggage.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: First Chance Exception CString

    Did you call somewhere GetBuffer without the following ReleaseBuffer?
    Try to set a breakpoint to this line to see where it was called from and when. Then restart the debugging from some earlir point.
    Victor Nijegorodov

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

    Re: First Chance Exception CString

    I'm not very experienced with unicode, but IIRC you have to prefix the string constants with "L".
    Code:
    thepath = dadir + L"\\*.csv";
    Does it make any difference?
    Nobody cares how it works as long as it works

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: First Chance Exception CString

    Quote Originally Posted by zerver View Post
    I'm not very experienced with unicode, but IIRC you have to prefix the string constants with "L".
    Code:
    thepath = dadir + L"\\*.csv";
    Does it make any difference?
    But OP wrote:
    Quote Originally Posted by Tom Frohman View Post
    ... This is with Visual Studio 2013 and it is set to use "Multibyte Character Set".
    Victor Nijegorodov

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

    Re: First Chance Exception CString

    Alright, well then use the _T macro anyway just to be sure, and rewrite the code a bit to rule out the possiblilty of corruption...
    Code:
    CString test = dadir;
    test += _T("\\*.csv");
    thepath = test;
    Nobody cares how it works as long as it works

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: First Chance Exception CString

    You could have memory corruption elsewhere in the app making it such that it only appears to be failing on the CString line.

    As a test, insert some temporary lines of code above the CString line. If the Cstring works at that point, you will know there memory corruption happening earlier.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured