Why does this crash?
        Posted  
        
            by Adam Driscoll
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Adam Driscoll
        
        
        
        Published on 2010-04-06T21:08:42Z
        Indexed on 
            2010/04/06
            21:13 UTC
        
        
        Read the original article
        Hit count: 353
        
I've been banging my head...I can't pretend to be a C++ guy...
    TCHAR * pszUserName = userName.GetBuffer();
SID sid;
SecureZeroMemory(&sid, sizeof(sid));
SID_NAME_USE sidNameUse;
DWORD cbSid = sizeof(sid);
pLog->Log(_T("Getting the SID for user [%s]"), 1, userName);
if (!LookupAccountName(NULL, (LPSTR)pszUserName, &sid, &cbSid, NULL, 0, &sidNameUse))
{
    pLog->Log(_T("Failed to look up user SID. Error code: %d"),1,  GetLastError());
    return _T("");
}
pLog->Log(_T("Converting binary SID to string SID"));
The message 'Getting the SID for user [x] is written' but then the app crashes. I'm assuming is was the LookupAccountName call.
EDIT:
Whoops userName is a MFC CString
© Stack Overflow or respective owner