OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 12:02 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: VC++Question
PostPosted: Tue Dec 03, 2002 6:10 pm 
Hello, I need to copy a file in the SYS32 dir to another dir...here is the code that doesn't work:

   // copy the old dll for backup.
   FILE* saveold = fopen( "\\DLLPATCH\\BACKUP\\uxtheme.dll", "wr" );

   int ch;

   do
   {
      ch = fgetc( fileput );

      fputc( ch, saveold );
   }

   while ( ch != EOF ); // end of file.
why?


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Tue Dec 03, 2002 8:03 pm 
First off, is this a compile-time error or a run-time error.

Second off, it appears that you are putting the ch back into the file you opened for reading. I'd open the original file as

FILE* readold = fopen( "\\DLLPATCH\\uxtheme.dll", "r" );

And then have

FILE* saveold =fopen("\\DLLPATCH\\BACKUP\\uxtheme.dll","w");

Or something like that, and then modify your do statement to read from readold and write to saveold.

Third off, am I confused or what? but what's with those double back-slashes? As far as I know, MSWIN uses a single back-slash for file separators.

Hope that helps.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Tue Dec 03, 2002 8:51 pm 
don't forget, you may need to state that it's a binary file.

so use "rb" and "wb" or else it will mangle your new line characters for you.

also, is the input file handle at the start of the file?

- Nick


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Tue Dec 03, 2002 9:32 pm 
Ok, i'll try that code and the rb stuff...

btw this is going to be for a UXTHEME.DLL patching utility for Windows XP and .NET server 2003 - letting you freely use StyleXP themes. It'll be on the web soon...and i've posted here before ;) ...but won't again( after this thread )...because I had too... ( don't know much Win32 programming ).


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Tue Dec 03, 2002 11:27 pm 
how to get the connected nodes ipaddress in vc++ :o
how to connect to a particular node


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Tue Dec 03, 2002 11:31 pm 
how to write bootstrap progrma :-[


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 12:42 am 
Andrew_Baker wrote:
Third off, am I confused or what? but what's with those double back-slashes? As far as I know, MSWIN uses a single back-slash for file separators.


You're confused :) Actually, the double backslashes are because C and its relatives all use a single backslash for escape codes, so that non-printing characters,(e.g., "\00" for an ASCII NUL character) or characters with special values (e.g., """ for a double quote) can be inserted in to strings. Because of this, the backslash itself needs to be escaped in order to have it in a string, and the code for it is, naturally enough, "\".

I imagine you knew this, but that it didn't click in the context.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 10:11 am 
Anyone have some code that copies some file?


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 11:40 am 
The Win32 CopyFile function should do what you need.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 12:59 pm 
Thankyou! Now, how do I rename a file? I found the movefile function also.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 3:21 pm 
I found how to rename and delete files, using CFile::RenameFile and DeleteFile. THankyou.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Wed Dec 04, 2002 4:25 pm 
I have one more question. Why won't CFile::Remove work? It keeps saying "Acess to unnamed file is denyed"? But there IS a file that I need to delete...it says the same thinge with CFile::Rename when I try to rename to a file that is alredy there. How do I delete a file? here is the code that won't work:

   // Delete temp stuff:
   CFile::Remove( "\\uxtheme.tmp" );
   CFile::Remove( "\\uxtheme.tm2" );

Why won't this work/how can I get it to work? I'm using Microsoft Visual C++ 5.0 on Windows .NET Server 2003 build 3663 on a NTFS file system. It won't work on FAT either.


Top
  
 
 Post subject: Re:VC++Question
PostPosted: Fri Dec 06, 2002 8:13 am 
Try the Win32 DeleteFile function, then use GetLastError to obtain the full error code.

Instead of GetLastError you can add the string err,hr into the VC++ watch window and it will give you a description of the last error that occurred.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group