A Stupid Question
idbruce
Posts: 6,197
Is it possible to change the compiler of Mcrosoft Visual C++ 6.0 to Propeller GCC? And of course, be able to switch it back again?

Comments
I really wanted to post something helpful too... but a quick Google did not turn up anything
Propeller GCC is for Propeller architecture.
Microsoft's Visual C++ is generally for Intel based architecture and their clones. I am not sure if Microsoft has managed to target other architectures, but they have ignored the Propeller.
Since the Propeller GCC is a cross-compiler, you could have both installed on the same computer.
Probably not so simple to do. What's wrong with SimpleIDE anyway?
Nothing is wrong with SimpleIDE, I am just accustomed to the Visual setup.
I doubt that VS debugging will work for gdb and gcc.
Like you I really got used to all the goodies of VS. It is a really nice IDE, fast, powerful and - well - I am used to since years. So I am biased. Yes I am.
I am also a fan of the company jetbrains. Never tried Clion, since I rarely program in C. But I used a program called TeamCity with some customers of mine and was very happy about that software. Works perfectly together with Visual Studio and almost any Source Control System. Builds whatever you want, runs tests over it, can run tests over your source (like duplicates) and does nice reporting about all of it. Highly recommended to look at.
Enjoy!
Mike
Thanks for the idea Mike.
For those that may be interested in a similar idea.... I don't believe this is the original code that I wrote for the self-deleting batch files, but I am certain that I must have copied the routine for use in this function. This function can easily be altered to create your own self-deleting batch files.
EDIT: Although I would write it much different these days with the use of CString. I was pretty much still a newbie when I wrote this.
void CFuzzyWuzzyDlg::OnUninstall() { HMODULE hModule; HANDLE hFile; TCHAR szWindowsDirectory[MAX_PATH] = _T(""); LPTSTR szBatchFilenameAndExt = _T("\\MYUNINSTALL.BAT"); TCHAR szSelfDeletingBatchFile[MAX_PATH] = _T(""); TCHAR szUninstallExe[MAX_PATH] = _T(""); TCHAR szUninstallExeShortPath[MAX_PATH] = _T(""); DWORD dwBytesWritten; DWORD cchBuffer = MAX_PATH; LPCTSTR szFirstBatLine = _T("@ECHO OFF\r\n"); LPCTSTR szSecondBatLine = _T(":REPEAT\r\n"); TCHAR szThirdBatLine[MAX_PATH] = _T(""); TCHAR szFourthBatLine[MAX_PATH] = _T(""); TCHAR szFifthBatLine[MAX_PATH] = _T(""); LPCTSTR szDelBatCommand = _T("DEL "); LPCTSTR szIfExistBatCondition = _T("IF EXIST "); LPCTSTR szGoToBatStatment = _T(" GOTO :REPEAT"); LPCTSTR szBatLineFeed = _T("\r\n"); hModule = GetModuleHandle(NULL); GetModuleFileName(hModule, szUninstallExe, MAX_PATH); GetShortPathName(szUninstallExe, szUninstallExeShortPath, cchBuffer); GetWindowsDirectory(szWindowsDirectory, MAX_PATH); lstrcat(szSelfDeletingBatchFile, szWindowsDirectory); lstrcat(szSelfDeletingBatchFile, szBatchFilenameAndExt); lstrcat(szThirdBatLine, szDelBatCommand); lstrcat(szThirdBatLine, szUninstallExeShortPath); lstrcat(szThirdBatLine, szBatLineFeed); lstrcat(szFourthBatLine, szIfExistBatCondition); lstrcat(szFourthBatLine, szUninstallExeShortPath); lstrcat(szFourthBatLine, szGoToBatStatment); lstrcat(szFourthBatLine, szBatLineFeed); lstrcat(szFifthBatLine, szDelBatCommand); lstrcat(szFifthBatLine, szSelfDeletingBatchFile); hFile = CreateFile(szSelfDeletingBatchFile, GENERIC_READ | GENERIC_WRITE, (DWORD)0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, (HANDLE)NULL); WriteFile(hFile, szFirstBatLine, (DWORD)lstrlen(szFirstBatLine), (LPDWORD)&dwBytesWritten, NULL); WriteFile(hFile, szSecondBatLine, (DWORD)lstrlen(szSecondBatLine), (LPDWORD)&dwBytesWritten, NULL); WriteFile(hFile, szThirdBatLine, (DWORD)lstrlen(szThirdBatLine), (LPDWORD)&dwBytesWritten, NULL); WriteFile(hFile, szFourthBatLine, (DWORD)lstrlen(szFourthBatLine), (LPDWORD)&dwBytesWritten, NULL); WriteFile(hFile, szFifthBatLine, (DWORD)lstrlen(szFifthBatLine), (LPDWORD)&dwBytesWritten, NULL); CloseHandle(hFile); ShellExecute(NULL, "open", szSelfDeletingBatchFile, NULL, 0, NULL); OnExit(); }I don't get the idea.
If you write a program that writes out a batch file, then runs it. And then the batch file deletes itself. Why not instead have the program delete the batch file when it's finished running?
On a Windows OS, ShellExecute is the easiest way to execute something, such as a batch file. The problem is that ShellExecute only returns a HINSTANCE. It would be difficult to monitor the batch file, to know when it has finished running. It is much easier to just create the self-deleting file, because it will know when the execution is complete.
EDIT: However, ShellExecute has the lpParameters parameter, which may allow you to pass command line arguments directly to GCC.
I don't know if you examined that code at all, but.....
The EXE file writes the BAT file, executes the BAT file, and then the EXE file exits. The BAT file then loops until it is capable of deleting the EXE file that wrote the BAT file and then the BAT file deletes itself
So what you have is a self deleting exe file. Now I have to ask, why do you need that ?
This C code deletes it's own executable on Linux. Similar can be done in other operating systems:
int main (int argc, char ** argv) { printf ("Program called as '%s'\n", argv[0]); char resolved_path[PATH_MAX]; if (realpath (argv[0], resolved_path) == 0) { fprintf (stderr, "realpath failed: %s\n", strerror (errno)); return -1; } else { printf ("Deleting myself now...'%s'\n", resolved_path); if (unlink (resolved_path) != 0) { fprintf (stderr, "Suicide failed!: %s\n", strerror (errno)); return -1; } } return 0; }Perhaps it does and I should have been more specific. So please allow me to rephrase. On a Windows OS, EXE files cannot delete themselves.
EDIT: Or should I say, that was the case when I wrote that routine.
Sorry for being tedious about this. It's just that I haven't written anything for Windows since Windows 3.1
Understandable.
Back when I wrote that, Visual C++ 6.0, came prepackaged with InstallShield (I think that is what it was called), but I did not like the program, because it was too complicated for the simple tasks that had to be done. Back then, the hardest part to writing your own install programs, were creating shell links and internet shortcuts,
FileServices.cpp
// FileServices.cpp: implementation of the CFileServices class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ClipList.h" #include "FileServices.h" #include <tlhelp32.h> #include <intshcut.h> #include <shlwapi.h> // link to shlwapi.lib in project settings #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif BOOL CALLBACK TerminateAppEnum(HWND hwnd, LPARAM lParam) { DWORD dwID; GetWindowThreadProcessId(hwnd, &dwID); if(dwID == (DWORD)lParam) { PostMessage(hwnd, WM_CLOSE, 0, 0); } return TRUE; } CFileServices::CFileServices() { if(InitializeDirPaths_FS() == FALSE) { CString strErrorMessage; strErrorMessage += "This program"; strErrorMessage += " has experienced a runtime error" " and must be shut down"; MessageBox(NULL, strErrorMessage, "Runtime Error", MB_OK); ExitProcess(0); } } CFileServices::~CFileServices() { } BOOL CFileServices::InitializeDirPaths_FS() { BOOL bDirIniResult = TRUE; HKEY hKey; DWORD lpcbData; GetWindowsDirectory(szWindowsDir, MAX_PATH); lstrcpyn(szMainDrive, (LPCTSTR)szWindowsDir, 3); RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey); RegQueryValueEx (hKey, "ProgramFilesDir", NULL, NULL, NULL, &lpcbData); RegQueryValueEx (hKey, "ProgramFilesDir", NULL, NULL, (LPBYTE)(LPTSTR)szProgramFilesDir, &lpcbData); RegCloseKey (hKey); // This is only a few of the available folders // and the following path functions are just a few // of those which are listed in shlwapi.h SHGetSpecialFolderPath(NULL, szProgramsDir, CSIDL_PROGRAMS, 0); SHGetSpecialFolderPath(NULL, szDesktopDir, CSIDL_DESKTOPDIRECTORY, 0); SHGetSpecialFolderPath(NULL, szStartupDir, CSIDL_STARTUP, 0); SHGetSpecialFolderPath(NULL, szStartMenuDir, CSIDL_STARTMENU, 0); SHGetSpecialFolderPath(NULL, szMyDocumentsDir, CSIDL_PERSONAL, 0); SHGetSpecialFolderPath(NULL, szFavoritesDir, CSIDL_FAVORITES, 0); if(strcmp(szWindowsDir, _T("")) == 0 || strcmp(szMainDrive, _T("")) == 0 || strcmp(szProgramFilesDir, _T("")) == 0 || strcmp(szProgramsDir, _T("")) == 0 || strcmp(szDesktopDir, _T("")) == 0 || strcmp(szStartupDir, _T("")) == 0 || strcmp(szStartMenuDir, _T("")) == 0 || strcmp(szMyDocumentsDir, _T("")) == 0 || strcmp(szFavoritesDir, _T("")) == 0) { bDirIniResult = FALSE; } return bDirIniResult; } BOOL CFileServices::CopyFile_FS(LPTSTR lpExistingFileName, LPTSTR lpNewFileName, BOOL bFailIfExists) { return CopyFile((LPCTSTR)lpExistingFileName, (LPCTSTR)lpNewFileName, bFailIfExists); } BOOL CFileServices::MoveFile_FS(LPTSTR lpExistingFileName, LPTSTR lpNewFileName) { return MoveFile((LPCTSTR)lpExistingFileName, (LPCTSTR)lpNewFileName); } BOOL CFileServices::DeleteFile_FS(LPTSTR lpFileName) { return DeleteFile((LPCTSTR)lpFileName); } BOOL CFileServices::CreateDirectory_FS(LPTSTR lpszDirPath) { return CreateDirectory((LPCTSTR)lpszDirPath, NULL); } void CFileServices::DeleteDirectory_FS(LPTSTR szDirectoryPath) { SHFILEOPSTRUCT shfo; ZeroMemory(&shfo, sizeof(SHFILEOPSTRUCT)); shfo.hwnd = NULL; shfo.wFunc = FO_DELETE; shfo.lpszProgressTitle = "Deleting Files"; shfo.fFlags = FOF_SIMPLEPROGRESS | FOF_NOCONFIRMATION | FOF_NOERRORUI; shfo.pFrom = szDirectoryPath; SHFileOperation(&shfo); } BOOL CFileServices::RemoveDirectory_FS(LPTSTR lpszDirPath) { return RemoveDirectory((LPCTSTR)lpszDirPath); } LPTSTR CFileServices::PathAddBackslash_FS(LPTSTR lpszPath) { return PathAddBackslash(lpszPath); } BOOL CFileServices::PathAddExtension_FS(LPTSTR pszPath, LPCTSTR pszExtension) { return PathAddExtension(pszPath, pszExtension); } BOOL CFileServices::PathAppend_FS(LPTSTR pszPath, LPCTSTR pszMore) { return PathAppend(pszPath, pszMore); } LPTSTR CFileServices::PathRemoveBackslash_FS(LPTSTR lpszPath) { return PathRemoveBackslash(lpszPath); } BOOL CFileServices::PathFileExists_FS(LPTSTR pszPath) { return PathFileExists((LPCTSTR)pszPath); } LPTSTR CFileServices::PathGetArgs_FS(LPTSTR pszPath) { return PathGetArgs((LPCTSTR) pszPath); } BOOL CFileServices::PathIsDirectory_FS(LPTSTR pszPath) { return PathIsDirectory((LPCTSTR)pszPath); } BOOL CFileServices::PathIsFileSpec_FS(LPTSTR pszPath) { return PathIsFileSpec((LPCTSTR)pszPath); } void CFileServices::PathRemoveArgs_FS(LPTSTR pszPath) { PathRemoveArgs(pszPath); } void CFileServices::PathRemoveExtension_FS(LPTSTR pszPath) { PathRemoveExtension(pszPath); } BOOL CFileServices::PathRemoveFileSpec_FS(LPTSTR pszPath) { return PathRemoveFileSpec(pszPath); } BOOL CFileServices::PathRenameExtension_FS(LPTSTR pszPath, LPCTSTR pszExt) { return PathRenameExtension(pszPath, pszExt); } BOOL CFileServices::PathStripToRoot_FS(LPTSTR szRoot) { return PathStripToRoot(szRoot); } BOOL CFileServices::CreateShellLink_FS(LPTSTR lpszLinkFile, LPTSTR lpszLinkPath, LPTSTR lpszIconFile, UINT idIcon, LPCTSTR pszCmdLineArgs) { IShellLink *pLink = NULL; IPersistFile *pFile = NULL; HRESULT hResult = NOERROR; BOOL bResult = FALSE; WCHAR szLinkFile[MAX_PATH] = L""; if (lpszLinkFile == NULL) { SetLastError (ERROR_INVALID_PARAMETER); return FALSE; } #ifdef UNICODE lstrcpy (szLinkFile, lpszLinkFile); #else MultiByteToWideChar (CP_ACP, 0, lpszLinkFile, -1, szLinkFile, MAX_PATH); #endif hResult = CoCreateInstance (CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*) &pLink); if (FAILED(hResult)) goto done; hResult = pLink->QueryInterface (IID_IShellLink, (LPVOID*) &pLink); if (FAILED(hResult)) goto done; hResult = pLink->QueryInterface (IID_IPersistFile, (LPVOID*) &pFile); if (FAILED(hResult)) goto done; hResult = pLink->SetPath (lpszLinkPath); if (FAILED(hResult)) goto done; if(pszCmdLineArgs != _T("")) { pLink->SetArguments (pszCmdLineArgs); } if (lpszIconFile) { hResult = pLink->SetIconLocation (lpszIconFile, idIcon); } hResult = pFile->Save (szLinkFile, TRUE); if (FAILED(hResult)) goto done; bResult = TRUE; done: if (pFile) { pFile->Release(); pFile = NULL; } if (pLink) { pLink->Release(); pLink = NULL; } SetLastError ((DWORD)hResult); return bResult; } BOOL CFileServices::CreateInternetShortcut_FS(LPTSTR lpszLinkFile, LPCTSTR lpszURL, LPTSTR lpszIconFile, UINT idIcon) { IUniformResourceLocator *pURL = NULL; IShellLink *pLink = NULL; IPersistFile *pFile = NULL; HRESULT hResult = NOERROR; BOOL bResult = FALSE; WCHAR szLinkFile[MAX_PATH] = L""; if (lpszURL == NULL || lpszLinkFile == NULL) { SetLastError (ERROR_INVALID_PARAMETER); return FALSE; } #ifdef UNICODE lstrcpy (szLinkFile, lpszLinkFile); #else MultiByteToWideChar (CP_ACP, 0, lpszLinkFile, -1, szLinkFile, MAX_PATH); #endif hResult = CoCreateInstance (CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, IID_IUniformResourceLocator, (LPVOID*)&pURL); if (FAILED(hResult)) goto done; hResult = pURL->QueryInterface (IID_IShellLink, (LPVOID*) &pLink); if (FAILED(hResult)) goto done; hResult = pURL->QueryInterface (IID_IPersistFile, (LPVOID*) &pFile); if (FAILED(hResult)) goto done; hResult = pURL->SetURL (lpszURL, IURL_SETURL_FL_GUESS_PROTOCOL); if (FAILED(hResult)) goto done; if (lpszIconFile) { hResult = pLink->SetIconLocation (lpszIconFile, idIcon); } hResult = pFile->Save (szLinkFile, TRUE); if (FAILED(hResult)) goto done; bResult = TRUE; done: if (pFile) { pFile->Release(); pFile = NULL; } if (pLink) { pLink->Release(); pLink = NULL; } if (pURL) { pURL->Release(); pURL = NULL; } SetLastError ((DWORD)hResult); return bResult; } void CFileServices::WriteIconResourceFromExe_FS(UINT idIcon, LPTSTR szPath) { LPICONRESOURCE lpIR; LPMEMICONDIR lpIcon; LPICONIMAGE lpImage; HRSRC hRsrc; HGLOBAL hGlobal; HANDLE hFile; UINT i; UINT nIndex; UINT nNumEntries; DWORD dwBytesWrittenOne; DWORD dwSize; DWORD dwBytesWrittenTwo; WORD Output; hRsrc = FindResource(NULL, (LPTSTR)idIcon, RT_GROUP_ICON); hGlobal = LoadResource(NULL, hRsrc); lpIcon = (LPMEMICONDIR)LockResource(hGlobal); lpIR = (LPICONRESOURCE)malloc(sizeof(ICONRESOURCE) + ((lpIcon->idCount-1) * sizeof(ICONIMAGE))); lpIR->nNumImages = lpIcon->idCount; for (i = 0; i < lpIR->nNumImages; i++) { hRsrc = FindResource(NULL, MAKEINTRESOURCE(lpIcon->idEntries[i].nID), RT_ICON); hGlobal = LoadResource(NULL, hRsrc); lpIR->IconImages[i].dwNumBytes = SizeofResource (NULL, hRsrc); lpIR->IconImages[i].lpBits = (LPBYTE)malloc( lpIR->IconImages[i].dwNumBytes); memcpy (lpIR->IconImages[i].lpBits, LockResource (hGlobal), lpIR->IconImages[i].dwNumBytes); lpImage = &(lpIR->IconImages[i]); lpImage->lpbi = (LPBITMAPINFO)lpImage->lpBits; lpImage->Width = lpImage->lpbi->bmiHeader.biWidth; lpImage->Height = (lpImage->lpbi->bmiHeader.biHeight) / 2; lpImage->Colors = lpImage->lpbi->bmiHeader.biPlanes * lpImage->lpbi->bmiHeader.biBitCount; } hFile = CreateFile( szPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); nNumEntries = lpIR->nNumImages; Output = 0; WriteFile( hFile, &Output, sizeof(WORD), &dwBytesWrittenTwo, NULL); Output = 1; WriteFile( hFile, &Output, sizeof(WORD), &dwBytesWrittenTwo, NULL); Output = (WORD)nNumEntries; WriteFile( hFile, &Output, sizeof(WORD), &dwBytesWrittenTwo, NULL); for( i=0; i<lpIR->nNumImages; i++ ) { ICONDIRENTRY ide; ide.bWidth = lpIR->IconImages[i].Width; ide.bHeight = lpIR->IconImages[i].Height; ide.bReserved = 0; ide.wPlanes = lpIR->IconImages[i].lpbi->bmiHeader.biPlanes; ide.wBitCount = lpIR->IconImages[i].lpbi->bmiHeader.biBitCount; if( (ide.wPlanes * ide.wBitCount) >= 8) ide.bColorCount = 0; else ide.bColorCount = 1 << (ide.wPlanes * ide.wBitCount); ide.dwBytesInRes = lpIR->IconImages[i].dwNumBytes; dwSize = 3 * sizeof(WORD); dwSize += lpIR->nNumImages * sizeof(ICONDIRENTRY); nIndex = i; for(i=0; i<nIndex; i++) dwSize += lpIR->IconImages[i].dwNumBytes; ide.dwImageOffset = dwSize; WriteFile( hFile, &ide, sizeof(ICONDIRENTRY), &dwBytesWrittenOne, NULL); } for( i=0; i<lpIR->nNumImages; i++ ) { DWORD dwTemp = lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage; lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage = 0; WriteFile( hFile, lpIR->IconImages[i].lpBits, lpIR->IconImages[i].dwNumBytes, &dwBytesWrittenOne, NULL); lpIR->IconImages[i].lpbi->bmiHeader.biSizeImage = dwTemp; } CloseHandle( hFile ); UnlockResource(hGlobal); FreeResource(hGlobal); for (i = 0; i < lpIR->nNumImages; i++) { free (lpIR->IconImages[i].lpBits); } free (lpIR); } void CFileServices::WriteBitmapResourceFromExe_FS(UINT idBitmap, LPTSTR szPath) { HANDLE hFile; BITMAPFILEHEADER bmfh; HRSRC hRsrc; HGLOBAL hGlobal; PBITMAPINFO pbmi; DWORD dwBytesWritten; hRsrc = FindResource(NULL, (LPSTR)idBitmap, RT_BITMAP); hGlobal = LoadResource(NULL, hRsrc); pbmi = (PBITMAPINFO)LockResource(hGlobal); hFile = CreateFile(szPath, GENERIC_READ | GENERIC_WRITE, (DWORD)0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_ARCHIVE, (HANDLE)NULL); bmfh.bfOffBits = 1078; bmfh.bfType = 0x4d42; bmfh.bfSize = pbmi->bmiHeader.biSizeImage + bmfh.bfOffBits; bmfh.bfReserved1 = 0; bmfh.bfReserved2 = 0; WriteFile(hFile, &bmfh, sizeof(BITMAPFILEHEADER), (LPDWORD)&dwBytesWritten, NULL); WriteFile(hFile, pbmi, pbmi->bmiHeader.biSizeImage + bmfh.bfOffBits - sizeof(BITMAPFILEHEADER), (LPDWORD)&dwBytesWritten, NULL); CloseHandle(hFile); UnlockResource(hGlobal); FreeResource(hGlobal); } void CFileServices::WriteCustomResourceFromExe_FS(UINT idCustom, LPCTSTR lpszCustomType, LPTSTR szPath, BOOL bBinary) { HMODULE hModule; HRSRC hRsrc; HGLOBAL hGlobal; BYTE* pBytes; DWORD dwLength; FILE* fOutput; hModule = GetModuleHandle(NULL); hRsrc = FindResource(hModule, MAKEINTRESOURCE(idCustom), lpszCustomType); hGlobal = LoadResource(hModule, hRsrc); pBytes = (BYTE*) LockResource(hGlobal); dwLength = SizeofResource(hModule, hRsrc); if(bBinary == TRUE) { fOutput = fopen(szPath, "wb"); } else { fOutput = fopen(szPath, "wt"); } fwrite(pBytes, 1, dwLength, fOutput); fclose(fOutput); UnlockResource(hGlobal); FreeResource(hGlobal); } BOOL CFileServices::CloseAppNow(LPTSTR szRunningApp) { // Enumerate and terminate all processes named szRunningApp. This code calls // the TerminateProcess API, which is usually not recommended. We must // use this here, however, because Explorer's auto-restart will cause // logoff problems. HINSTANCE hInstLib; HANDLE hSnapShot; PROCESSENTRY32 procentry; BOOL bFlag; BOOL bAppIsRunning = FALSE; // ToolHelp function pointers. HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD); BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32); BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32); hInstLib = LoadLibraryA("Kernel32.DLL"); if(hInstLib == NULL) { return FALSE; } // Get procedure addresses. // We are linking to these functions of Kernel32 // explicitly, because otherwise a module using // this code would fail to load under Windows NT, // which does not have the Toolhelp32 // functions in the Kernel 32. lpfCreateToolhelp32Snapshot= (HANDLE(WINAPI *)(DWORD,DWORD)) GetProcAddress(hInstLib, "CreateToolhelp32Snapshot"); lpfProcess32First= (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) GetProcAddress(hInstLib, "Process32First"); lpfProcess32Next= (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32)) GetProcAddress(hInstLib, "Process32Next"); if(lpfProcess32Next == NULL || lpfProcess32First == NULL || lpfCreateToolhelp32Snapshot == NULL) { FreeLibrary(hInstLib); return FALSE; } // Get a handle to a ToolHelp snapshot of the systems // processes. hSnapShot = lpfCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hSnapShot == INVALID_HANDLE_VALUE) { FreeLibrary(hInstLib); return FALSE; } // Get the first process's information. procentry.dwSize = sizeof(PROCESSENTRY32); bFlag = lpfProcess32First(hSnapShot, &procentry); // While there are processes, keep looping. while(bFlag) { { // We need to see if the app were looking for is executing HANDLE hProcess; INT nPos; nPos = lstrlen(procentry.szExeFile); if(nPos) { while (procentry.szExeFile[--nPos] != '\\'); if(!lstrcmpi(szRunningApp,&(procentry.szExeFile[nPos+1]))) { // Terminate the process. hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE, procentry.th32ProcessID); EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)procentry.th32ProcessID); if(WaitForSingleObject(hProcess, 600) != WAIT_OBJECT_0) { TerminateProcess(hProcess, 1); } CloseHandle(hProcess); bAppIsRunning = TRUE; } } } procentry.dwSize = sizeof(PROCESSENTRY32); bFlag = lpfProcess32Next(hSnapShot, &procentry); } CloseHandle(hSnapShot); // Free the library. FreeLibrary(hInstLib); if(bAppIsRunning == TRUE) { return TRUE; } else { return 0; } }FileServices.h
// FileServices.h: interface for the CFileServices class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_FILESERVICES_H__5DBE30E0_89CF_11D7_A72F_A35BBEF5307B__INCLUDED_) #define AFX_FILESERVICES_H__5DBE30E0_89CF_11D7_A72F_A35BBEF5307B__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 ////////////////////////////////////////////////////////////////////// #define SETPOINT(pt, h, v) { (pt).x=h; (pt).y=v; } #pragma pack(push) #pragma pack(2) typedef struct { BYTE bWidth; BYTE bHeight; BYTE bColorCount; BYTE bReserved; WORD wPlanes; WORD wBitCount; DWORD dwBytesInRes; WORD nID; } MEMICONDIRENTRY, *LPMEMICONDIRENTRY; typedef struct { WORD idReserved; WORD idType; WORD idCount; MEMICONDIRENTRY idEntries[1]; } MEMICONDIR, *LPMEMICONDIR; #pragma pack(pop) typedef struct { BYTE bWidth; BYTE bHeight; BYTE bColorCount; BYTE bReserved; WORD wPlanes; WORD wBitCount; DWORD dwBytesInRes; DWORD dwImageOffset; } ICONDIRENTRY, *LPICONDIRENTRY; typedef struct { UINT Width; UINT Height; UINT Colors; LPBYTE lpBits; DWORD dwNumBytes; LPBITMAPINFO lpbi; LPBYTE lpXOR; LPBYTE lpAND; } ICONIMAGE, *LPICONIMAGE; typedef struct { UINT nNumImages; ICONIMAGE IconImages[1]; } ICONRESOURCE, *LPICONRESOURCE; typedef struct { CStringList* strList; WINDOWPLACEMENT wndpl; } MYCUSTOMDATA, *LPMYCUSTOMDATA; ////////////////////////////////////////////////////////////////////// class CFileServices { public: TCHAR szWindowsDir[MAX_PATH]; TCHAR szMainDrive[MAX_PATH]; TCHAR szProgramFilesDir[MAX_PATH]; TCHAR szProgramsDir[MAX_PATH]; TCHAR szDesktopDir[MAX_PATH]; TCHAR szStartupDir[MAX_PATH]; TCHAR szStartMenuDir[MAX_PATH]; TCHAR szMyDocumentsDir[MAX_PATH]; TCHAR szFavoritesDir[MAX_PATH]; BOOL CloseAppNow(LPTSTR szRunningApp); BOOL PathStripToRoot_FS(LPTSTR szRoot); BOOL PathRenameExtension_FS(LPTSTR pszPath, LPCTSTR pszExt); BOOL PathRemoveFileSpec_FS(LPTSTR pszPath); void PathRemoveExtension_FS(LPTSTR pszPath); void PathRemoveArgs_FS(LPTSTR pszPath); BOOL PathIsFileSpec_FS(LPTSTR pszPath); BOOL PathIsDirectory_FS(LPTSTR pszPath); LPTSTR PathGetArgs_FS(LPTSTR pszPath); BOOL PathFileExists_FS(LPTSTR pszPath); BOOL PathAddExtension_FS(LPTSTR pszPath, LPCTSTR pszExtension); BOOL MoveFile_FS(LPTSTR lpExistingFileName, LPTSTR lpNewFileName); BOOL CopyFile_FS(LPTSTR lpExistingFileName, LPTSTR lpNewFileName, BOOL bFailIfExists); BOOL RemoveDirectory_FS(LPTSTR lpszDirPath); BOOL PathAppend_FS(LPTSTR pszPath, LPCTSTR pszMore); LPTSTR PathRemoveBackslash_FS(LPTSTR lpszPath); LPTSTR PathAddBackslash_FS(LPTSTR lpszPath); BOOL DeleteFile_FS(LPTSTR lpFileName); void DeleteDirectory_FS(LPTSTR szDirectoryPath); BOOL CreateDirectory_FS(LPTSTR lpszDirPath); BOOL InitializeDirPaths_FS(); void WriteIconResourceFromExe_FS(UINT idIcon, LPTSTR szPath); void WriteBitmapResourceFromExe_FS(UINT idBitmap, LPTSTR szPath); void WriteCustomResourceFromExe_FS(UINT idCustom, LPCTSTR lpszCustomType, LPTSTR szPath, BOOL bBinary); BOOL CreateInternetShortcut_FS(LPTSTR lpszLinkFile, LPCTSTR lpszURL, LPTSTR lpszIconFile, UINT idIcon); BOOL CreateShellLink_FS(LPTSTR lpszLinkFile, LPTSTR lpszLinkPath, LPTSTR lpszIconFile, UINT idIcon, LPCTSTR pszCmdLineArgs); CFileServices(); virtual ~CFileServices(); }; #endif // !defined(AFX_FILESERVICES_H__5DBE30E0_89CF_11D7_A72F_A35BBEF5307B__INCLUDED_)