VC++Question

Programming, for all ages and all languages.
Post Reply
VC++Question

VC++Question

Post 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?
Andrew_Baker

Re:VC++Question

Post 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.
sonneveld

Re:VC++Question

Post 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
VC++Question

Re:VC++Question

Post 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 ).
yourgovind

Re:VC++Question

Post by yourgovind »

how to get the connected nodes ipaddress in vc++ :o
how to connect to a particular node
yourgovind

Re:VC++Question

Post by yourgovind »

how to write bootstrap progrma :-[
Schol-R-LEA

Re:VC++Question

Post 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.
VC++Question

Re:VC++Question

Post by VC++Question »

Anyone have some code that copies some file?
Tim

Re:VC++Question

Post by Tim »

The Win32 CopyFile function should do what you need.
VC++Question

Re:VC++Question

Post by VC++Question »

Thankyou! Now, how do I rename a file? I found the movefile function also.
VC++Question

Re:VC++Question

Post by VC++Question »

I found how to rename and delete files, using CFile::RenameFile and DeleteFile. THankyou.
VC++Question

Re:VC++Question

Post 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.
Tim

Re:VC++Question

Post 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.
Post Reply