Hi, I am having a C++ application. It works fine when I run it in Debug mode, and debugs the code. But when I execute it in comand line mode I get an Unhandled exception.
Unhandled exception at 0x77012016 in test.exe: 0xC0000005: Access violation reading location 0x6cfd018d.
LPTSTR getFileDetails(LPTSTR pszObjName, SE_OBJECT_TYPE ObjectType, BOOL getOwner, BOOL getGroup)
{
PSID pSidG = (PSID)HeapAlloc(sizeof(PSID));
PSID pSidO = (PSID)HeapAlloc(sizeof(PSID));
LPTSTR AcctName = (LPTSTR)"", DomainName = (LPTSTR)"";
DWORD dwAcctName = 1, dwDomainName = 1;
SID_NAME_USE eUse = SidTypeUnknown;
PSECURITY_DESCRIPTOR pSD = NULL;
BOOL dwRes = FALSE , bRtnBool = FALSE;
DWORD ccv = GetLastError();
dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL, &pSD);
if(getGroup){
dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, GROUP_SECURITY_INFORMATION, NULL, &pSidG, NULL, NULL, &pSD);
ccv = GetLastError();
bRtnBool = LookupAccountSid(NULL, pSidG, AcctName, (LPDWORD)&dwAcctName, DomainName, (LPDWORD)&dwDomainName, &eUse);
}
if(getOwner){
dwRes = GetNamedSecurityInfo(pszObjName, ObjectType, OWNER_SECURITY_INFORMATION,&pSidO, NULL, NULL, NULL, &pSD);
ccv = GetLastError();
[B]//here crashes and return error [/B]
[B] bRtnBool = LookupAccountSid(NULL, pSidO, AcctName, (LPDWORD)&dwAcctName, DomainName, (LPDWORD)&dwDomainName, &eUse); [/B]
}
ccv = GetLastError();
AcctName = (LPTSTR)GlobalAlloc(GMEM_FIXED, dwAcctName);
if(AcctName == NULL)
{
printf("GlobalAlloc() error = %d\n", GetLastError());
return NULL;
}
DomainName = (LPTSTR)GlobalAlloc(GMEM_FIXED, dwDomainName);
if(DomainName == NULL)
{
printf("GlobalAlloc() error = %d\n", GetLastError());
return NULL;
}
if(getGroup)
bRtnBool = LookupAccountSid(NULL, pSidG, AcctName, (LPDWORD)&dwAcctName, DomainName, (LPDWORD)&dwDomainName, &eUse);
if(getOwner)
bRtnBool = LookupAccountSid(NULL, pSidO, AcctName, (LPDWORD)&dwAcctName, DomainName, (LPDWORD)&dwDomainName, &eUse);
return AcctName;
}