#include #include #include #include // using http://www.piotrkaluski.com/files/winguitest/docs/winguitest.html as a guide, because it shows both C and Win32::GuiTest #define NPPMSG (WM_USER + 1000) #define NPP_GETNBOPENFILES (NPPMSG + 7) #define NPP_GETOPENFILENAMES (NPPMSG + 8) #define NPP_GETOPENFILENAMESPRIMARY (NPPMSG + 17) #define NPP_GETOPENFILENAMESSECOND (NPPMSG + 18) int main(int argc, char**argv) { LRESULT ret, msg, w, l; HWND hWnd; int i; for(i = 0; i ), notepad()->{$_} for qw/_hwnd _exe _pid/\"\n"); return 255; } hWnd = (HWND)strtoull( argv[1], (char**)NULL, 0 ); // first need to verify I can do simple messages in C. Since I'll need it, grab the ret = SendMessage((HWND)hWnd, (UINT)(msg=NPP_GETNBOPENFILES), (WPARAM)(w=0), (LPARAM)(l=0)); fprintf(stderr, "run SendMessage(0x%016I64x,0x%016I64x,0x%016I64x,0x%016I64x) = %016I64x\n", (LRESULT)hWnd, msg, w, l, ret); int n_all = ret; ret = SendMessage((HWND)hWnd, (UINT)(msg=NPP_GETNBOPENFILES), (WPARAM)(w=0), (LPARAM)(l=1)); fprintf(stderr, "run SendMessage(0x%016I64x,0x%016I64x,0x%016I64x,0x%016I64x) = %016I64x\n", (LRESULT)hWnd, msg, w, l, ret); int n_one = ret; ret = SendMessage((HWND)hWnd, (UINT)(msg=NPP_GETNBOPENFILES), (WPARAM)(w=0), (LPARAM)(l=2)); fprintf(stderr, "run SendMessage(0x%016I64x,0x%016I64x,0x%016I64x,0x%016I64x) = %016I64x\n", (LRESULT)hWnd, msg, w, l, ret); int n_two = ret; fprintf(stderr, "all=%d, one=%d, two=%d\n", n_all, n_one, n_two); // now get process info DWORD pid = 0; GetWindowThreadProcessId( hWnd , & pid ); HANDLE hProcHnd = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pid ); fprintf(stderr, "pid = %ld, hProcHnd = 0x%016I64x\n", pid, (LRESULT)hProcHnd); #if 1 // I think this allocates virtual space for an array of LPVOID elements LPVOID* fileNames = calloc( n_all , sizeof(LPVOID) ); LPVOID pVirtFileNames = VirtualAllocEx( hProcHnd, NULL, sizeof( LPVOID* ), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); fprintf(stderr, "pVirtFileNames = %p\n", pVirtFileNames); SIZE_T copied = 0; char fileName[1025]; // for each filename, allocate real and virtual for 1025 TCHAR for(int i=0; i