void DeletePipe(Pipe_t *p) { DeleteCondition(p->cond_get); DeleteCondition(p->cond_put); DeleteMonitor(p->monitor); Free(p->buf); Free(p); }
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow) { DWORD version = GetVersion(); phInstance = hInstance; if ((HIWORD(version) & 0x8000)==0) is_winnt = TRUE; if (LOBYTE(LOWORD(version)) >= 4) is_win4 = TRUE; if (lstrlen(lpszCmdLine)) silent = TRUE; LoadString(phInstance, IDS_TITLE, title, sizeof(title)/sizeof(TCHAR)-1); LoadString(phInstance, IDS_MONITORNAME, monitorname, sizeof(monitorname)/sizeof(TCHAR)-1); /* Check that it really is installed */ if (EnumMonitors(NULL, 1, (LPBYTE)buffer, sizeof(buffer), &needed, &returned)) { MONITOR_INFO_1 *mi; mi = (MONITOR_INFO_1 *)buffer; for (i=0; i<returned; i++) { if (lstrcmp(mi[i].pName, monitorname) == 0) break; } } else return message(IDS_ENUMMONITORS_FAILED); if (i == returned) return message(IDS_NOT_INSTALLED); /* Warn user about what we are about to do */ if (!silent) { TCHAR buf[256]; LoadString(phInstance, IDS_INTRO, buf, sizeof(buf)/sizeof(TCHAR)-1); if (MessageBox(HWND_DESKTOP, buf, title, MB_YESNO) != IDYES) return 0; } /* Check if monitor is still in use */ rc = EnumPorts(NULL, 2, (LPBYTE)buffer, sizeof(buffer), &needed, &returned); pi2 = (PORT_INFO_2 *)buffer; if (rc) { for (i=0; i<returned; i++) { if (lstrcmp(pi2[i].pMonitorName, monitorname) == 0) { TCHAR buf[256]; LoadString(phInstance, IDS_INUSE, buf, sizeof(buf)/sizeof(TCHAR)-1); wsprintf(sysdir, buf, pi2[i].pPortName); MessageBox(HWND_DESKTOP, sysdir, title, MB_OK); return 1; } } } else return message(IDS_ENUMPORTS_FAILED); /* Try to delete the monitor */ if (!DeleteMonitor(NULL, NULL /* is_winnt ? MONITORENVNT : MONITORENV95 */, monitorname)) return message(IDS_DELETEMONITOR_FAILED); /* Delete the monitor files */ if (!GetSystemDirectory(sysdir, sizeof(sysdir))) return message(IDS_NOSYSDIR); lstrcpy(buffer, sysdir); lstrcat(buffer, "\\"); lstrcat(buffer, is_winnt ? MONITORDLLNT : MONITORDLL95); if (!DeleteFile(buffer)) return message(IDS_ERROR_DELETE_DLL); lstrcpy(buffer, sysdir); lstrcat(buffer, "\\"); lstrcat(buffer, MONITORHLP); if (!DeleteFile(buffer)) return message(IDS_ERROR_DELETE_HELP); lstrcpy(buffer, sysdir); lstrcat(buffer, "\\"); lstrcat(buffer, REDCONF); if (!DeleteFile(buffer)) return message(IDS_ERROR_DELETE_REDCONF); /* delete registry entries for uninstall */ if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, UNINSTALLKEY, 0, KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) { RegDeleteKey(hkey, MONITORKEY); RegCloseKey(hkey); } /* Delete this program, but we can't do it while we are running. * Defer deletion until next reboot */ wsprintf(buffer, TEXT("%s\\%s"), sysdir, UNINSTALLPROG); if (is_winnt) { MoveFileEx(buffer, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); } else { char ininame[256]; GetWindowsDirectory(ininame, sizeof(ininame)); lstrcat(ininame, "\\wininit.ini"); /* This method is dodgy, because multiple applications * using this method to delete files will overwrite * earlier delete instructions. */ WritePrivateProfileString("Rename", "NUL", buffer, ininame); SetLastError(0); } #ifdef UNUSED /* We should delete this program, but we can't do it * while we are running. * I think there is a registry key we can create which says * "Delete these files on next reboot", but I can't find the * documentation about it. * Instead, run a DOS window once to delete the file */ if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", 0, KEY_ALL_ACCESS, &hkey)) == ERROR_SUCCESS) { wsprintf(buffer, "command /c del %s\\%s", sysdir, UNINSTALLPROG); RegSetValueEx(hkey, MONITORKEY, 0, REG_SZ, (CONST BYTE *)buffer, lstrlen(buffer)+1); } #endif message(IDS_UNINSTALLED); return 0; }