Click here to Skip to main content
16,016,759 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to remove the extra border of a button after enabling xp visual style Pin
goldenrose918-Mar-11 17:38
goldenrose918-Mar-11 17:38 
AnswerRe: how to remove the extra border of a button after enabling xp visual style Pin
Hans Dietrich19-Mar-11 2:32
mentorHans Dietrich19-Mar-11 2:32 
QuestionRe: how to remove the extra border of a button after enabling xp visual style Pin
goldenrose919-Mar-11 8:02
goldenrose919-Mar-11 8:02 
QuestionAccess violation reading location 0x00378004. Pin
so0_lanhlung218-Mar-11 17:06
so0_lanhlung218-Mar-11 17:06 
QuestionRe: Access violation reading location 0x00378004. Pin
CPallini18-Mar-11 23:37
mveCPallini18-Mar-11 23:37 
AnswerRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 3:31
so0_lanhlung219-Mar-11 3:31 
QuestionRe: Access violation reading location 0x00378004. Pin
Code-o-mat18-Mar-11 23:59
Code-o-mat18-Mar-11 23:59 
AnswerRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 3:23
so0_lanhlung219-Mar-11 3:23 
this is my function
void CShowHandlesOfProc::AddHandlesToList(CListCtrl *m_list,DWORD pid)
{
	int nItem=0;
	NTSTATUS                   status;
    PSYSTEM_HANDLE_INFORMATION handleInfo;
    ULONG                      handleInfoSize = 0x10000;
    HANDLE                     processHandle;
    ULONG                      i;
    
    _NtQuerySystemInformation NtQuerySystemInformation = 
    (_NtQuerySystemInformation)GetLibraryProcAddress("ntdll.dll", "NtQuerySystemInformation");

	_NtDuplicateObject NtDuplicateObject =
    (_NtDuplicateObject)GetLibraryProcAddress("ntdll.dll", "NtDuplicateObject");

	_NtQueryObject NtQueryObject =
    (_NtQueryObject)GetLibraryProcAddress("ntdll.dll", "NtQueryObject");

    if(!(processHandle = OpenProcess(PROCESS_DUP_HANDLE|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid))) return;

    handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc(handleInfoSize);

    while((status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,handleInfoSize,NULL)) == STATUS_INFO_LENGTH_MISMATCH)
    handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2);

    if(!NT_SUCCESS(status)) return;
    
    for(i = 0; i < handleInfo->HandleCount; i++)
    {
        SYSTEM_HANDLE handle     = handleInfo->Handles[i];
        HANDLE dupHandle         = NULL;
        POBJECT_TYPE_INFORMATION objectTypeInfo;
        PVOID                    objectNameInfo;
        UNICODE_STRING           objectName;
        ULONG                    returnLength;

        if(handle.ProcessId != pid) continue;
        if(!NT_SUCCESS(NtDuplicateObject(processHandle,(HANDLE)handle.Handle,GetCurrentProcess(),&dupHandle,0,0,0))) continue;
        objectTypeInfo = (POBJECT_TYPE_INFORMATION)malloc(0x1000);

        if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectTypeInformation,objectTypeInfo,0x1000,NULL)))
        {
            CloseHandle(dupHandle);
            continue;
        }

        if((handle.GrantedAccess != 0x0012019f)
        && (handle.GrantedAccess != 0x001a019f)
        && (handle.GrantedAccess != 0x00120189)
        && (handle.GrantedAccess != 0x00100000))
        {
            wprintf(L"%s - 0x%X - ",objectTypeInfo->Name.Buffer, handle.Handle);
            //wprintf(L"0x%X",handle.GrantedAccess);
			CString szType,szHandle,szName;
			szHandle.Format(L"0x%X",handle.Handle);
			m_list->InsertItem(nItem,szHandle);
			nItem++;
            objectNameInfo = malloc(0x1000);
            if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectNameInformation,objectNameInfo,0x1000,&returnLength)))
            {
                objectNameInfo = realloc(objectNameInfo, returnLength);
                if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectNameInformation,objectNameInfo,returnLength,NULL)))
                {
                    free(objectTypeInfo);
                    free(objectNameInfo);
                    CloseHandle(dupHandle);
                    continue;
                }
            }
            objectName = *(PUNICODE_STRING)objectNameInfo;

            if(objectName.Length) wprintf(L"%s",objectName.Buffer);
            else wprintf(L"\0");
            
            wprintf(L"\n");
        }
        free(objectTypeInfo);
        free(objectNameInfo);
        CloseHandle(dupHandle);
    }
    free(handleInfo);
    CloseHandle(processHandle);
    return;
}


this is my structs
#define SystemHandleInformation 16
#define ObjectBasicInformation 0
#define ObjectNameInformation 1
#define ObjectTypeInformation 2

typedef ULONG (NTAPI *_NtQuerySystemInformation)(
    ULONG SystemInformationClass,
    PVOID SystemInformation,
    ULONG SystemInformationLength,
    PULONG ReturnLength
    );
typedef ULONG (NTAPI *_NtDuplicateObject)(
    HANDLE SourceProcessHandle,
    HANDLE SourceHandle,
    HANDLE TargetProcessHandle,
    PHANDLE TargetHandle,
    ACCESS_MASK DesiredAccess,
    ULONG Attributes,
    ULONG Options
    );
typedef ULONG (NTAPI *_NtQueryObject)(
    HANDLE ObjectHandle,
    ULONG ObjectInformationClass,
    PVOID ObjectInformation,
    ULONG ObjectInformationLength,
    PULONG ReturnLength
    );

typedef struct _UNICODE_STRING
{
    USHORT Length;
    USHORT MaximumLength;
    PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;

typedef struct _SYSTEM_HANDLE
{
    ULONG ProcessId;
    BYTE ObjectTypeNumber;
    BYTE Flags;
    USHORT Handle;
    PVOID Object;
    ACCESS_MASK GrantedAccess;
} SYSTEM_HANDLE, *PSYSTEM_HANDLE;

typedef struct _SYSTEM_HANDLE_INFORMATION
{
    ULONG HandleCount;
    SYSTEM_HANDLE Handles[1];
} SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION;

typedef enum _POOL_TYPE
{
    NonPagedPool,
    PagedPool,
    NonPagedPoolMustSucceed,
    DontUseThisType,
    NonPagedPoolCacheAligned,
    PagedPoolCacheAligned,
    NonPagedPoolCacheAlignedMustS
} POOL_TYPE, *PPOOL_TYPE;

typedef struct _OBJECT_TYPE_INFORMATION
{
    UNICODE_STRING Name;
    ULONG TotalNumberOfObjects;
    ULONG TotalNumberOfHandles;
    ULONG TotalPagedPoolUsage;
    ULONG TotalNonPagedPoolUsage;
    ULONG TotalNamePoolUsage;
    ULONG TotalHandleTableUsage;
    ULONG HighWaterNumberOfObjects;
    ULONG HighWaterNumberOfHandles;
    ULONG HighWaterPagedPoolUsage;
    ULONG HighWaterNonPagedPoolUsage;
    ULONG HighWaterNamePoolUsage;
    ULONG HighWaterHandleTableUsage;
    ULONG InvalidAttributes;
    GENERIC_MAPPING GenericMapping;
    ULONG ValidAccess;
    BOOLEAN SecurityRequired;
    BOOLEAN MaintainHandleCount;
    USHORT MaintainTypeList;
    POOL_TYPE PoolType;
    ULONG PagedPoolUsage;
    ULONG NonPagedPoolUsage;
} OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION;

this funciton run in Console project
but when i creat dialog MFC..and i try add handle to ListCtrl have Error

Access violation reading location 0xbaadf00d.
i don't know...
help me plz
GeneralRe: Access violation reading location 0x00378004. Pin
Richard MacCutchan19-Mar-11 3:59
mveRichard MacCutchan19-Mar-11 3:59 
GeneralRe: Access violation reading location 0x00378004. Pin
Code-o-mat19-Mar-11 4:01
Code-o-mat19-Mar-11 4:01 
GeneralRe: Access violation reading location 0x00378004. Pin
so0_lanhlung219-Mar-11 6:22
so0_lanhlung219-Mar-11 6:22 
QuestionRe: Access violation reading location 0x00378004. Pin
CPallini19-Mar-11 4:41
mveCPallini19-Mar-11 4:41 
QuestionMy computer is possessed Pin
Kaaib18-Mar-11 11:30
Kaaib18-Mar-11 11:30 
AnswerRe: My computer is possessed Pin
వేంకటనారాయణ(venkatmakam)18-Mar-11 20:24
వేంకటనారాయణ(venkatmakam)18-Mar-11 20:24 
GeneralRe: My computer is possessed Pin
Kaaib18-Mar-11 21:47
Kaaib18-Mar-11 21:47 
GeneralRe: My computer is possessed Pin
Richard MacCutchan18-Mar-11 23:45
mveRichard MacCutchan18-Mar-11 23:45 
GeneralRe: My computer is possessed Pin
Code-o-mat19-Mar-11 0:06
Code-o-mat19-Mar-11 0:06 
QuestionWhat is corect way to send an CString through ::PostMessage(...) ? Pin
_Flaviu18-Mar-11 0:09
_Flaviu18-Mar-11 0:09 
AnswerRe: What is corect way to send an CString through ::PostMessage(...) ? Pin
CPallini18-Mar-11 1:23
mveCPallini18-Mar-11 1:23 
GeneralRe: What is corect way to send an CString through ::PostMessage(...) ? Pin
_Flaviu18-Mar-11 2:23
_Flaviu18-Mar-11 2:23 
GeneralRe: What is corect way to send an CString through ::PostMessage(...) ? Pin
CPallini18-Mar-11 2:46
mveCPallini18-Mar-11 2:46 
QuestionHow can I tell the compiler that should compile only VC6 ? Pin
_Flaviu17-Mar-11 23:57
_Flaviu17-Mar-11 23:57 
AnswerRe: How can I tell the compiler that should compile only VC6 ? Pin
Niklas L18-Mar-11 0:31
Niklas L18-Mar-11 0:31 
GeneralRe: How can I tell the compiler that should compile only VC6 ? Pin
_Flaviu18-Mar-11 0:43
_Flaviu18-Mar-11 0:43 
GeneralRe: How can I tell the compiler that should compile only VC6 ? Pin
Niklas L18-Mar-11 1:30
Niklas L18-Mar-11 1:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.