Click here to Skip to main content
16,011,680 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Serialization Pin
Demian Panello15-Apr-04 4:43
Demian Panello15-Apr-04 4:43 
GeneralRe: Serialization Pin
Ravi Bhavnani16-Apr-04 3:05
professionalRavi Bhavnani16-Apr-04 3:05 
GeneralVS C++ Standard Edition and shareware Pin
Franc Morales12-Apr-04 8:16
Franc Morales12-Apr-04 8:16 
GeneralRe: VS C++ Standard Edition and shareware Pin
Ravi Bhavnani12-Apr-04 9:04
professionalRavi Bhavnani12-Apr-04 9:04 
Generalexecute an app from code Pin
BlackDice12-Apr-04 7:58
BlackDice12-Apr-04 7:58 
GeneralRe: execute an app from code Pin
T1TAN12-Apr-04 8:15
T1TAN12-Apr-04 8:15 
GeneralRe: execute an app from code Pin
BlackDice12-Apr-04 8:44
BlackDice12-Apr-04 8:44 
GeneralRe: execute an app from code Pin
Ed K12-Apr-04 8:34
Ed K12-Apr-04 8:34 
Don't remember where I picked this up but most likely somewhere here...Best site around!!

BOOL LaunchChild(LPCSTR lpszCmdLine, BOOL bShowChildWindow)
{
	HANDLE hProcess = ::GetCurrentProcess();
	
	PROCESS_INFORMATION pi;
	
	// Set up the start up info struct.
	STARTUPINFO si;
	::ZeroMemory(&si, sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);
	si.dwFlags = STARTF_USESHOWWINDOW;
	// Note that dwFlags must include STARTF_USESHOWWINDOW to
	// use the wShowWindow flags.
	si.wShowWindow = bShowChildWindow ? SW_SHOW: SW_HIDE;
	
	// Create the NULL security token for the process
	LPVOID lpSD = NULL;
	LPSECURITY_ATTRIBUTES lpSA = NULL;
	
	lpSD = ::GlobalAlloc(GPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
	::InitializeSecurityDescriptor(lpSD, SECURITY_DESCRIPTOR_REVISION);
	::SetSecurityDescriptorDacl(lpSD, -1, 0, 0);
	
	lpSA = (LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR, sizeof(SECURITY_ATTRIBUTES));
	lpSA->nLength = sizeof(SECURITY_ATTRIBUTES);
	lpSA->lpSecurityDescriptor = lpSD;
	lpSA->bInheritHandle = TRUE;
	
	// Try to spawn the process.
	BOOL bResult = ::CreateProcess(NULL, (LPTSTR)(LPCTSTR)lpszCmdLine, lpSA, NULL, TRUE,
		CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
	
	// Cleanup memory allocation
	if (lpSA != NULL)
		::GlobalFree(lpSA);
	if (lpSD != NULL)
		::GlobalFree(lpSD);
	
	// Return if an error occurs.
	if (!bResult) return FALSE;
	
	// Close the handles to reduce kernal usage count
	::CloseHandle(pi.hThread);
	::CloseHandle(pi.hProcess);
	
	// return true
	return bResult;	
}


Just pass in the command line and whether or not you want the console window displayed.

Thanks to whomever submitted this!

ed

The absence of evidence is not evidence of absence.
GeneralRe: execute an app from code Pin
BlackDice12-Apr-04 8:45
BlackDice12-Apr-04 8:45 
GeneralRe: execute an app from code Pin
Snyp12-Apr-04 11:26
Snyp12-Apr-04 11:26 
GeneralRe: execute an app from code Pin
Tim Smith12-Apr-04 18:21
Tim Smith12-Apr-04 18:21 
QuestionASSERT_VALID ? Pin
Jnewg512-Apr-04 7:13
Jnewg512-Apr-04 7:13 
AnswerRe: ASSERT_VALID ? Pin
Anthony_Yio13-Apr-04 0:21
Anthony_Yio13-Apr-04 0:21 
GeneralCWinThread "issues" Pin
T1TAN12-Apr-04 6:59
T1TAN12-Apr-04 6:59 
GeneralRe: CWinThread "issues" Pin
John M. Drescher12-Apr-04 8:18
John M. Drescher12-Apr-04 8:18 
GeneralRe: CWinThread "issues" Pin
T1TAN12-Apr-04 8:53
T1TAN12-Apr-04 8:53 
GeneralRe: CWinThread "issues" Pin
John M. Drescher12-Apr-04 8:58
John M. Drescher12-Apr-04 8:58 
GeneralRe: CWinThread "issues" Pin
T1TAN12-Apr-04 9:17
T1TAN12-Apr-04 9:17 
GeneralRe: CWinThread "issues" Pin
John M. Drescher12-Apr-04 9:33
John M. Drescher12-Apr-04 9:33 
GeneralRe: CWinThread "issues" Pin
T1TAN12-Apr-04 9:41
T1TAN12-Apr-04 9:41 
GeneralRe: CWinThread "issues" Pin
John M. Drescher12-Apr-04 10:36
John M. Drescher12-Apr-04 10:36 
GeneralRe: CWinThread "issues" Pin
dreamerzz18-Apr-04 0:07
dreamerzz18-Apr-04 0:07 
GeneralRe: CWinThread "issues" Pin
John M. Drescher18-Apr-04 18:13
John M. Drescher18-Apr-04 18:13 
GeneralRe: CWinThread "issues" Pin
dreamerzz20-Apr-04 2:15
dreamerzz20-Apr-04 2:15 
GeneralRe: CWinThread "issues" Pin
John M. Drescher20-Apr-04 4:28
John M. Drescher20-Apr-04 4:28 

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.