473,554 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::Diagno stics::Process' :
placement arguments not allowed while creating instances of managed
classes.
TAD2H5TDTestGui .cpp(148): error C3828:
'System::Thread ing::ThreadStar t': placement arguments not allowed while
creating instances of managed classes.
TAD2H5TDTestGui .cpp(149): error C3828: 'System::Thread ing::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;

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

class CTAD2H5TDTestGu iApp : public CWinApp
{
public:

CTAD2H5TDTestGu iApp();
static void ProcessRunner() ;

// Overrides
public:
virtual BOOL InitInstance();

// Implementation
DECLARE_MESSAGE _MAP()
};

extern CTAD2H5TDTestGu iApp theApp;

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


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

#include "stdafx.h"
#include "TAD2H5TDTestGu i.h"
#include "TAD2H5TDTestGu iDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

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

using namespace System;
using namespace System::Threadi ng;
using namespace System::Diagnos tics;
using namespace System::Compone ntModel;

// CTAD2H5TDTestGu iApp

BEGIN_MESSAGE_M AP(CTAD2H5TDTes tGuiApp, CWinApp)
ON_COMMAND(ID_H ELP, CWinApp::OnHelp )
END_MESSAGE_MAP ()

// The one and only CTAD2H5TDTestGu iApp object

CTAD2H5TDTestGu iApp theApp;
CString fileType = "";
CString openFile = "";
CString saveFile = "";
// CTAD2H5TDTestGu iApp construction

CTAD2H5TDTestGu iApp::CTAD2H5TD TestGuiApp(){
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

void CTAD2H5TDTestGu iApp::ProcessRu nner() {
CString commandStr;

if (fileType == "hdf5") {
commandStr = "c:\\hdf5\\tad2 h5td\\tad2h5td. exe";
} else {
commandStr = "c:\\matlab\\ta d2matlab\\tad2m atlab.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->UseShellExecut e = false;
myProcess->StartInfo->RedirectStanda rdOutput = true;

myProcess->Start();

Console::WriteL ine(myProcess->StandardOutp ut->ReadToEnd()) ;

myProcess->WaitForExit( );

} catch (Win32Exception *e) {
if(e->NativeErrorCod e == ERROR_ACCESS_DE NIED) {
Console::WriteL ine(S"{0}. You don't have permission to access this
file.",e->Message);

}
}
}

// CTAD2H5TDTestGu iApp initialization

BOOL CTAD2H5TDTestGu iApp::InitInsta nce()
{
// InitCommonContr ols() 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.
InitCommonContr ols();

CWinApp::InitIn stance();

AfxEnableContro lContainer();

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

CTAD2H5TDTestGu iDlg* openDlg = new CTAD2H5TDTestGu iDlg(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;

CTAD2H5TDTestGu iDlg* saveDlg = new CTAD2H5TDTestGu iDlg(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::WriteL ine("The Main Program Starts!");
----> Line 148 <----<<< ThreadStart *thrStart = new ThreadStart(0,& CTAD2H5TDTestGu iApp::ProcessRu nner)
----> Line 149 <----<<< Thread &thr1 = *new Thread(thrStart );

thr1.Start();
Console::WriteL ine("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 1694
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::Diagno stics::Process' :
placement arguments not allowed while creating instances of managed
classes.
TAD2H5TDTestGui .cpp(148): error C3828:
'System::Thread ing::ThreadStar t': placement arguments not allowed while
creating instances of managed classes.
TAD2H5TDTestGui .cpp(149): error C3828: 'System::Thread ing::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;

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

class CTAD2H5TDTestGu iApp : public CWinApp
{
public:

CTAD2H5TDTestGu iApp();
static void ProcessRunner() ;

// Overrides
public:
virtual BOOL InitInstance();

// Implementation
DECLARE_MESSAGE _MAP()
};

extern CTAD2H5TDTestGu iApp theApp;

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


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

#include "stdafx.h"
#include "TAD2H5TDTestGu i.h"
#include "TAD2H5TDTestGu iDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

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

using namespace System;
using namespace System::Threadi ng;
using namespace System::Diagnos tics;
using namespace System::Compone ntModel;

// CTAD2H5TDTestGu iApp

BEGIN_MESSAGE_M AP(CTAD2H5TDTes tGuiApp, CWinApp)
ON_COMMAND(ID_H ELP, CWinApp::OnHelp )
END_MESSAGE_MAP ()

// The one and only CTAD2H5TDTestGu iApp object

CTAD2H5TDTestGu iApp theApp;
CString fileType = "";
CString openFile = "";
CString saveFile = "";
// CTAD2H5TDTestGu iApp construction

CTAD2H5TDTestGu iApp::CTAD2H5TD TestGuiApp(){
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

void CTAD2H5TDTestGu iApp::ProcessRu nner() {
CString commandStr;

if (fileType == "hdf5") {
commandStr = "c:\\hdf5\\tad2 h5td\\tad2h5td. exe";
} else {
commandStr = "c:\\matlab\\ta d2matlab\\tad2m atlab.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->UseShellExecut e = false;
myProcess->StartInfo->RedirectStanda rdOutput = true;

myProcess->Start();

Console::WriteL ine(myProcess->StandardOutp ut->ReadToEnd()) ;

myProcess->WaitForExit( );

} catch (Win32Exception *e) {
if(e->NativeErrorCod e == ERROR_ACCESS_DE NIED) {
Console::WriteL ine(S"{0}. You don't have permission to access this
file.",e->Message);

}
}
}

// CTAD2H5TDTestGu iApp initialization

BOOL CTAD2H5TDTestGu iApp::InitInsta nce()
{
// InitCommonContr ols() 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.
InitCommonContr ols();

CWinApp::InitIn stance();

AfxEnableContro lContainer();

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

CTAD2H5TDTestGu iDlg* openDlg = new CTAD2H5TDTestGu iDlg(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;

CTAD2H5TDTestGu iDlg* saveDlg = new CTAD2H5TDTestGu iDlg(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::WriteL ine("The Main Program Starts!");

----> Line 148 <----<<< ThreadStart *thrStart = new ThreadStart(0,& CTAD2H5TDTestGu iApp::ProcessRu nner)
----> Line 149 <----<<< Thread &thr1 = *new Thread(thrStart );


thr1.Start();
Console::WriteL ine("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
3395
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 expensive function with different parameter sets. Running the functions in different threads doesn't seem to work, because of the global interpreter lock. Would it help to fork processes, which run...
1
2034
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 see the results. The purpose for this application is for a user to be able to use a page on our intranet to start running a time-consuming reporting and analysis job. I'm not sure how to start a process...
3
442
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 about to replace is running. In UNIX I'd use: PS | grep -i MyApp Can this be done in .Net?
6
21655
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, including a "user name" associated with each process (e.g. SYSTEM). My application needs to check if a particular process is running, and if so get the associated "owner". I am really trying to...
0
2167
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 running... I want to be able to Kill it by pressing a command button in the application. So the code goes something like this: psiBat = New ProcessStartInfo(arrRun.Item(0)(1)) psiBat.WindowStyle =...
4
821
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 textbox on my form. I cant seem to find an easy way to do this in vb.net. Does anybody have a piece of code that can help me? Thanks
1
6003
by: Anonieko | last post by:
Query: How to display progress bar for long running page Answer: Yet another solution. REFERENCE: http://www.eggheadcafe.com/articles/20050108.asp My only regret is that when click the browser back button, it loads the progress bar again. Any solution to this?
5
6569
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 same (System.Runtime.InteropServices.Marshal.ReleaseComObject(exApplication)) to solve my problem but could not. Background : My app uses a WebBrowser control to display to the user the contents...
14
23127
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 while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update...
4
2843
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 resources about the best practices to do that. I've found a lot of email discussions that say something like, "You need to educate yourself about the differences when you have long- running...
0
7603
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7806
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7891
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5159
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3553
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2021
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
845
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.