local funcion definitions are illegal =(

This topic is 4790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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);

return  (   dwCode);
}

void CStarCraftRegisterDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

Share on other sites
   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

Share on other sites
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

Share on other sites
^^... 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!

Share on other sites
The error is telling you exactly what the problem is. "Local function defenitions are illegal" == "You can't put one function inside another".

Share on other sites
Exactly like my man above me says, you can't have a function inside a functon, it aint kosher dude!

ace

Share on other sites
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?

Share on other sites
Just put the function above the calling function, is there any problem with that?

ace

Share on other sites
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?

Share on other sites
Yeah i did understand. So it is working now?

ace

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633759
• Total Posts
3013720
×