Re: Run-Time Check Failure #2
Thanks to all
I modified my code little bit now its working
PTOKEN_PRIVILEGES tokenPrev = NULL;
if(OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken))
{
if(!GetTokenInformation(hToken,TokenPrivileges,NULL,0,&dwTokenLength))
{
//allocate the buffer
tokenPrev =
(PTOKEN_PRIVILEGES)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,dwTokenLength);
GetTokenInformation(hToken,TokenPrivileges,tokenPrev,dwTokenLength,&dwTokenLength);
for(int nCount = 0; nCount < tokenPrev->PrivilegeCount; nCount++)
{
TCHAR szPath[_MAX_PATH] = _T("");
DWORD len = _MAX_PATH;
LookupPrivilegeName(NULL,&tokenPrev->Privileges[nCount].Luid,szPath,&len);
TRACE(szPath);
}
//free the buffer
if(tokenPrev)
{
HeapFree(GetProcessHeap(), 0, (LPVOID)tokenPrev);
}
}
}
CloseHandle(hToken);
}
Thanks & Regards
Manoj Jangid
"Manoj" <manojjangid@nath.com> wrote in message
news:6B3840B7-A524-4C98-91AB-0157E9359776@microsoft.com...
Hi I am getting this error
Run-Time Check Failure #2 - Stack around the variable 'tokenPrev' was
corrupted.
I am also paste the my code can anyone tell me how can I fix this problem
?
//---------------------------------------------------------------------------------------------
BOOL CnewAppDlg::OnInitDialog()
{
HANDLE hToken = NULL;
DWORD hTokenLength = 0;
TOKEN_PRIVILEGES tokenPrev = {0};
if(OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken))
{
if(!GetTokenInformation(hToken,TokenPrivileges,NULL,0,&hTokenLength))
{
GetTokenInformation(hToken,TokenPrivileges,(LPVOID)&tokenPrev,hTokenLength,&hTokenLength);
for(int nCount = 0; nCount < tokenPrev.PrivilegeCount;
nCount++)
{
TCHAR szPath[_MAX_PATH] = _T("");
DWORD len = _MAX_PATH;
LookupPrivilegeName(NULL,&tokenPrev.Privileges[nCount].Luid,szPath,&len);
TRACE(szPath);
}
}
}
CloseHandle(hToken);
}
return TRUE; // return TRUE unless you set the focus to a control
}
//---------------------------------------------------------------------------------------------
Regards
Manoj Jangid