|
i try to run an console application through a programmatically created process. i dont want a new console command window to pop up during the process running. hence, i use the following code.
------
System.Diagnostics.ProcessStartInfo pi = new System.Diagnostics.ProcessStartInfo(Application.StartupPath+"\\EncodeFile.exe");
pi.CreateNoWindow = true;
p = new System.Diagnostics.Process();
p.StartInfo = pi;
p.Start();
------
however, the console command window still show up although i oledi set
pi.CreateNoWindow = true;
can anyone tell me the solution?
thank you.
regards
yccheok
|
|
|
|
|
try it with the compiler option /target:winexe
Cheers
Kannan
|
|
|
|
|
You need to set the RedirectStandardInput , RedirectStandardOutput and RedirectStandardError properties of the <EDIT>ProcessStartInfo </EDIT> object to true . If you need to, you can then access the input and output of the console using the StandardInput , StandardOutput and StandardError properties.
E.g.:
ProcessStartInfo psi = new ProcessStartInfo();
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.FileName = "Path to the exe";
Process p = Process.Start(psi);
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
<br />
((Rectangle)mySquares[i]).X = <br />
((Rectangle)mySquares[i-1]).X;
I have an ArrayList of Rectangles and would like to update the X co-ordinate with the old one but this assignment generates a compiler error "The left-hand side of an assignment must be a variable, property or indexer"
yet the left hand side of this IS a property. Is there a reason for this? do I have to extract/assign the x co-ordinates in a for loop?
|
|
|
|
|
If this is not already in a for loop, then how is the current value of i determined?
in any event, it will fail for i=0 since there is no element whose index = -1.
Perhaps we need a to see just a wee bit more of your code in order to help?;)
|
|
|
|
|
<br />
for (i = mySquares.Count - 1; i > 0; i--)<br />
{<br />
((Rectangle)mySquares[i]).X = <br />
((Rectangle)mySquares[i-1]).X;<br />
((Rectangle)mySquares[i]).Y = <br />
((Rectangle)mySquares[i-1]).Y;<br />
}<br />
I'm trying to update the x,y co-ordinates of the rectangles in the arrary in a Timer.Tic() method.
it tells me that my left operand has to be a property but is Rectangle.X not a property?
|
|
|
|
|
Interesting, try this:
for (int i = mySquares.Count - 1; i > 0; i--) {
Rectangle r1 = (Rectangle)mySquares[i];
Rectangle r2 = (Rectangle)mySquares[i-1];
r1.X = r2.X;
r1.Y = r2.Y;
}
Burt Harris
|
|
|
|
|
Burt Harris (msft) wrote:
Rectangle r1 = (Rectangle)mySquares[i];
Rectangle r2 = (Rectangle)mySquares[i-1];
Unfortunately that won't work either.
The problem is that Rectangle is a value type so the modifications you are doing are being done to the unboxed value which is discarded. Instead, you should create a new Rectangle object and place it back in the collection.
for (int i = mySquares.Count - 1; i > 0; i--)
{
Rectangle r1 = (Rectangle)mySquares[i];
Rectangle r2 = (Rectangle)mySquares[i-1];
mySquares[i] = new Rectangle(r2.X, r2.Y,
r1.Width, r1.Height);
}
[Edit]I should have posted this sooner instead of catching up on CP, Richard beat me to it :P[/Edit]
James
- out of order -
|
|
|
|
|
Rectangle is a struct, so that probably won't work anyway, since you're changing the coordinates of an unboxed copy of your rectangle. Try something like:
for (i = mySquares.Count - 1; i > 0; i--)
{
mySquares[i] = new Rectangle(
((Rectangle)mySquares[i-1]).Location,
((Rectangle)mySquares[i]).Size);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Thanks everyone for your replies it is working now (Well at least the assignment problem I had
|
|
|
|
|
Is this the only way to 'fall through' on switch statements?
<br />
int x = 3;<br />
switch(x){<br />
case 0:<br />
goto case 1;<br />
case 1:<br />
goto case 2;<br />
case 2:<br />
goto case 3;<br />
...<br />
}<br />
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
|
IMHO something like this would be a cludge that screams poor design.
If you need to use goto to 'fall through' a switch then you need to consider redesigning your application.
<br />
switch(x)<br />
{<br />
case 0:<br />
case 1:<br />
case 2:<br />
DoAction();<br />
break;<br />
.<br />
.<br />
.<br />
}<br />
Probably not what your doing though.
|
|
|
|
|
yeah indeed. perhaps you could consider getting each of your case statements to call functions instead of each other.
not sure what your exact need is, but all i know is from previous experience that fallthrough statements come back to bite you in the butt later when you least expect them.
|
|
|
|
|
No, you can 'fall' through so long as there is no code between the case statements.
And yes, it sucks.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Anyone know how to get system info at runtime. I specifically need to find out what COM ports are installed.
Thanks
-Sam
|
|
|
|
|
Hi Sam,
Take a look at System.Management namespace, its a wrapper for WMI, you might find what you are looking for.
Cheers
Kannan
|
|
|
|
|
Try this out:
private void btnComPorts_Click(object sender, System.EventArgs e)
{
txtOutput.Clear();
string server = @"\\" + txtServer.Text;
ManagementScope ms = new ManagementScope(server + @"\root\cimv2");
ObjectQuery oq = new ObjectQuery("select deviceID from win32_SerialPort");
ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq);
ManagementObjectCollection moc = mos.Get();
foreach(ManagementObject mo in moc)
{
txtOutput.AppendText(mo["DeviceID"].ToString());
txtOutput.AppendText("\r\n");
}
}
Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side work.
|
|
|
|
|
Thanks Matt, worked excellent!
|
|
|
|
|
I've seen many really good examples of how to add scrolling credits to your Visual C++ applications, but I haven't found any yet for a C# Windows application. Are there any out there?
|
|
|
|
|
How can I test for a null string?
if (str == "")
doesn't work if str is a string containing just \0.
|
|
|
|
|
if (str == null)
[edit]Note that .NET makes a distinction between null and "" - both are possible. The first one throws a Null exception, when you try to use it, the second one bevaves like you expect from a zero-length string.[/edit]
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
So, if (str == null || str.Length == 0) then.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am not sure what you mean by "contains just \0". If you mean something like the C string terminator this is not really used and if you happen to get strings like this you will have to test for this case explicitly.
If you want to treat null references the same as empty strings you need a test like this:
if((str == null) || (str == ""))
Do not check the string length, by the way. Strings can contain characters such as writing direction markers that do not show. Hence, their length is > 0 but they are still empty!
cheers
erik
|
|
|
|
|
Yes, I did mean the C string terminator. If you write out a string to memory using MemoryStream and StreamWriter and then read it back in with a MemoryStream and StreamReader, you get that terminating \0 at the end of the string. However, (str == null), (str.Length == 0), and (str == "") all fail. The only solution I found was to use string.Trim to manually remove the \0.
|
|
|
|