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. Using FILE* as paramter to DLL-function fails

Using FILE* as paramter to DLL-function fails

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 3 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.
  • C Offline
    C Offline
    Chris Vischer
    wrote on last edited by
    #1

    Hi, i want to call a function defined in an DLL with a FILE * as parameter, but trying to access the file via this fileponter i get an access violation. Isn't it possible to pass a filepointer to a dll function, or is there anything else to do before passing this pointer? TIA, Chris

    V L 3 Replies Last reply
    0
    • C Chris Vischer

      Hi, i want to call a function defined in an DLL with a FILE * as parameter, but trying to access the file via this fileponter i get an access violation. Isn't it possible to pass a filepointer to a dll function, or is there anything else to do before passing this pointer? TIA, Chris

      V Offline
      V Offline
      VitSoft
      wrote on last edited by
      #2

      I don't know, what kind of dll's function you used, but maybe you try use CFile class.

      1 Reply Last reply
      0
      • C Chris Vischer

        Hi, i want to call a function defined in an DLL with a FILE * as parameter, but trying to access the file via this fileponter i get an access violation. Isn't it possible to pass a filepointer to a dll function, or is there anything else to do before passing this pointer? TIA, Chris

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I'm not sure if this is the answer but from experience I do know that the standard library allocates memeory out of a heap. This heap is maintained by the standard library and your application and it's DLL would each maintain separate heaps. A problem will occur if a heap allocation/deallocation occurs when this FILE * pointer is used. Basically you cannot allocate from the heap in the application then attempt to deallocate from the DLL since the DLL assumes that the memory is in its own heap. I would suggest if possible to use file handles and work with the Win32 API instead of the standard library.

        V 1 Reply Last reply
        0
        • L Lost User

          I'm not sure if this is the answer but from experience I do know that the standard library allocates memeory out of a heap. This heap is maintained by the standard library and your application and it's DLL would each maintain separate heaps. A problem will occur if a heap allocation/deallocation occurs when this FILE * pointer is used. Basically you cannot allocate from the heap in the application then attempt to deallocate from the DLL since the DLL assumes that the memory is in its own heap. I would suggest if possible to use file handles and work with the Win32 API instead of the standard library.

          V Offline
          V Offline
          VitSoft
          wrote on last edited by
          #4

          OK, but i dont know exactly, maybe Win32API HFILE == CFile::m_hFile. I haven't big experience in Win32 development :(

          1 Reply Last reply
          0
          • C Chris Vischer

            Hi, i want to call a function defined in an DLL with a FILE * as parameter, but trying to access the file via this fileponter i get an access violation. Isn't it possible to pass a filepointer to a dll function, or is there anything else to do before passing this pointer? TIA, Chris

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Where possible, have both your EXE and DLL(s) use the dynamic run-time libraries (msvcrt.dll) instead of statocally linking to the C RTL.

            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