CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2001
    Posts
    5

    CFile::Open within an ActiveX ?

    I have the following code within an ActiveX control and it crashes the TestContainer every time.


    CFile f;
    CFileException e;
    TCHAR* pFileName = _T("c:\\tree.txt");

    f.Open(pFileName, CFile::modeRead | CFile::shareDenyWrite, &e);




    The "tree.txt" file is in the "c:\" directory.
    Is there another way I should be doing file reading from within an ActiveX control?

    Any help would be greatly appreciated.

    Thanks. Pete


  2. #2
    Join Date
    Oct 2001
    Posts
    5

    Re: CFile::Open within an ActiveX ?

    I forgot to mention the error I get is:
    3e6 : "Invalid access to memory location"


  3. #3
    Join Date
    Feb 2001
    Location
    Sydney, Australia
    Posts
    1,909

    Re: CFile::Open within an ActiveX ?

    use ifstream C++ class, or fread().

    Please - rate answer if it helped you
    It gives me inspiration when I see myself in the top list =)

    Best regards,

    -----------
    Igor Soukhov (Brainbench/Tekmetrics ID:50759)
    igor@soukhov.com | ICQ:57404554 | http://soukhov.com

    Member of Russian Software Developer Network http://rsdn.ru
    Best regards,
    Igor Sukhov

    www.sukhov.net

  4. #4
    Join Date
    Jun 2014
    Posts
    2

    Re: CFile::Open within an ActiveX ?

    Quote Originally Posted by pdcira View Post
    I have the following code within an ActiveX control and it crashes the TestContainer every time.


    CFile f;
    CFileException e;
    TCHAR* pFileName = _T("c:\\tree.txt");

    f.Open(pFileName, CFile::modeRead | CFile::shareDenyWrite, &e);




    The "tree.txt" file is in the "c:\" directory.
    Is there another way I should be doing file reading from within an ActiveX control?

    Any help would be greatly appreciated.

    Thanks. Pete
    Shouldn't this line...
    TCHAR* pFileName = _T("c:\\tree.txt");

    only have one backslash?

    TCHAR* pFileName = _T("c:\tree.txt");

    Perhaps that would work better?

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: CFile::Open within an ActiveX ?

    Quote Originally Posted by HarveyURAD View Post
    Shouldn't this line...
    TCHAR* pFileName = _T("c:\\tree.txt");

    only have one backslash?

    TCHAR* pFileName = _T("c:\tree.txt");

    Perhaps that would work better?
    No! \ is the escape char in strings so to actually have a \ in a string you use \\. See http://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Jun 2014
    Posts
    2

    Re: CFile::Open within an ActiveX ?

    Quote Originally Posted by 2kaud View Post
    No! \ is the escape char in strings so to actually have a \ in a string you use \\. See http://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx
    Ah! You are absolutely correct, my mistake

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