• Advertisement
Sign in to follow this  

local funcion definitions are illegal =(

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

If you intended to correct an error in the post then please contact us.

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

Share this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Yes It Is... I Love You Man... By The Way... :D... I've Just Formatted And I Don't Have The Acrobat Reader To Read My Guides... :p... I Mean... Which Was The Command To Run A Program... Not Using The Shell Please :)...

Share this post


Link to post
Share on other sites
There is a function for windows called CreateProcess(), its complicated but the only other way i know of is to use system( [command] ).

ace

Share this post


Link to post
Share on other sites
I Mean One That You Put Something Like

Run(".\\file.exe");

Well... That's Why I'm Needing It To Be From The Program... The Program Won't Know In Which Directory He Is.

AnyWay... May I Do The Same With The Create Process?... May You Tell Me How?... Should I Start A New Thread? :D.

Share this post


Link to post
Share on other sites
>AnyWay... May I Do The Same With The Create Process?...
>May You Tell Me How?... Should I Start A New Thread? :D.

No need to start a new thread, the other posters already gave
you info about what function to use - google for it first and
get some information - or look on msdn.microsoft.com.

If you can't get it to work, _then_ start a new thread where
you give as much info as possible, so we can help you.

Regards

Share this post


Link to post
Share on other sites
But You Can't Use .\\ ... Well I Think... I Should Test :P...
It's Prettier Capitalizing EveryOne :)... Including The Ones Combo... Like "EveryOne".. :D...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement