My script won't read the room taken up in C:\!

This is a discussion on My script won't read the room taken up in C:\! within the C++ Programming forums, part of the General Programming Boards category; This will not read the size of C:\. or the room that is taken up in C:\. How can I ...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation My script won't read the room taken up in C:\!

    This will not read the size of C:\. or the room that is taken up in C:\. How can I make it work?

    Thanks in advance, August.

    Code:
     
    	 HANDLE hFile = CreateFile("C:\", GENERIC_READ, FILE_SHARE_READ, NULL,
    	 OPEN_EXISTING, 0, 0);
     
    	 DWORD dwFileSize;
    	 dwFileSize = GetFileSize(hFile, NULL);
    	 char* constant;
    	 wsprintf(constant,"%d",dwFileSize);
    	 MessageBox(hwnd, constant, "Room taken up in C:", 0);
    Last edited by Queatrix; 09-06-2005 at 10:13 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,538
    1. You gotta watch all those \ in your paths, remember the C quoting rules for \\ to represent a \

    2. What did you expect?
    Does GetFileSize even say that it works on directories, and works in an extra special way on the root directory?

    Try GetLastError to help you figure out more.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > char* constant;
    > wsprintf(constant,"%d",dwFileSize);
    constant is just a char pointer. Unless there's something special about wsprintf() vs sprintf(), you need to make some space for the string.
    Code:
    	 char constant[20];
    	 wsprintf(constant,"%d",dwFileSize);

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    And I think %d should for correctness be %lu or %ld.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Got a project. No help, confused on how to do this.
    By DazedNconfused in forum C# Programming
    Replies: 5
    Last Post: 10-12-2008, 07:02 AM
  2. Handling movement in text-adventures.
    By suzakugaiden in forum Game Programming
    Replies: 31
    Last Post: 02-13-2005, 02:18 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Pausing script to read output
    By a_priebe47 in forum C Programming
    Replies: 1
    Last Post: 06-15-2004, 10:16 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21