local funcion definitions are illegal =(

Started by
16 comments, last by Tim Cowley 18 years, 5 months ago
I've read similar posts but i don't think it's a } { thing... I've downloaded this code from somewhere but it jumps me the error previously said and i get nervous :mad: This error jumps at the second line, at the { but i don't know what's the problem :(...
DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd)
{
   STARTUPINFO         si;
   PROCESS_INFORMATION pi;

   BOOL                bRes;

   DWORD               dwCode  =   0;

   MSG                 msg;

   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

   si.cb           =   sizeof  (   STARTUPINFO);
   si.dwFlags      =   STARTF_USESHOWWINDOW;
   si.wShowWindow  =   SW_SHOWNORMAL;

   bRes		=   CreateProcess   (   NULL,
                                   pszCmd,
                                   NULL,
                                   NULL,
                                   TRUE,
                                   NORMAL_PRIORITY_CLASS,
                                   NULL,
                                   NULL,
                                   &si,
                                   π
                               );

   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,
                                                                   &pi.hProcess,
                                                                   FALSE,
                                                                   INFINITE,
                                                                   QS_ALLINPUT
                                                               )
           )
           {
               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))
                       {
                           DispatchMessage     (   &msg);
                       }
           }

   GetExitCodeProcess  (   pi.hProcess,    &dwCode);

   CloseHandle (   pi.hProcess);
   CloseHandle (   pi.hThread);

   return  (   dwCode);
}	

void CStarCraftRegisterDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}
Advertisement
   return  (   dwCode);}		return TRUE;  // return TRUE  unless you set the focus to a control}


This bit is wrong, you have two returns and therefore a spare closing brace.

ace
the following from your code seems to be a syntax error

:

return TRUE; // return TRUE unless you set the focus to a control
}

:

remove it.
Just return one thing per function
^^... That's Because I Inserted It On The InitDialog Of A MFC Application... A Little Longer It Looks Like This...

BOOL CStarCraftRegisterDlg::OnInitDialog(){	CDialog::OnInitDialog();	// Add "About..." menu item to system menu.	// IDM_ABOUTBOX must be in the system command range.	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);	ASSERT(IDM_ABOUTBOX < 0xF000);	CMenu* pSysMenu = GetSystemMenu(FALSE);	if (pSysMenu != NULL)	{		CString strAboutMenu;		strAboutMenu.LoadString(IDS_ABOUTBOX);		if (!strAboutMenu.IsEmpty())		{			pSysMenu->AppendMenu(MF_SEPARATOR);			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);		}	}	// Set the icon for this dialog.  The framework does this automatically	//  when the application's main window is not a dialog	SetIcon(m_hIcon, TRUE);			// Set big icon	SetIcon(m_hIcon, FALSE);		// Set small icon	DWORD ExecuteAndWaitForCompletion   (   LPSTR   pszCmd){   STARTUPINFO         si;   PROCESS_INFORMATION pi;   BOOL                bRes;   DWORD               dwCode  =   0;   MSG                 msg;   ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));   si.cb           =   sizeof  (   STARTUPINFO);   si.dwFlags      =   STARTF_USESHOWWINDOW;   si.wShowWindow  =   SW_SHOWNORMAL;   bRes		=   CreateProcess   (   NULL,                                   pszCmd,                                   NULL,                                   NULL,                                   TRUE,                                   NORMAL_PRIORITY_CLASS,                                   NULL,                                   NULL,                                   &si,                                   π                               );   while   (   WAIT_OBJECT_0   !=  MsgWaitForMultipleObjects   (   1,                                                                   &pi.hProcess,                                                                   FALSE,                                                                   INFINITE,                                                                   QS_ALLINPUT                                                               )           )           {               while   (   PeekMessage (   &msg,   NULL,   0,  0,  PM_REMOVE))                       {                           DispatchMessage     (   &msg);                       }           }   GetExitCodeProcess  (   pi.hProcess,    &dwCode);   CloseHandle (   pi.hProcess);   CloseHandle (   pi.hThread);   return  (   dwCode);}		return TRUE;  // return TRUE  unless you set the focus to a control}


If you can give me a better way to this i would really aprecciate it, don't treat me as a mothafVck@ useless programmer... i want to be a big one when i get older... i see that you're answering really fast... i love u people... you are really helpful!
The error is telling you exactly what the problem is. "Local function defenitions are illegal" == "You can't put one function inside another".
Exactly like my man above me says, you can't have a function inside a functon, it aint kosher dude!

ace
I Get It... That's Why The => { <= Thingy... When you forgot one it "assimilates" to the next door function... thanks man ^^... but i mean... where could i insert this piece of code?
Just put the function above the calling function, is there any problem with that?

ace
Let me exply you the following... i just discovered which was the problem... i thought that i had to "run" it but this code was making the command that i had to run so i though that i had to put it like OnInitDialog... but i just had to put it alone and another line where i put before the full code:
ExecuteAndWaitForCompletion ( "notepad.exe");

i really love you people ^^

PD.: Did You UnderStand My Explanation?
Yeah i did understand. So it is working now?

ace

This topic is closed to new replies.

Advertisement