Index: trunk/ab5.0/abdev/abdev/Attach.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/Attach.cpp	(revision 763)
+++ trunk/ab5.0/abdev/abdev/Attach.cpp	(revision 828)
@@ -4,4 +4,6 @@
 
 #include "common.h"
+#include <abdev/ab_common/include/Path.h>
+#include <abdev/ab_common/include/ProcessAndModule.h>
 #include <psapi.h>
 #include <tlhelp32.h>
@@ -37,5 +39,5 @@
 }
 
-void InsertProcess_ToListView(HWND hListView,char *lpszAppPath,int id,char *lpszPlatform,char *lpszTitle){
+void InsertProcess_ToListView(HWND hListView,char const* lpszAppPath,int id,char const* lpszPlatform,char const * lpszTitle){
 	char szAppName[MAX_PATH],temp2[MAX_PATH];
 	_splitpath(lpszAppPath,NULL,NULL,szAppName,temp2);
@@ -75,9 +77,9 @@
 	ListView_SetItem(hListView,&item);
 
-	item.pszText=lpszPlatform;
+	item.pszText=const_cast<LPSTR>(lpszPlatform);
 	item.iSubItem++;
 	ListView_SetItem(hListView,&item);
 
-	item.pszText=lpszTitle;
+	item.pszText=const_cast<LPSTR>(lpszTitle);
 	item.iSubItem++;
 	ListView_SetItem(hListView,&item);
@@ -159,40 +161,30 @@
 BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam)
 {
-    HWND* pphWnd = (HWND*)lParam;
-    *pphWnd = hwnd;
-    return FALSE; /* 列挙を中断 */
+	auto pProcessIdAndHWnd = reinterpret_cast<std::pair<DWORD, HWND>*>(lParam);
+	DWORD processId = 0;
+	::GetWindowThreadProcessId(hwnd, &processId);
+	if (processId == pProcessIdAndHWnd->first)
+	{
+		pProcessIdAndHWnd->second = hwnd;
+		return FALSE;
+	}
+	else
+	{
+		return TRUE;
+	}
 }
 void ListupProcesses(HWND hListView){
-	char temporary[MAX_PATH];
-
 	ListView_DeleteAllItems(hListView);
 
-	DWORD *pdwProcessId;
-	pdwProcessId=(DWORD *)HeapAlloc(hHeap,0,8192*sizeof(DWORD));
-
 	//プロセスを列挙
-	DWORD cbNeeded;
-	EnumProcesses(pdwProcessId,8192*sizeof(DWORD),&cbNeeded);
-
-	char szMyAppPath[MAX_PATH];
-	GetModuleFileName(GetModuleHandle(0),szMyAppPath,MAX_PATH);
-
-	int i;
-	for(i=0;i<(int)(cbNeeded/sizeof(DWORD));i++){
-
-		//プロセスIDを元にハンドルを取得
-		HANDLE hProcess;
-		hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,pdwProcessId[i]);
-		if(!hProcess) continue;
-
+	auto processIds = ActiveBasic::Common::GetProcesses();
+
+	char szMyAppPath[MAX_PATH] = {};
+	GetModuleFileName(nullptr, szMyAppPath, MAX_PATH);
+
+	BOOST_FOREACH(DWORD processId, processIds)
+	{
 		//そのプロセスにおける実行モジュールのインスタンスハンドルを取得
-		HINSTANCE hModule;
-		DWORD cbReturned;
-		if(!EnumProcessModules( hProcess, &hModule, sizeof(HINSTANCE), &cbReturned ))
-			continue;
-
-		//実行ファイル名を取得
-		GetModuleFileNameEx(hProcess,hModule,temporary,MAX_PATH);
-
+		auto executablePath = ActiveBasic::Common::GetExecutableModulePath(processId);
 
 		//////////////////////////////
@@ -200,36 +192,13 @@
 		//////////////////////////////
 
-		//スナップショットを取得
-		HANDLE hSnapshot;
-		hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
-
-		THREADENTRY32 te;
-		memset(&te,0,sizeof(THREADENTRY32));
-		te.dwSize=sizeof(THREADENTRY32);
-		if(Thread32First(hSnapshot,&te)){
-			do{
-				if(te.th32OwnerProcessID==pdwProcessId[i]){
-					break;
-				}
-			}while(Thread32Next(hSnapshot,&te));
-		}
-
-		HWND hwnd;
-		hwnd=0;
-		EnumThreadWindows(te.th32ThreadID,FindWindowProc,(LPARAM)&hwnd);
-
-		while(GetParent(hwnd)) hwnd=GetParent(hwnd);
-
-		char szWndTitle[1024];
-		szWndTitle[0]=0;
-		if(hwnd) GetWindowText(hwnd,szWndTitle,1024);
-
-		CloseHandle(hSnapshot);
-
-
-
-		CloseHandle(hProcess);
-
-		if(lstrcmpi(szMyAppPath,temporary)==0){
+		std::pair<DWORD, HWND> processIdAndHWnd(processId, nullptr);
+		EnumWindows(FindWindowProc, reinterpret_cast<LPARAM>(&processIdAndHWnd));
+		HWND hwnd = processIdAndHWnd.second;
+
+		TCHAR szWndTitle[1024] = {};
+		if(hwnd) GetWindowText(hwnd, szWndTitle, 1024);
+
+		if (ActiveBasic::Common::IsPathEqual(Jenga::Common::ToWString(szMyAppPath).c_str(), executablePath.wstring().c_str()))
+		{
 			//自分自身（ProjectEditor.exe）は無視
 			continue;
@@ -237,8 +206,6 @@
 
 		//リストビューへ追加
-		InsertProcess_ToListView(hListView,temporary,pdwProcessId[i],"Win32",szWndTitle);
-	}
-
-	HeapDefaultFree(pdwProcessId);
+		InsertProcess_ToListView(hListView,executablePath.string().c_str(),processId,"Win32",szWndTitle);
+	}
 }
 
