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. Windows API
  4. Problem with tmpfile() function.

Problem with tmpfile() function.

Scheduled Pinned Locked Moved Windows API
helpc++
9 Posts 4 Posters 7 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.
  • S Offline
    S Offline
    Sameerkumar Namdeo
    wrote on last edited by
    #1

    Hello Everybody, I am having an application that has been developed using (VC++ 6.0 \ Xp Platform). Now, that application is shifted on Vista. I have installed VC++ 6.0 on Vista and my application is running properly on (VC++6.0 \ Vista platform). There is one function tmpfile() in which creates temporary file. This function was working properly on (VC++ 6.0 \ Xp Platform), but returns NULL on (VC++ 6.0 \ Vista) platform. When I was debugging I found that internally this function is calling CreateFile(). Here, CreateFile() fails and GetLastError() returns 5. Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista). Also, GetLastError() returns 5 which specifies file Access is denied. Internally, tmpfile() calls _sopen() and _sopen calls CreateFile(). After _sopen() I am getting errno = EACCES (Plz refer ERRNO.H). Can any one please specify the solution as to why tmpfile() is returning NULL. Thanks & Regards, Sameer();

    P M P 3 Replies Last reply
    0
    • S Sameerkumar Namdeo

      Hello Everybody, I am having an application that has been developed using (VC++ 6.0 \ Xp Platform). Now, that application is shifted on Vista. I have installed VC++ 6.0 on Vista and my application is running properly on (VC++6.0 \ Vista platform). There is one function tmpfile() in which creates temporary file. This function was working properly on (VC++ 6.0 \ Xp Platform), but returns NULL on (VC++ 6.0 \ Vista) platform. When I was debugging I found that internally this function is calling CreateFile(). Here, CreateFile() fails and GetLastError() returns 5. Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista). Also, GetLastError() returns 5 which specifies file Access is denied. Internally, tmpfile() calls _sopen() and _sopen calls CreateFile(). After _sopen() I am getting errno = EACCES (Plz refer ERRNO.H). Can any one please specify the solution as to why tmpfile() is returning NULL. Thanks & Regards, Sameer();

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      ccpptrain wrote:

      Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista).

      There is more secured version available for this function called tmpfile_s . But in this case, running your program as administrator would solve the issue.


      Prasad MS MVP -  VC++

      S 1 Reply Last reply
      0
      • S Sameerkumar Namdeo

        Hello Everybody, I am having an application that has been developed using (VC++ 6.0 \ Xp Platform). Now, that application is shifted on Vista. I have installed VC++ 6.0 on Vista and my application is running properly on (VC++6.0 \ Vista platform). There is one function tmpfile() in which creates temporary file. This function was working properly on (VC++ 6.0 \ Xp Platform), but returns NULL on (VC++ 6.0 \ Vista) platform. When I was debugging I found that internally this function is calling CreateFile(). Here, CreateFile() fails and GetLastError() returns 5. Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista). Also, GetLastError() returns 5 which specifies file Access is denied. Internally, tmpfile() calls _sopen() and _sopen calls CreateFile(). After _sopen() I am getting errno = EACCES (Plz refer ERRNO.H). Can any one please specify the solution as to why tmpfile() is returning NULL. Thanks & Regards, Sameer();

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        You can use GetTempPath() and GetTempFileName() to do the same thing as tmpfile().

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

        S 1 Reply Last reply
        0
        • S Sameerkumar Namdeo

          Hello Everybody, I am having an application that has been developed using (VC++ 6.0 \ Xp Platform). Now, that application is shifted on Vista. I have installed VC++ 6.0 on Vista and my application is running properly on (VC++6.0 \ Vista platform). There is one function tmpfile() in which creates temporary file. This function was working properly on (VC++ 6.0 \ Xp Platform), but returns NULL on (VC++ 6.0 \ Vista) platform. When I was debugging I found that internally this function is calling CreateFile(). Here, CreateFile() fails and GetLastError() returns 5. Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista). Also, GetLastError() returns 5 which specifies file Access is denied. Internally, tmpfile() calls _sopen() and _sopen calls CreateFile(). After _sopen() I am getting errno = EACCES (Plz refer ERRNO.H). Can any one please specify the solution as to why tmpfile() is returning NULL. Thanks & Regards, Sameer();

          P Offline
          P Offline
          Paresh Chitte
          wrote on last edited by
          #4

          Please refer this[^]. Regards, Paresh.

          S 1 Reply Last reply
          0
          • P prasad_som

            ccpptrain wrote:

            Since the tmpfile() function is related to C Runtime Library, so is there any incompatibitly issue while shifting from (VC++ 6.0 \ Xp) to (VC++ 6.0 \ Vista).

            There is more secured version available for this function called tmpfile_s . But in this case, running your program as administrator would solve the issue.


            Prasad MS MVP -  VC++

            S Offline
            S Offline
            Sameerkumar Namdeo
            wrote on last edited by
            #5

            But I think tmpfile_s is available in .net framework. Will I be able to use it in VC++ 6.0.

            P 1 Reply Last reply
            0
            • M Michael Dunn

              You can use GetTempPath() and GetTempFileName() to do the same thing as tmpfile().

              --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

              S Offline
              S Offline
              Sameerkumar Namdeo
              wrote on last edited by
              #6

              Thanks for the replies... But, I can always do the manipulation by using GetTempPath() to create a temporary file. But I wanted to know the reasons for why tmpfile() is returning NULL, GetLastError() return 5, and errno = EACCES. In Vista I have logged on as an administrator, so I think there should not be any problem for creating file anywhere on the system.

              M 1 Reply Last reply
              0
              • S Sameerkumar Namdeo

                But I think tmpfile_s is available in .net framework. Will I be able to use it in VC++ 6.0.

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                ccpptrain wrote:

                But I think tmpfile_s is available in .net framework

                I'm sorry about that, its supported on VS2K5. And, it is part of enhanced CRT library, not .net framework.

                ccpptrain wrote:

                Will I be able to use it in VC++ 6.0.

                No. But, older version you can still use. As mentioned earlier, even if you are logged in as administrator, you need to run that program as administrator.


                Prasad MS MVP -  VC++

                1 Reply Last reply
                0
                • S Sameerkumar Namdeo

                  Thanks for the replies... But, I can always do the manipulation by using GetTempPath() to create a temporary file. But I wanted to know the reasons for why tmpfile() is returning NULL, GetLastError() return 5, and errno = EACCES. In Vista I have logged on as an administrator, so I think there should not be any problem for creating file anywhere on the system.

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  Ah, the docs say:

                  The temporary file is created in the root directory.

                  The root directory of a drive is a protected location, that's why you're getting access denied.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

                  1 Reply Last reply
                  0
                  • P Paresh Chitte

                    Please refer this[^]. Regards, Paresh.

                    S Offline
                    S Offline
                    Sameerkumar Namdeo
                    wrote on last edited by
                    #9

                    Yes it solved my problem... Actually, vista is installed on D drive which is root directory on my PC. Previously, I use to log on as a user who was not having write/ create file permission on root directory. That is the reason why tmpfile() was returning NULL. The temporary file is created when I log on as an Administrator or a user who has that permission. I gave Permission "Full Control" to User. I solved that my "right clicking on D drive", then "propertise", then going to "Security Tab", then "Advanced", and then "selecting the User" and then "Edit" and giving the appropriate permission. Thanks & Regards, Sameer.

                    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