Page 1 of 1

VC++Question

Posted: Tue Dec 03, 2002 6:10 pm
by VC++Question
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?

Re:VC++Question

Posted: Tue Dec 03, 2002 8:03 pm
by Andrew_Baker
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.

Re:VC++Question

Posted: Tue Dec 03, 2002 8:51 pm
by sonneveld
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

Re:VC++Question

Posted: Tue Dec 03, 2002 9:32 pm
by VC++Question
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 ).

Re:VC++Question

Posted: Tue Dec 03, 2002 11:27 pm
by yourgovind
how to get the connected nodes ipaddress in vc++ :o
how to connect to a particular node

Re:VC++Question

Posted: Tue Dec 03, 2002 11:31 pm
by yourgovind
how to write bootstrap progrma :-[

Re:VC++Question

Posted: Wed Dec 04, 2002 12:42 am
by Schol-R-LEA
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.

Re:VC++Question

Posted: Wed Dec 04, 2002 10:11 am
by VC++Question
Anyone have some code that copies some file?

Re:VC++Question

Posted: Wed Dec 04, 2002 11:40 am
by Tim
The Win32 CopyFile function should do what you need.

Re:VC++Question

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

Re:VC++Question

Posted: Wed Dec 04, 2002 3:21 pm
by VC++Question
I found how to rename and delete files, using CFile::RenameFile and DeleteFile. THankyou.

Re:VC++Question

Posted: Wed Dec 04, 2002 4:25 pm
by VC++Question
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.

Re:VC++Question

Posted: Fri Dec 06, 2002 8:13 am
by Tim
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.