CFile::Open within an ActiveX ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: CFile::Open within an ActiveX ?

  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
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,265

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center