![]() |
|
[C] CopyFile - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] CopyFile (/showthread.php?tid=4539753) |
CopyFile - IAmNotHere - Nov 16, 2014 Hello, I have a source where I need to copy a file to a folder, but the CopyFile function I insert in my project almost doubles the filesize after compiling. The ouput size grows from 500 kb to 1 MB! Are there less size consuming alternatives? Regards, IANH * - HelloMyNameIsWalter - Nov 16, 2014 (Nov 16, 2014 01:26 AM)IAmNotHere Wrote: Hello, Post the source? Noone can help you without seeing what you are doing. * - 0xDEAD10CC - Nov 16, 2014 ever thought about WIN32_LEAN_AND_MEAN? * - Masm4ever - Nov 17, 2014 CopyFile is a Kernel32 function, i.e. it's already present without any "included" extra libraries. The call itself costs a few bytes, not kBytes. So obviously something is seriously going wrong with your project, but without seeing the source (as IAmNotHere already wrote), there is no way to understand what exactly causes that behaviour. * - IAmNotHere - Nov 18, 2014 I replaced : Code bool copyFile(const char SRC[], const char DEST[])with: Code BOOL WINAPI CopyFile(and I have the filesize 100 KB smaller. And indeed the code doesn't run as supposed. On some machines the code runs and on some not at all. IANH * - Mouse❤️ - Nov 18, 2014 If you use <<, and your file contains a \0 null byte, what do you think happens when it runs into it? You need to know the size of your file and then copy just that many bytes, so find the size of the file with your ifstream by seekg()ing to the end of the file, tellg()ing your program how big the file is, then ostream::write()ing to the new file the contents of the old file that you istream::read() from. If that doesn't make any sense to you, then you better stop talking, and start posting code because you're not going to get anything from us if we don't know what the real problem is, because if you don't know, why the heck would we without seeing it? * - IAmNotHere - Nov 18, 2014 Thanks, I have to re-look the whole source first myself. I will take your advise along coding. IAmNotHere * - _Stoner - Nov 19, 2014 What do your #include header files look like? * - HelloMyNameIsWalter - Nov 19, 2014 You are obviously doing something wrong so here you go. This was slapped together so you may want to add more error checking or fix some syntax errors (if there are any) Code int copyFile(char *src, char *dst)* - IAmNotHere - Nov 19, 2014 (Nov 19, 2014 05:13 PM)_Stoner Wrote: What do your #include header files look like? Code #include <windows.h>* - _Stoner - Nov 19, 2014 That would be why your file size is so huge. 🤝 iostream is huge, as are some of the other headers you are using. If you want a small file size, you should look into wanting to code natively instead of using standard libraries. * - IAmNotHere - Nov 19, 2014 I noticed already. I deleted one by one of the <headers> till my vs 2013 errored to see if the filesize changed. Regards. |