Problem with tmpfile() function.
-
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();
-
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();
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++
-
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();
You can use
GetTempPath()
andGetTempFileName()
to do the same thing astmpfile()
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
-
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();
-
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++
But I think tmpfile_s is available in .net framework. Will I be able to use it in VC++ 6.0.
-
You can use
GetTempPath()
andGetTempFileName()
to do the same thing astmpfile()
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?
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.
-
But I think tmpfile_s is available in .net framework. Will I be able to use it in VC++ 6.0.
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++
-
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.
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?
-
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.