472,331 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

Running a process

I've written a C program that I want to run inside an Gui wrapper that
I started to write in MFC. I have to select some files then kick off a
process running the C program. I have the initial dialog file
selection stuff written, but am not sure how to run the C program
inside a seperate thread. I'm using VS.NET 2003 and am trying to use
the Thread and Process objects, but am not sure if I can use that with
MFC. I can't compile the code I have because I get some compiler
errors...

TAD2H5TDTestGui.cpp(57): error C3828: 'System::Diagnostics::Process':
placement arguments not allowed while creating instances of managed
classes.
TAD2H5TDTestGui.cpp(148): error C3828:
'System::Threading::ThreadStart': placement arguments not allowed while
creating instances of managed classes.
TAD2H5TDTestGui.cpp(149): error C3828: 'System::Threading::Thread':
placement arguments not allowed while creating instances of managed
classes.

I looked up what placement arguments are in the documentation, but
found that I don't have any in the code. Here's the code with the line
numbers marked that have the errors. I've include both the header and
the source file, where the errors are.

////////////////////////////////////////////////////////////
// TAD2H5TDTestGui.h : main header file for the application
////////////////////////////////////////////////////////////

#pragma once

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include <string>
#include "resource.h" // main symbols

using std::string;

// CTAD2H5TDTestGuiApp:
// See TAD2H5TDTestGui.cpp for the implementation of this class
//

class CTAD2H5TDTestGuiApp : public CWinApp
{
public:

CTAD2H5TDTestGuiApp();
static void ProcessRunner();

// Overrides
public:
virtual BOOL InitInstance();

// Implementation
DECLARE_MESSAGE_MAP()
};

extern CTAD2H5TDTestGuiApp theApp;

////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////
// TAD2H5TDTestGui.cpp : Defines the class behaviors for the app.
////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TAD2H5TDTestGui.h"
#include "TAD2H5TDTestGuiDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Threading;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// CTAD2H5TDTestGuiApp

BEGIN_MESSAGE_MAP(CTAD2H5TDTestGuiApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

// The one and only CTAD2H5TDTestGuiApp object

CTAD2H5TDTestGuiApp theApp;
CString fileType = "";
CString openFile = "";
CString saveFile = "";
// CTAD2H5TDTestGuiApp construction

CTAD2H5TDTestGuiApp::CTAD2H5TDTestGuiApp(){
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

void CTAD2H5TDTestGuiApp::ProcessRunner() {
CString commandStr;

if (fileType == "hdf5") {
commandStr = "c:\\hdf5\\tad2h5td\\tad2h5td.exe";
} else {
commandStr = "c:\\matlab\\tad2matlab\\tad2matlab.exe";
}
commandStr = commandStr + " " + openFile + " " + saveFile + " -bs
50000";

TRACE("\n" + commandStr + "\n\n");

// M *m1 = new M();
----> Line 57 <----<<< Process *myProcess = new Process();
try {
myProcess->StartInfo->FileName = commandStr;

myProcess->StartInfo->UseShellExecute = false;
myProcess->StartInfo->RedirectStandardOutput = true;

myProcess->Start();

Console::WriteLine(myProcess->StandardOutput->ReadToEnd());

myProcess->WaitForExit();

} catch (Win32Exception *e) {
if(e->NativeErrorCode == ERROR_ACCESS_DENIED) {
Console::WriteLine(S"{0}. You don't have permission to access this
file.",e->Message);

}
}
}

// CTAD2H5TDTestGuiApp initialization

BOOL CTAD2H5TDTestGuiApp::InitInstance()
{
// InitCommonControls() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
InitCommonControls();

CWinApp::InitInstance();

AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

CTAD2H5TDTestGuiDlg* openDlg = new CTAD2H5TDTestGuiDlg(TRUE,NULL) ;
// m_pMainWnd = openDlg;
INT_PTR nResponse = openDlg->DoModal();
if (nResponse == IDOK) {

// TODO: Place code here to handle when the dialog is
// dismissed with OK
openFile = openDlg->GetPathName();
TRACE("\n" + openFile + "\n\n");
delete openDlg;

CTAD2H5TDTestGuiDlg* saveDlg = new CTAD2H5TDTestGuiDlg(FALSE,NULL)
;
nResponse = saveDlg->DoModal();
if (nResponse == IDOK) {

// TODO: Place code here to handle when the dialog is
// dismissed with OK
saveFile = saveDlg->GetPathName();
fileType = saveDlg->GetFileExt();
TRACE("\n" + saveFile + "\n\n");
TRACE("\n" + fileType + "\n\n");
delete saveDlg;

//System
// TODO: Place code here to handle when the dialog is
// dismissed with OK

} else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
delete saveDlg;
}
}
else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
delete openDlg;
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

int main() {
// Console::WriteLine("The Main Program Starts!");
----> Line 148 <----<<< ThreadStart *thrStart = new ThreadStart(0,&CTAD2H5TDTestGuiApp::ProcessRunner)
----> Line 149 <----<<< Thread &thr1 = *new Thread(thrStart);

thr1.Start();
Console::WriteLine("The Main Program Ends!");
}
/////////////////////////////////////////////////////////////
I'm not sure what I'm doing wrong. Also, if you have any other
comments like what are you doing that for, please let me know. I
usually try things until they work, but that doesn't mean that it's the
best way to do it. Thanks for any and all help...

Nov 17 '05 #1
2 1604
MattMenard wrote:
I've written a C program that I want to run inside an Gui wrapper that
I started to write in MFC. I have to select some files then kick off a
process running the C program. I have the initial dialog file
selection stuff written, but am not sure how to run the C program
inside a seperate thread. I'm using VS.NET 2003 and am trying to use
the Thread and Process objects, but am not sure if I can use that with
MFC. I can't compile the code I have because I get some compiler
errors...

TAD2H5TDTestGui.cpp(57): error C3828: 'System::Diagnostics::Process':
placement arguments not allowed while creating instances of managed
classes.
TAD2H5TDTestGui.cpp(148): error C3828:
'System::Threading::ThreadStart': placement arguments not allowed while
creating instances of managed classes.
TAD2H5TDTestGui.cpp(149): error C3828: 'System::Threading::Thread':
placement arguments not allowed while creating instances of managed
classes.

I looked up what placement arguments are in the documentation, but
found that I don't have any in the code. Here's the code with the line
numbers marked that have the errors. I've include both the header and
the source file, where the errors are.

////////////////////////////////////////////////////////////
// TAD2H5TDTestGui.h : main header file for the application
////////////////////////////////////////////////////////////

#pragma once

#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif

#include <string>
#include "resource.h" // main symbols

using std::string;

// CTAD2H5TDTestGuiApp:
// See TAD2H5TDTestGui.cpp for the implementation of this class
//

class CTAD2H5TDTestGuiApp : public CWinApp
{
public:

CTAD2H5TDTestGuiApp();
static void ProcessRunner();

// Overrides
public:
virtual BOOL InitInstance();

// Implementation
DECLARE_MESSAGE_MAP()
};

extern CTAD2H5TDTestGuiApp theApp;

////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////
// TAD2H5TDTestGui.cpp : Defines the class behaviors for the app.
////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TAD2H5TDTestGui.h"
#include "TAD2H5TDTestGuiDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Threading;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// CTAD2H5TDTestGuiApp

BEGIN_MESSAGE_MAP(CTAD2H5TDTestGuiApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

// The one and only CTAD2H5TDTestGuiApp object

CTAD2H5TDTestGuiApp theApp;
CString fileType = "";
CString openFile = "";
CString saveFile = "";
// CTAD2H5TDTestGuiApp construction

CTAD2H5TDTestGuiApp::CTAD2H5TDTestGuiApp(){
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

void CTAD2H5TDTestGuiApp::ProcessRunner() {
CString commandStr;

if (fileType == "hdf5") {
commandStr = "c:\\hdf5\\tad2h5td\\tad2h5td.exe";
} else {
commandStr = "c:\\matlab\\tad2matlab\\tad2matlab.exe";
}
commandStr = commandStr + " " + openFile + " " + saveFile + " -bs
50000";

TRACE("\n" + commandStr + "\n\n");

// M *m1 = new M();

----> Line 57 <----<<< Process *myProcess = new Process();

try {
myProcess->StartInfo->FileName = commandStr;

myProcess->StartInfo->UseShellExecute = false;
myProcess->StartInfo->RedirectStandardOutput = true;

myProcess->Start();

Console::WriteLine(myProcess->StandardOutput->ReadToEnd());

myProcess->WaitForExit();

} catch (Win32Exception *e) {
if(e->NativeErrorCode == ERROR_ACCESS_DENIED) {
Console::WriteLine(S"{0}. You don't have permission to access this
file.",e->Message);

}
}
}

// CTAD2H5TDTestGuiApp initialization

BOOL CTAD2H5TDTestGuiApp::InitInstance()
{
// InitCommonControls() is required on Windows XP if an application
// manifest specifies use of ComCtl32.dll version 6 or later to enable
// visual styles. Otherwise, any window creation will fail.
InitCommonControls();

CWinApp::InitInstance();

AfxEnableControlContainer();

// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need
// Change the registry key under which our settings are stored
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated Applications"));

CTAD2H5TDTestGuiDlg* openDlg = new CTAD2H5TDTestGuiDlg(TRUE,NULL) ;
// m_pMainWnd = openDlg;
INT_PTR nResponse = openDlg->DoModal();
if (nResponse == IDOK) {

// TODO: Place code here to handle when the dialog is
// dismissed with OK
openFile = openDlg->GetPathName();
TRACE("\n" + openFile + "\n\n");
delete openDlg;

CTAD2H5TDTestGuiDlg* saveDlg = new CTAD2H5TDTestGuiDlg(FALSE,NULL)
;
nResponse = saveDlg->DoModal();
if (nResponse == IDOK) {

// TODO: Place code here to handle when the dialog is
// dismissed with OK
saveFile = saveDlg->GetPathName();
fileType = saveDlg->GetFileExt();
TRACE("\n" + saveFile + "\n\n");
TRACE("\n" + fileType + "\n\n");
delete saveDlg;

//System
// TODO: Place code here to handle when the dialog is
// dismissed with OK

} else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
delete saveDlg;
}
}
else if (nResponse == IDCANCEL) {
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
delete openDlg;
}

// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

int main() {
// Console::WriteLine("The Main Program Starts!");

----> Line 148 <----<<< ThreadStart *thrStart = new ThreadStart(0,&CTAD2H5TDTestGuiApp::ProcessRunner)
----> Line 149 <----<<< Thread &thr1 = *new Thread(thrStart);


thr1.Start();
Console::WriteLine("The Main Program Ends!");
}
/////////////////////////////////////////////////////////////
I'm not sure what I'm doing wrong. Also, if you have any other
comments like what are you doing that for, please let me know. I
usually try things until they work, but that doesn't mean that it's the
best way to do it. Thanks for any and all help...

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

Is the problem. Remove that and for safety add

#undef new

after where that block originally was (in case you picked up the
definition from the MFC headers).

Look at the second question in this MSDN column for full details as to
what is happening:
http://msdn.microsoft.com/msdnmag/is...A/default.aspx

Thanks.

Ronald Laeremans
Nov 17 '05 #2
Thanks for the reply. That was very helpful....

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Schmitt | last post by:
Hello. What is the usual way for running functions in parallel on a multiple-processor machine. Actually I want to run a single computationally...
1
by: Marc | last post by:
I want to write a C#/ASP.NET application where a user can go to a web page, start running a job, close their browser, and then come back later and...
3
by: Billg_sd | last post by:
Is there a programatic way in VB.NET to determine if a specific process is running? During an app update, I need to check if the component I'm...
6
by: Moses M | last post by:
I posted this a short while ago , but I don't think I explained the problem clearly. Task Manager lists processes running on a local system,...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is...
4
by: sneffe | last post by:
Hi, im writing a program to keep track of which programs is currently running. I would like to have the caption of running programs displayed in a...
1
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE:...
5
by: mabond | last post by:
Hi recently read a posting and reply about Excel processs still running after the Appliction.Quit was called. Thought I might be able to use the...
14
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page...
4
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.