Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Cannot ever open fstream object in DLL?

Cannot ever open fstream object in DLL?

Scheduled Pinned Locked Moved C / C++ / MFC
helpiosperformancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    registering
    wrote on last edited by
    #1

    Howdy all, First off this board is great, thanks for everyone who helped me earlier. I'm explicitly loading a DLL and constructing an object of type CTestDLL. In this class's constructor is the following code: CTestDLL::CTestDLL() { fstream outfile; cerr << "constructed"; outfile.open("c:\test.log", ios::app); if (!outfile) { cerr << "could not open file"; exit(1); } } It always fails to open, but the constructor's definitely being called. In addition to failing to open, I always get "the instruction at 0x00000000 referenced memory at 0x00000000. The memory could not be read". I've tried creating the file manually, then trying to open it, with no luck. I've tried casting the const char* to a (LPCTSTR), using a CString, making the whole class visible, or just the individual methods (constructor/destructor) visible, all with the same results and same error. Any ideas? I've googled and found others with the same problem, but unfortunately no answers. If I take the fstream code out the object contructs fine, but the fstream seems to muck things up.

    B 1 Reply Last reply
    0
    • R registering

      Howdy all, First off this board is great, thanks for everyone who helped me earlier. I'm explicitly loading a DLL and constructing an object of type CTestDLL. In this class's constructor is the following code: CTestDLL::CTestDLL() { fstream outfile; cerr << "constructed"; outfile.open("c:\test.log", ios::app); if (!outfile) { cerr << "could not open file"; exit(1); } } It always fails to open, but the constructor's definitely being called. In addition to failing to open, I always get "the instruction at 0x00000000 referenced memory at 0x00000000. The memory could not be read". I've tried creating the file manually, then trying to open it, with no luck. I've tried casting the const char* to a (LPCTSTR), using a CString, making the whole class visible, or just the individual methods (constructor/destructor) visible, all with the same results and same error. Any ideas? I've googled and found others with the same problem, but unfortunately no answers. If I take the fstream code out the object contructs fine, but the fstream seems to muck things up.

      B Offline
      B Offline
      bmzhao
      wrote on last edited by
      #2

      change "c:\test.log" to "c:\\test.log" must have double '\'

      R 1 Reply Last reply
      0
      • B bmzhao

        change "c:\test.log" to "c:\\test.log" must have double '\'

        R Offline
        R Offline
        registering
        wrote on last edited by
        #3

        Thank you so much, what a silly mistake! What's weird is it fails even if I say "test.log" -- for some reason I have to state the drive.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups