Thread: GetCurrentDirectory problems.

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Question GetCurrentDirectory problems.

    I don't understand why 'nBufferLength' and 'pathBuffer' are printing out as '0' and 'NULL' respectively. Could someone please explain to me what I am doing incorrectly. I am sure I am just trying to use it wrong, but I don't see it!

    [code]
    DWORD nBufferLength = NULL;
    LPTSTR pathBuffer= NULL;
    DWORD temp = 0;
    char str[MAX_PATH];


    // the return value 'temp' specifies the number of characters written to the buffer,
    // not including the terminating null character.
    temp = GetCurrentDirectory(nBufferLength, pathBuffer);

    sprintf(str,"temp is %d",temp); //this prints out as 95 which is correct
    MessageBox(NULL, str, "Temp", MB_OK);

    sprintf(str,"nBufferLength is %d",nBufferLength); // This prints out as 0 ???
    MessageBox(NULL, str, "nBufferLength", MB_OK);

    sprintf(str,"path is %s",pathBuffer); // This prints out as NULL ???
    MessageBox(NULL, str, "Solution:", MB_OK);
    [\code]
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    GetCurrentDirectory() first parameter indicates the size of the buffer, not the size of the buffer after it fills the buffer with data.

    char pathBuffer[MAX_PATH + 1];
    pathBuffer[MAX_PATH] = '\0';
    ::GetCurrentDirectory(MAX_PATH, pathBuffer);

    Kuphryn

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Talking

    Thank you kuphryn this has been driving me nuts!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM