Page 1 of 1

View GDI handles/resources list and detect GDI leaks

Posted: Tue Jul 30, 2013 4:14 pm
by Antonio Linares

Re: View GDI handles/resources list and detect GDI leaks

Posted: Tue Jul 30, 2013 4:59 pm
by Antonio Linares
Buscando he llegado hasta esto con código muy interesante :-)

http://drmemory.googlecode.com/svn/trun ... handle.cpp

y desde ahi a su página:
https://code.google.com/p/drmemory/

Re: View GDI handles/resources list and detect GDI leaks

Posted: Tue Jul 30, 2013 5:51 pm
by Antonio Linares
I was curious to know how they get such info, so I started googling and it seems as first of all we need to identify the running processes. Here you can test it from FWH :-)

Code: Select all

#include "FiveWin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Right click me"

   ACTIVATE WINDOW oWnd ;
      ON RIGHT CLICK XBrowse( GetProcesses(), "Processes" )

return nil

//----------------------------------------------------------------------------//

#pragma BEGINDUMP

#include <windows.h>
#include <tlhelp32.h>
#include <hbapi.h>
#include <hbapiitm.h>

HB_FUNC( GETPROCESSES )
{
   HANDLE hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
   HANDLE hProcess;
   PROCESSENTRY32 pe;
   PHB_ITEM pProcesses = hb_itemArrayNew( 0 );
   PHB_ITEM pProcess = hb_itemNew( NULL );
    
   pe.dwSize = sizeof( pe );
   Process32First( hSnapshot, &pe );
   
   do 
   {
      hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID );

      hb_arrayNew( pProcess, 2 );
      hb_arraySetNLL( pProcess, 1, pe.th32ProcessID );
      hb_arraySetC( pProcess, 2, pe.szExeFile );
      hb_arrayAddForward( pProcesses, pProcess );
      
   } while( Process32Next( hSnapshot, &pe ) );
    
   hb_itemRelease( pProcess ); 
   hb_itemReturnRelease( pProcesses );
    
   CloseHandle( hProcess );
   CloseHandle( hSnapshot );
}

#pragma ENDDUMP

Re: View GDI handles/resources list and detect GDI leaks

Posted: Tue Jul 30, 2013 6:02 pm
by Antonio Linares

Re: View GDI handles/resources list and detect GDI leaks

Posted: Tue Jul 30, 2013 6:05 pm
by Antonio Linares