|
you are familiar to "..." block same as my first reply
...
System.Diagnostics.Process pr = new System.Diagnostics.Process();
pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
pr.StartInfo.FileName = "cmd.exe";
pr.StartInfo.UseShellExecute = false;
pr.StartInfo.RedirectStandardInput = true;
pr.StartInfo.RedirectStandardOutput = true;
pr.Start();
pr.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(pr_OutputDataReceived);
pr.BeginOutputReadLine();
System.IO.StreamWriter swWriter = pr.StandardInput;
swWriter.WriteLine("echo SomeTextHere\n");
swWriter.Flush();
...
//Define a delagate function
delegate void SetTextCallback(string text);
//Define a function for setting
void SetText(string text)
{
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox1.Text = text;
}
}
void pr_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
//event fired and u have data use it thread-safe
SetText(e.Data);
}
if this does not work define your problem with more details
UMS
|
|
|
|
|
Thanks for the replies guys, umseker thats almost exacly what i wrote...
the problem is that the window doesn't repaint itself until the other process has finished (i presume).
Anyway i'll post the code when i'll get home...
Erik.
|
|
|
|
|
Consider the code
DataTable dt = /* something */
double h_bid = (double)dt.Row[(int)SecurityColumns.BID];
double h_offer = (double)dt.Row[(int)SecurityColumns.ASK];
where /SecurityColumns.BID/ and /.ASK/ come from the enum type /SecurityColumns/.
Does the compiler determine before runtime the integer values of .BID and .ASK and make the substitution into the binaries? Or is the enum eval'd at runtime and converted to an int?
Execution speed is what I'm after. Thanks.
|
|
|
|
|
As the values of the enum is known at compile time, the values will be evaluated when it's compiled.
The compiler always evaluates everything that it can. For an example:
string msg = "Hello" + " " + "world!";
produces the exact same code as:
string msg = "Hello world!";
---
b { font-weight: normal; }
|
|
|
|
|
|
i am working with icodecompiler
ICodeCompiler compiler = codeProvider.CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
it works well when i give it a cs form containing main function in it
but i want to build a form in which there is no main what should i do to achieve this
is it possible to do this without main if no then is there some way to add main at run time if the main is not there as in my case
|
|
|
|
|
Assalam-o-Alaikum,
i've compiled a classLibrary to generate a DLL. as you know classLibrary doesnt have a main method,
i used a switch "/target:library".
parameters.CompilerOptions="/target:library";
there is also a method named MainClass in CompilerParameters class, i didnt use that but i think u can specify ur main class in it.
I hope this will help you
Allah Hafiz
-- modified at 4:29 Tuesday 3rd October, 2006
|
|
|
|
|
im working on a P2P messaging and file sharing app with C#. i want to use HTTP between peers in case the packets might be dropped by firewalls.
how can i do this?
wht technologies should i use?
thanks...
asamay
|
|
|
|
|
You could emulate a very simple Web server.
Use a TcpListener to listen on Port 80 and handle some very basic HTTP requests.
On the client side you can use a HttpWebRequest do send/read the data you need.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thank you so much!!
it looks easy to do!
asamay
|
|
|
|
|
I am trying to encrypt and decrypt using the functions below. Encryption is successful but decryption will return Bad Data. The Utils.byteToHexStr is a function to convert a hexadecimal string into a byte array where by each two characters of the hexadecimal string are combined to create one byte. (eg. 0x31 0x32 0x33 0x34 (ASCII 1234) -> 0x12 0x34). This is the requirement of the inputdata for encryption and decryption.
crypto.DesEncrypt("1234567812345678", "123456789012345678901234567890123456789012345678", "0000000000000000");
- > the code above got 0x2D 0xC8 0x88 0xCA 0x7D 0x62 0x17 0xE7 as result. However, to restore the original value using the code below, the program complain "Bad Data". I have tried all sorts of ways but still to no avail. Please provide me some advices.
crypto.DesDecrypt("2DC888CA7D6217E7", "123456789012345678901234567890123456789012345678", "0000000000000000");
public static byte[] DesEncrypt(string stringToEncrypt, string szKey, string szIV)
{
byte[] data = Utils.byteToHexStr(stringToEncrypt);
byte[] m_bDESKey = Utils.byteToHexStr(szKey);
byte[] m_bDESIV = Utils.byteToHexStr(szIV);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.Mode = CipherMode.ECB;
MemoryStream ms = new MemoryStream(4096);
CryptoStream encStream = new CryptoStream(ms,des.CreateEncryptor(m_bDESKey, m_bDESIV),CryptoStreamMode.Write);
encStream.Write(data,0,data.Length);
//encStream.FlushFinalBlock();
//calculate the length of the encrypted data
byte[] bResult = new byte[ms.Position];
ms.Position = 0;
ms.Read(bResult, 0, bResult.Length) ;
encStream.Close();
return bResult;
}
public static string DesDecrypt(string stringToDeCrypt, string szKey, string szIV)
{
byte[] data = Utils.byteToHexStr(stringToDeCrypt);
byte[] m_bDESKey = Utils.byteToHexStr(szKey);
byte[] m_bDESIV = Utils.byteToHexStr(szIV);
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.Mode = CipherMode.ECB;
MemoryStream ms = new MemoryStream(4096);
CryptoStream encStream = new CryptoStream(ms,des.CreateDecryptor(m_bDESKey, m_bDESIV),CryptoStreamMode.Read);
ms.Write(data,0,data.Length);
ms.Position = 0;
string strResult = new StreamReader(encStream).ReadToEnd();
encStream.Close();
return strResult;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public static byte[] byteToHexStr(string szHexString)
{
int discarded;
byte[] byteArray = HexEncoding.GetBytes(szHexString, out discarded);
if (discarded > 0)
{
return null;
}
return byteArray;
}
public static byte[] GetBytes(string hexString, out int discarded)
{
discarded = 0;
string newString = "";
char c;
// remove all none A-F, 0-9, characters
for (int i=0; i<hexstring.length; i++)
="" {
="" c="hexString[i];
" if="" (ishexdigit(c))
="" newstring="" +="c;
" else
="" discarded++;
="" }
="" odd="" number="" of="" characters,="" discard="" last="" character
="" (newstring.length="" %="" 2="" !="0)
" newstring.length-1);
="" }
="" int="" bytelength="newString.Length" 2;
="" byte[]="" bytes="new" byte[bytelength];
="" string="" hex;
="" j="0;
" for="" (int="" i="0;" i<bytes.length;="" hex="new" string(new="" char[]="" {newstring[j],="" newstring[j+1]});
="" bytes[i]="HexToByte(hex);
" return="" bytes;
="" public="" static="" tostring(byte[]="" bytes)
="" hexstring="" ;
="" hexstring;
="" <summary="">
/// Determines if given string is in proper hexadecimal string format
///
/// <param name="hexString" />
/// <returns>
public static bool InHexFormat(string hexString)
{
bool hexFormat = true;
foreach (char digit in hexString)
{
if (!IsHexDigit(digit))
{
hexFormat = false;
break;
}
}
return hexFormat;
}
///
/// Returns true is c is a hexadecimal digit (A-F, a-f, 0-9)
///
/// <param name="c" />Character to test
/// <returns>true if hex digit, false if not
public static bool IsHexDigit(Char c)
{
int numChar;
int numA = Convert.ToInt32('A');
int num1 = Convert.ToInt32('0');
c = Char.ToUpper(c);
numChar = Convert.ToInt32(c);
if (numChar >= numA && numChar < (numA + 6))
return true;
if (numChar >= num1 && numChar < (num1 + 10))
return true;
return false;
}
///
/// Converts 1 or 2 character string into equivalant byte value
///
/// <param name="hex" />1 or 2 character string
/// <returns>byte
private static byte HexToByte(string hex)
{
if (hex.Length > 2 || hex.Length <= 0)
throw new ArgumentException("hex must be 1 or 2 characters in length");
byte newByte = byte.Parse(hex, System.Globalization.NumberStyles.HexNumber);
return newByte;
}
|
|
|
|
|
i have a listbox and i want to put the list items (just the text) shown in an excel sheet.
how can i achieve this using `ctrl + c`, `crtl + v`? how can i catch the ctrl + c keypress event and have access to windows transfer area in .NET?
thanks in advance
|
|
|
|
|
What you would do is hook into the KeyPress event. The event arguments pass the key information.
|
|
|
|
|
Does anyone know the status with NDoc?
Obviously I've read their webpage and it looks like activity is slow or dead. I've tried NDoc 1.3 against VS2005 and it doesn't work. Its such an awesome application I hate to see it go stale.
|
|
|
|
|
It's dead. It was announced a few weeks ago by the NDoc founder. Microsoft started a new project, SandCastle[^], to replace the now-dead NDoc.
|
|
|
|
|
Right on!
|
|
|
|
|
Well, thanks for a definite answer, although its sad indeed. Just downloaded Sandcastle... there's no front end like NDoc? Has anyone actually used this tool?
|
|
|
|
|
AFAIK it's working and was used by Microsoft to build framework documentation. Take a look at the following article which allows you to keep the look and feel of NDoc while working with Sandcastle. Sandcastle Builder.asp[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Our posts crossed. Okay, great link. I'll have a look. Thanks!
|
|
|
|
|
Hi Guys,
I'm working on a C# form which hosts a Flash movie. That works fine.
I want to run this as the Flash Player can do in full screen mode. I've got as far as hiding the task bar and stretching my form beyond the bounds of the screen so that only the Flash movie is visible... nearly. Although I can hide the taskbar (using InterOp and ShowWindow(SW_HIDE)) my form simply will not stretch into the area where the hidden taskbar once sat!
My fall-back is to auto-hide the taskbar but this is not really an acceptable solution. Does anyone know a way to create a form which truly runs full screen?
Many thanks,
Simon
|
|
|
|
|
srev wrote: Does anyone know a way to create a form which truly runs full screen?
Have you looked at Managed DirectX? I know that can do it pretty easily.
|
|
|
|
|
Thanks for the thought, but unfortunately I can't use Flash with DirectX.
|
|
|
|
|
NO, just use directx for the full screeen functionality.
/\ |_ E X E GG
|
|
|
|
|
I'm not sure if I should be using this forum or the SQL Server forum, but I'll start here. I have been tasked with writing a project that, as part of its duties, will attach to a SQL Server database (2000 now, 2005 in the near future), and retrieve the columns that a stored procedure will return. I'm using the OleDB provider on purpose, as opposed to System.Data.SqlClient, because of the possible future need to support other systems. Currently, I'm doing the following:
<br />
private DataTable GetFields()<br />
{<br />
DataTable tbl = new DataTable();<br />
<br />
using (OleDbConnection conn = new OleDbConnection(txtConnectionString.Text))<br />
{<br />
try<br />
{<br />
conn.Open();<br />
<br />
using (OleDbCommand cmd = new OleDbCommand())<br />
{<br />
cmd.Connection = conn;<br />
if (cmbStoredProcedures.SelectedIndex > 0)<br />
{<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.CommandText = cmbStoredProcedures.GetItemText(cmbStoredProcedures.SelectedItem);<br />
}<br />
else<br />
cmd.CommandText = txtQuery.Text;<br />
<br />
using (OleDbDataAdapter adapter = new OleDbDataAdapter(cmd))<br />
adapter.FillSchema(tbl, SchemaType.Source);<br />
}<br />
}<br />
catch (Exception Ex)<br />
{<br />
MessageBox.Show(Ex.Message);<br />
}<br />
finally<br />
{<br />
if (conn.State == ConnectionState.Open) conn.Close();<br />
}<br />
}<br />
return tbl;<br />
}<br />
My question is this: Is there a better/more efficient way of doing this, or is this really the best way?
Kyosa Jamie Nordmeyer - Taekwondo Yi (2nd) Dan
Portland, Oregon, USA
|
|
|
|
|
Perhaps a slightly more efficient way would be to command.ExecuteReader().GetDataTypeName on each column. But I think it would be hardly distinguishable from your FillSchema. I see no reason to change your existing code.
p.s. for large code blocks, next time use <pre> tags instead of <code> tags.
|
|
|
|