Click here to Skip to main content
15,885,278 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: random access iterator Pin
George_George2-Mar-08 14:09
George_George2-Mar-08 14:09 
Questioncreating windows services using MFC\c++ Pin
AmitCohen2221-Mar-08 19:13
AmitCohen2221-Mar-08 19:13 
GeneralRe: creating windows services using MFC\c++ Pin
Hamid_RT1-Mar-08 19:50
Hamid_RT1-Mar-08 19:50 
AnswerRe: creating windows services using MFC\c++ Pin
AmitCohen2222-Mar-08 3:22
AmitCohen2222-Mar-08 3:22 
GeneralRe: creating windows services using MFC\c++ Pin
Hamid_RT2-Mar-08 4:51
Hamid_RT2-Mar-08 4:51 
QuestionSuperImposing text over video? Pin
Chandrasekharan P1-Mar-08 18:17
Chandrasekharan P1-Mar-08 18:17 
AnswerRe: SuperImposing text over video? Pin
Mark Salsbery1-Mar-08 18:46
Mark Salsbery1-Mar-08 18:46 
QuestionA program which can delete itself Pin
zengkun1001-Mar-08 18:12
zengkun1001-Mar-08 18:12 
Many years ago, Jeffrey Richter wrote a program to show how to delete a program itself when it was closed. It sounds very funny, and I tried this program yesterday. I saidly found that the program does deleted but the temp file still exist. It seems that FILE_FLAG_DELETE_ON_CLOSE flag doesn't work on a exe file.
Here is the source code.Any one knowns why the temp file doesn't get deleted? Sigh | :sigh:

int WINAPI _tWinMain(HINSTANCE h, HINSTANCE b, LPTSTR psz, int n)<br />
{<br />
	// Is this the Original EXE or the clone EXE?<br />
	// If the command-line 1 argument, this is the Original EXE<br />
	// If the command-line >1 argument, this is the clone EXE<br />
	if (__argc == 1) <br />
	{<br />
		// Original EXE: Spawn clone EXE to delete this EXE<br />
		// Copy this EXEcutable image into the user''s temp directory<br />
		TCHAR szPathOrig[_MAX_PATH], szPathClone[_MAX_PATH];<br />
		GetModuleFileName(NULL, szPathOrig, _MAX_PATH);<br />
		GetTempPath(_MAX_PATH, szPathClone);<br />
		GetTempFileName(szPathClone, __TEXT("Del"), 0, szPathClone);<br />
		CopyFile(szPathOrig, szPathClone, FALSE);<br />
		// Open the clone EXE using FILE_FLAG_DELETE_ON_CLOSE<br />
		HANDLE hfile = CreateFile(szPathClone, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);<br />
		// Spawn the clone EXE passing it our EXE''s process handle<br />
		// and the full path name to the Original EXE file.<br />
		TCHAR szCmdLine[512];<br />
		HANDLE hProcessOrig = OpenProcess(SYNCHRONIZE, TRUE, GetCurrentProcessId());<br />
		wsprintf(szCmdLine, __TEXT("%s %d \"%s\""), szPathClone, hProcessOrig, szPathOrig);<br />
		STARTUPINFO si;<br />
		ZeroMemory(&si, sizeof(si));<br />
		si.cb = sizeof(si);<br />
		PROCESS_INFORMATION pi;<br />
		CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);<br />
		CloseHandle(hProcessOrig);<br />
		CloseHandle(hfile);<br />
		// This original process can now terminate.<br />
	}<br />
	else<br />
	{<br />
		// Clone EXE: When original EXE terminates, delete it<br />
		HANDLE hProcessOrig = (HANDLE) _ttoi(__targv[1]);<br />
		WaitForSingleObject(hProcessOrig, INFINITE);<br />
		CloseHandle(hProcessOrig);<br />
		DeleteFile(__targv[2]);<br />
		// Insert code here to remove the subdirectory too (if desired).<br />
		// The system will delete the clone EXE automatically<br />
		// because it was opened with FILE_FLAG_DELETE_ON_CLOSE<br />
	}<br />
	return(0);<br />
}


A Chinese VC++ programmer

GeneralRe: A program which can delete itself Pin
Hamid_RT1-Mar-08 19:58
Hamid_RT1-Mar-08 19:58 
GeneralRe: A program which can delete itself Pin
zengkun1001-Mar-08 21:15
zengkun1001-Mar-08 21:15 
GeneralRe: A program which can delete itself Pin
Hamid_RT2-Mar-08 4:48
Hamid_RT2-Mar-08 4:48 
QuestionIs it possible to create /delete a new user/group using win32 apis Pin
vineeshV1-Mar-08 6:12
vineeshV1-Mar-08 6:12 
GeneralRe: Is it possible to create /delete a new user/group using win32 apis Pin
Mark Salsbery1-Mar-08 8:12
Mark Salsbery1-Mar-08 8:12 
GeneralRe: Is it possible to create /delete a new user/group using win32 apis Pin
vineeshV1-Mar-08 8:58
vineeshV1-Mar-08 8:58 
GeneralRe: Is it possible to create /delete a new user/group using win32 apis Pin
zengkun1001-Mar-08 21:17
zengkun1001-Mar-08 21:17 
Generalfloat overflow Pin
FredrickNorge1-Mar-08 5:13
FredrickNorge1-Mar-08 5:13 
GeneralRe: float overflow Pin
Luc Pattyn1-Mar-08 15:33
sitebuilderLuc Pattyn1-Mar-08 15:33 
QuestionInterfacing webcam to C++ program to manipulate the images in real time Pin
look4star29-Feb-08 21:45
look4star29-Feb-08 21:45 
GeneralRe: Interfacing webcam to C++ program to manipulate the images in real time Pin
Amar Sutar1-Mar-08 0:40
Amar Sutar1-Mar-08 0:40 
Questionhow to create a new process in c Pin
prasadbuddhika29-Feb-08 21:40
prasadbuddhika29-Feb-08 21:40 
AnswerRe: how to create a new process in c Pin
Gary R. Wheeler1-Mar-08 0:55
Gary R. Wheeler1-Mar-08 0:55 
AnswerRe: how to create a new process in c Pin
Dave Calkins1-Mar-08 3:34
Dave Calkins1-Mar-08 3:34 
AnswerRe: how to create a new process in c Pin
CPallini1-Mar-08 4:19
mveCPallini1-Mar-08 4:19 
GeneralError!! Pin
rowdy_vc++29-Feb-08 20:27
rowdy_vc++29-Feb-08 20:27 
GeneralRe: Error!! Pin
Michael Schubert29-Feb-08 20:44
Michael Schubert29-Feb-08 20:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.