开发者

Why does this crash?

I've been banging my head...I can't pretend to be a C++ guy...

    TCHAR * pszUserName = userName.GetBuffer();
SID sid;
Se开发者_开发问答cureZeroMemory(&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


Parameter 6 (cchReferencedDomainName) should point to a DWORD. When the documentation says, "if the ReferencedDomainName parameter is NULL, this parameter must be zero," I believe they mean that the referenced DWORD must be 0.

Try adding:

DWORD cchReferencedDomainName = 0;
if (!LookupAccountName(NULL, (LPSTR)pszUserName, &sid, &cbSid, NULL, &cchReferencedDomainName, &sidNameUse))
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜