|
You probably need to remove the quotes in GetBytes(\xFF\x00\xAA\x55).
|
|
|
|
|
What do you mean by "a string of hex characters"? Once the characters are in the string, there is nothing hexadecimal about them.
How do you do a "quick watch" on the array? It doesn't contain any characters at all, it's a byte array, not a char array.
The byte array will contain the ASCII codes of the characters in the string, which will be exactly the same as if the array was created with:
byte[] HBReply = new byte[] {255, 0, 170, 85};
Let's simplify the code somewhat, by the way. There is no need to create more than one byte array.
byte[] HBReply = Encoding.ASCII.GetBytes("\xFF\x00\xAA\x55");<br />
return HBReply;
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: What do you mean by "a string of hex characters"? Once the characters are in the string, there is nothing hexadecimal about them.
Each character in the sting array is a hex value. I need to show the character related to that value......Okay let me explain. I'm writing an interface that communicates over tcp/ip from a PC to a Mainframe. Everything must be sent in a byte array over this connection. However I'm having trouble creating the heartbeat which begins with hex ff00aa55.
Guffa wrote: How do you do a "quick watch" on the array? It doesn't contain any characters at all, it's a byte array, not a char array
While stepping thru my code i right click on the array HBReply and see what's in it.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Tom,
I think I found your problem. You use the System.Text.Encoding.ASCII encoder which, by definition in the .NET platform, is a seven-bit text representation. From the documentation:ASCII characters are limited to the lowest 128 Unicode characters, from U+0000 to U+007f. To do what you want, try the following:
System.Text.Encoding en = System.Text.Encoding.Unicode;
byte[] HBReply = new byte[ 30 ];
byte[] buffer = null;
string s = "\xFF\x00\xAA\x55";
buffer = en.GetBytes( s );
for( int i = 0; i < buffer.Length; i += 2 )
{
HBReply[ i / 2 ] = buffer[ i ];
}
return HBReply; This encodes the string as Unicode, gets every other entry, and puts that into the HBReply array.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
If you need a byte array with those values, just create that array. There is no need to mess around with a string. I showed the code for it in my previous post.
---
b { font-weight: normal; }
|
|
|
|
|
i make a project about image processing. I want to make image layers in program. How can i make it ? any idea ?
Help !...
-- modified at 16:19 Monday 16th January, 2006
|
|
|
|
|
You'll need to create a bitmap for each layer, either make one color that you don't allow on the bitmap ( for masking ) or manage your own masks, and do your own merging of layers to show your image.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
thanks Christian...
it is a good idea but it doesnt fit my application. When i refresh all bitmaps to draw on the form, it flickers. I need layer which can be refresh on itself so i dont need to refresh all layers.
Any idea about this...
|
|
|
|
|
It's not 'a good idea', it's the only way it can be done. Perhaps you need to turn on double buffering, or perhaps C# just can't handle this sort of app. I've done it a few times, but in C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I am teaching myself about custom controls so i am a newbie. I have made some basic user controls with success. But now i am having difficulty with components. After reading a CodeProject article i am coding a custom Textbox component. I have made a component class, inherited Textbox and overrode the WndProc to display key down messages in the Debug window. Pretty basic. How do i get this component to show up in the form designer like other textbox controls? In the CodeProject article the author managed to do this but i cannot figure out how it is done. I do not see the component in the toolbox and i cannot drag-and-dropon the form. Can someone provide me the HowTo?
|
|
|
|
|
Right click in the toolbox and select "Add/Remove Items...". Browse to the dll for the component.
---
b { font-weight: normal; }
|
|
|
|
|
Yep, that was the problem. I was trying to make a component inside the main project and use it. I could do this with user controls, but not components. I have to make that class DLL and then add it to the toolbox. When i looked at the CodeProject example i saw two projects, one for the component and one for the main form. I thought this was a code management decision by the author, i did not know it was a necessity... aHHHH... the subtleties of the NET framework...
|
|
|
|
|
Its not a necessity, its a nicety. You could have clicked Add/Remove Items and browsed for the .exe - which is an .NET assmbly itself.
|
|
|
|
|
Hi,
Just checking to see if there's a way to send a double click into a textbox.
Thanks!
Mel
|
|
|
|
|
Have you tried sending the WM_LBUTTONDBLCLK message to the control using the SendMessage[^] Win32 API?
That said, when you're resorting to faking mouse clicks, often times there's a better solution.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
As far as I can tell from my understanding of UDP and how it is delivered to a process, this should not be possible. However, I'm checking just in case someone can tell me I'm wrong (I'd like to be!).
Is it possible to have several processes on the same computer listen a single UDP multicast port? (let's say 224.0.0.0:60000) The ExclusiveAddressUse shows promise, but doesn't seem to really handle this situation.
The end goal is for 2+ process to listen to the same multicast group and receive all the messages. (I don't want one process to get one message, then the next process get the next, etc.)
[edit] I'm also wanting to stick with IPv4 if possible. [/edit]
Thanks for any advice. (If this doesn't work, I'll have to write a service that lets multiple processes on one computer use some form of IPC to talk to it. That service would then use the one available UDP connection to the multicast group.)
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
-- modified at 12:36 Monday 16th January, 2006
|
|
|
|
|
I'm using the RijndaelManaged class to encrypt data. One of the things I want to encrypt is a log file that records the usernames of the people who log on to my application.
When I write a single line to a file, I'm able to decrypt the data without a problem, but when I log onto the program again, thereby encrypting a second username to the file, I'm unable to successfully decrypt both lines of data. Only part of the second line is decrypted successfully. Does anyone have any suggestions/comments about why I'm encountering this problem?
|
|
|
|
|
In general, debugging a problem for you requires us to view the code you are using. We may not always be able to help, but seeing your code greatly increases the possibility.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Okay, here's the code I'm using to encrypt:
public void EncryptData()
{
FileStream fs=null;
if(File.Exists(Directory.GetCurrentDirectory() + "\\c#.ini") == false)
{
fs=new FileStream(Directory.GetCurrentDirectory() + "\\c#.ini",
System.IO.FileMode.CreateNew);
}
else
{
fs=new FileStream(Directory.GetCurrentDirectory() + "\\c#.ini",
System.IO.FileMode.Append);
}
byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
RijndaelManaged RMCrypto=new RijndaelManaged();
System.Security.Cryptography.CryptoStream cryption=new CryptoStream(fs,
RMCrypto.CreateEncryptor(Key, IV), CryptoStreamMode.Write);
StreamWriter tnWriter2 = new StreamWriter(cryption,
System.Text.Encoding.Unicode);
tnWriter2.WriteLine(log);
tnWriter2.Close();
fs.Close();
}
And here's the code for Decrypting:
private void DecryptDataLog()
{
FileStream read=new FileStream(currPath + "\\c#.ini",
System.IO.FileMode.OpenOrCreate);
byte[] Key = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
byte[] IV = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10,
0x11, 0x12, 0x13, 0x14, 0x15, 0x16};
RijndaelManaged RMCrypto=new RijndaelManaged();
System.Security.Cryptography.CryptoStream cryption=new CryptoStream(read,
RMCrypto.CreateDecryptor(Key, IV), CryptoStreamMode.Read);
StreamReader tnReader = new StreamReader(cryption,
System.Text.Encoding.Unicode);
this.textBox1.Text=tnReader.ReadToEnd();
tnReader.Close();
read.Close();
}
When the file I'm writing to has more than one line, the first few characters of the 2nd, 3rd, etc lines of encrypted text show up as gibberish, while the rest of the line is OK.
|
|
|
|
|
Do you write those lines in a separate step from the code listed, or does the "log" variable have multiple lines in it?
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
The log variable is simply this:
log=this.txtBxUsername.Text + ", " + DateTime.Now;
I want only to record the username and the time the user logged on.
administrator, 1/16/2006 10:55:37 AM
တတတတတတတတ襢⭺鉳䀗霳ꇳtrator, 1/16/2006 10:55:48 AM
တတတတတတတတ垵쌂멨蛫륢trator, 1/16/2006 10:56:02 AM
တတတတတတတတ뙩鲂팒ᬵ밞拑䔏⎗trator, 1/16/2006 10:56:15 AM
This is an example of the output I receive.
|
|
|
|
|
How is it that you get a multi-line file from code that only writes one line?
[edit]Oops, just looked back and saw the APPEND option when you open the file. That's the problem.
You need to write the entire file each time if you plan on encrypting and decrypting it. It appears that you accidentally read some of it because you are using the same key and initialization vector each time.[/edit]
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
-- modified at 14:20 Monday 16th January, 2006
|
|
|
|
|
The file is written to every time a user logs on to the application. I'm appending the new user information to the document each time the user logs on. So, the WriteLine is performed once each time through the application, but the file is appended the next time through.
|
|
|
|
|
I just modified the previous post to comment on this behavior. Check it out.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
So, would you suggest I read the file first and append the content to it the result of that read, then encrypt the whole thing? How are user logon records stored typically?
|
|
|
|
|