Sign in to follow this  
JuliaN91

local funcion definitions are illegal =(

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
^^... 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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this