none
GetUserDirectory is crashing. Unable to find good documentation. RRS feed

  • Question

  •  Hello Gentlemen,

    I have to restore the HK_CURRENT_USER registry. The backup file needs to be stored in the user's profile directory. I wrote the code below to find the path to the user's profile but it is crashing.

    I searched on the internet and could not find anything so I'm wondering if this is even supported.

    I'm developing for Win CE 6.0.

    WCHAR buf[512];
        LPWSTR pbuf = buf;

    RETAILMSG(1,(_T("Get User Directory\r\n")));
        GetUserDirectory( pbuf, (LPDWORD)(sizeof(buf)/sizeof(WCHAR)));

    Have a great day!

    Gil


    • Edited by Gil Motta Friday, January 17, 2014 6:13 PM
    Friday, January 17, 2014 6:09 PM

Answers

  • You can't cast a stack variable to an LPDWORD.

    This should work:

    WCHAR szBuffer[MAX_PATH];
    DWORD dwSize = _countof(szBuffer);
    
    if (!GetUserDirectory(szBuffer, &dwSize))
       RETAILMSG(1, (L"Error getting user directory [%d]\r\n", GetLastError()));
    else
       RETAILMSG(1, ("User directory: \"%s\"\r\n", szBuffer));


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Monday, January 20, 2014 11:06 AM
    Moderator

All replies

  • You can't cast a stack variable to an LPDWORD.

    This should work:

    WCHAR szBuffer[MAX_PATH];
    DWORD dwSize = _countof(szBuffer);
    
    if (!GetUserDirectory(szBuffer, &dwSize))
       RETAILMSG(1, (L"Error getting user directory [%d]\r\n", GetLastError()));
    else
       RETAILMSG(1, ("User directory: \"%s\"\r\n", szBuffer));


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Monday, January 20, 2014 11:06 AM
    Moderator
  • Great, Thank you!
    Monday, January 20, 2014 3:30 PM