|
Hi
yes there is. you can open the Parallel port open as a file and use FileStream to write on it.
something like this:
<br />
public class ParallelWriter<br />
{<br />
public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000;<br />
public const UInt32 OPEN_EXISTING = 3;<br />
public const UInt32 GENERIC_READ = 0x80000000;<br />
public const UInt32 GENERIC_WRITE = 0x40000000;<br />
[DllImport("kernel32.dll", SetLastError=true)]<br />
private static extern IntPtr CreateFile(String lpFileName, UInt32 dwDesiredAccess, UInt32 dwShareMode,<br />
IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, UInt32 dwFlagsAndAttributes,<br />
IntPtr hTemplateFile);<br />
private FileStream strm;<br />
public FileStream Stream<br />
{<br />
get<br />
{<br />
return strm;<br />
}<br />
}<br />
public ParallelWriter(string Port)<br />
{<br />
IntPtr Handle = CreateFile(Port,GENERIC_READ|GENERIC_WRITE,0,IntPtr.Zero,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,IntPtr.Zero);<br />
strm = new FileStream(Handle,FileAccess.ReadWrite,true,1,true);<br />
}<br />
}<br />
now just use the Stream to write your data to the Parallelport
greets
m@u
|
|
|
|
|
hi,
thanx for ur response.. After getting the strm how will i connect to parallel port to send this data... can u give me the code for the parallel port connection....
|
|
|
|
|
Hello everyone,
I have a ListView which is populated by a CSV file. Using program I am going to select one of the rows in the ListView.
I have questions and I will be greatfull if someone can tell me how I can achieve it.
Question 1: How can I change the row's color "Similar as when it is clicked by mouse" when the program pick a particular row?
Question 2: The list of data is very long and not all of it can be placed in the ListView window. Is it possible to move the list and make sure the picked row with be somewhere in the middle of the ListView window, visiable to the user?
Thank you very much and have a good day/night.
Khoramdin
|
|
|
|
|
1) In the listview there is event like ColumnClick. It's parameter (e) is the column number. Try using this parameter with the colum color.
2)Try using property "ListName".AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
One nation - underground
|
|
|
|
|
I am using a Symbol device and my application pre-requisites include installing the symbol.all.arm.cab on the device.
The first time I installed the pre-requisites and the application on the device, the application ran properly without any crash.
But later, when I tried to start the application again, there was an error seen and the application did not start.
The following error was seen
TypeLoadException
Could not load type
Symbol.Generic.Reader from assembly Symbol,
Version=1.0.5000.3, Culture=neutral, PublicKeyToken=68EC8DB391F150CA.
MSDN says “TypeLoadException is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type.”
I tried reinstalling the ‘symbol.all.arm.cab’ file again, but it gives the same error.
can anyone help me in understanding why am I getting this error and what should I do to correct it.
|
|
|
|
|
Hey all,
I'm writing a program that can modify packets in c#.
Everything is going fine except my TCP checksum generator where it seems to work for some packets but with a few slight changes it generates the wrong thing. It only seems to be doing this when sending packets to my test box, otherwise it works fine.
Could the community please have a look at my code and try and find out what is wrong? i know my programming style Isn't exactly neat although any help would be appreciated.
I pass it the whole packet and it sends back a string of the checksum in hex format.
Cheers
-Glen
<br />
private static string GenerateTCPChecksum(byte[] packet)<br />
{<br />
packet[0x32] = 0x00;<br />
packet[0x33] = 0x00;<br />
<br />
int sum = 0;<br />
string ipHeaderLength = Convert.ToString(packet[0x0e], 16);<br />
ipHeaderLength = "" + ipHeaderLength[1];<br />
int packetSize = Convert.ToInt32(Convert.ToString(packet[0x10], 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[0x11], 16).PadLeft(2, '0'), 16);<br />
int length = packetSize - (Int32.Parse(ipHeaderLength) * 4);
<br />
for (int i = 0x22; i < packet.Length; i++)<br />
{<br />
try<br />
{<br />
sum = sum + Convert.ToInt32(Convert.ToString(packet, 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[i + 1], 16).PadLeft(2, '0'), 16);<br />
}<br />
catch (IndexOutOfRangeException)<br />
{<br />
sum = sum + Convert.ToInt32(Convert.ToString(packet, 16).PadLeft(2, '0') + "00", 16);<br />
}<br />
i++;<br />
}<br />
<br />
sum = sum + (Convert.ToInt32(Convert.ToString(packet[0x1a], 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[0x1b], 16).PadLeft(2, '0'), 16)) +<br />
(Convert.ToInt32(Convert.ToString(packet[0x1c], 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[0x1d], 16).PadLeft(2, '0'), 16)) +<br />
(Convert.ToInt32(Convert.ToString(packet[0x1e], 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[0x1f], 16).PadLeft(2, '0'), 16)) +<br />
(Convert.ToInt32(Convert.ToString(packet[0x20], 16).PadLeft(2, '0') +<br />
Convert.ToString(packet[0x21], 16).PadLeft(2, '0'), 16)) +<br />
0x06 + length;<br />
string s = Convert.ToString(sum, 16);<br />
string carry = "00";<br />
if (s.Length >= 5)<br />
{<br />
carry = s.Substring(0, s.Length - 4);<br />
s = s.Substring(s.Length - 4, 4);<br />
}<br />
sum = Convert.ToInt32(s, 16);<br />
sum = sum + Convert.ToInt32(carry, 16);<br />
sum = 0xffff - sum;<br />
s = Convert.ToString(sum, 16).PadLeft(4, '0');<br />
return s;
}
|
|
|
|
|
Hi all,
I am using the zedgraph control in my current project in which i am using zedgraph as a graphing area,
here i am plotting the line graph dynamically(ie., when the user clicks on the graph pane the points r created and the graph is drawn). According to our project requirement if the user selects a point it should be highlighted by dispalying a different color for that point so i am repainting the graph with a different color of the selected point this works fine but when selecting more than one point all selected points should be highlighted wher i am facing the problem. when i am passing all the selected points index and trying to highlight them its is working but on mouse click i am unable to get the desired o/p may b some where it is repainting i think.
Thanx in advance
prashanth
|
|
|
|
|
I'm guessing that you should post this against the article on ZedGraph. The author is probably your best bet for answering this one.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I want a DataGridView property in my UserControl:
C#<br />
<br />
public DataGridView _DataGridView<br />
<br />
[Category("Data"), DefaultValue(null)] <br />
public DataGridView DataGridView<br />
{<br />
get { return _DataGridView; }<br />
set { _DataGridView = value; }<br />
}<br />
I put the user control on a form, and this property shows (none) by default. I assign a dataGridView1 to the property.
But, when I delete dataGridView1, the property does not revert to (none). I can even still press the [+] and traverse as if the property was still referring to something.
I've looked everywhere (documentation, msdn, and searched the web) for any example demonstrating how to define a property to exhibiting the correct behavior.
The correct behaviour is exhibited by the ContextMenuStrip property of a Control, where it reverts to (none) when a contextMenuStrip1 is assigned to it and then deleted.
I'm new hear, so please forgive me if this query's been resolved, and point me in the right direction.
Thank you for your attention,
S
-- modified at 14:54 Thursday 29th March, 2007
|
|
|
|
|
Is there a similar method for a toolbarbutton?
|
|
|
|
|
The toolbar button (ToolStripButton) works just like a regular button.
Check for its events in the object browser or reflector.
ToolStripButton myToolbarButton1 = new ToolStripButton();
toolStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
myToolbarButton1,myToolbarButton2.... etc } );
this.myToolbarButton1.Click += new System.EventHandler(this.myToolbarButton1_Click);
Hope i helped.
Gideon
|
|
|
|
|
Hi
I have a XML file processing in C# as part of my project, it takes more time to process in some system even though system configuration is same (including free memory space and all). Does and any other factors affect this? Like XML versions or anything?
Please let me know...
|
|
|
|
|
Hi All,
Is there anyone who knows how to add a Restart Machine Dialog to installer.
I'm using the Setup Projcet in Visual Studio 2005.
I want the dialog can show after the installer.
Counld you help me?
|
|
|
|
|
I recently attended a VB (yes VB, so I could get a free version of VS2005 standard) and in the toolbox there was a snippet manager where you could drag snippets from there an introduce into code. How was this done? I've done some research but couldn't find anything.
Thanks
Mike
Everybody gotta be somebody
|
|
|
|
|
Hi
I am developing a windows applicaiton which is a client and connected with a server(a 3rd party tool developed in Labview) thru TCP socket. Communication is ok but when i unplugg the ethernet, the server is still indicating the client is connected. when i replugg the ethernet cable in the client side, im have done shutdown, close of socket and trying to re-establish the connection. But i could not make the conncetion the Socket.Beginconnect throwing the exception.
How to handle this situation..
can server detect the client availablity if the ethernet cable unplugged at client side?
I can't modify that server code, Is it possible to do something at client side to reconnect it to server?
I have tried Networkavailablitychange class, but no use..
Please post some sample code or links, that would be really help full please..
Thanks
Srini
|
|
|
|
|
there are interfaces declared in a dll below
-------------------- Encrypt.dll -------------------------
interface IDESCoder
{
string CreateCode(string IVString,string KeyString,string StringToEncode);
string GetCode(string IVString, string KeyString, string StringToDecode);
}
interface IMD5Encoder
{
string CreateCode(string StringToEncode);
}
public class ClsDES : IDESCoder
{
public string CreateCode(string IVString, string KeyString, string StringToEncode)
{
}
public string GetCode(string IVString, string KeyString, string StringToDecode)
{
}
private Boolean CheckIVKey(string IVString, string KeyString, string StringToEncode)
{
}
}
public class CldMD5 : IMD5Encoder
{
public string CreateCode(string StringToEncode)
{
}
}
-----------------------------------------------------------------------
and there is a Host
-------------------- test.exe ----------------------------------------
string filepath = @"E:\Encrypt.dll";
Assembly myDllAssembly = Assembly.LoadFrom(filepath);
Type dllType = myDllAssembly.GetType("IDESCoder");
if (dllType!=null)
{
......??????
}
-------------------------------------------------------------------------
then,what should i do next with Reflection if i want to use Interface declared in the dll??
|
|
|
|
|
string filepath = @"E:\Encrypt.dll";
Assembly myDllAssembly = Assembly.LoadFrom(filepath);
Type dllTypeInterface = myDllAssembly.GetType("IDESCoder");//this statement may have some question
Type dllTypeClass = myDllAssembly.GetType("ClsDES");//this statement may have some question
if (dllType!=null)
{
//TODO---you can use Factory pattern to improve it
dllTypeInterface interf=Activator.CreateInstance(dllTypeClass );
}
and you can choose another simpler way to resolve the problem.
first of all,You should Add references into your application in VS.NET.
then you can use it like using some interface or class in mscorlib.dll.
for example. using System.Int32;
It is very useful for everyone to show your own ideas to others.---Discussion is the power of improvement.
|
|
|
|
|
i know the way you said, and, you see , if i just know the interface'name ,can i have the dllTypeInterface object?
|
|
|
|
|
Hi all,
I am trying to use a DLL that modifies a stream of bytes (basically it's an encryption/decryption DLL). This DLL comes from a third party and I have to use it "as is". It wasn't designed for C#, but I really don't see any reason I shouldn't be able to use it.
The DLL reads and writes to a byte array (reads encrypted data, writes decrypted data), and this is giving me the error "Attempted to read or write protected memory."
I think the problem is quite simply that I don't understand how C# handles this kind of thing, so was wondering if I could get a little help.
The code goes something like this:
<br />
[DllImport("ABCdecrypt.dll", EntryPoint = "ABCdecrypt", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]<br />
unsafe public static extern bool ABCdecrypt([MarshalAs(UnmanagedType.I4)] int type, byte* data, int datalength);<br />
<br />
private void buttonGo_Click(object sender, EventArgs e)<br />
{<br />
byte[] yData = File.ReadAllBytes(textBoxInput.Text);
unsafe<br />
{<br />
fixed (byte* pBuf = &yData[0])<br />
{<br />
ABCdecrypt(100, pBuf, yData.Length);
File.WriteAllBytes(textBoxOutput.Text, yData);
}<br />
}<br />
MessageBox.Show("Done");<br />
}<br />
If I'm not being clear, please ask me to clarify. Essentially, all I want to do is use the library to decrypt the file referred to by textBoxInput.Text and save it out as the file referred to by textBoxOutput.Text
|
|
|
|
|
Hi YttriumOxide,
I've been struggling with something very similar recently. You can read my question here[^]:
I seem to have found an answer and it turned out to be far simpler than I thought it was going to be. Having said that, I might still be doing something wrong which will come back to bite me later but for now I seem to be OK and on my way.
What I did different from you was not to pass a pointer to the byte array as a parameter to the function but the byte array itself. I did not even do it in an unsafe block (which I probably should) but it worked.
So, leaving your declaration of your function unchanged (where you import it from the DLL), I would have called it like this:
ABCdecrypt(100, yData, yData.Length);
I have to stress though that I am by no means an expert in this field. I'm only just starting to meddle in C# and I haven't the faintest clue about marshalling. By the way, why did you marshal your first parameter as UnmanagedType.I4? And why did you not marshal the other two parameters? Do you know of any sites where I can read up on the MarshalAs attribute when used in this context?
Good luck
|
|
|
|
|
I am a C# programmer with mostly ASP.NET experience. I have done very little Win32 (WinForms) programming. Any suggestions for a good book on Windows Forms? I don't mean a general C# or .NET book, but one that specifically addresses the topic of Windows Forms.
|
|
|
|
|
I use this one at work, and it is pretty good.
Edit: Sorry, just noticed you said not specifically for C#.
|
|
|
|
|
No, your answer is great - I don't want a VB book, I want a C# one. What I meant was I don't want a C# book on General .NET. I want a C# book written specifically for windows forms, and that's exactly what you found.
Thanks
|
|
|
|
|
I use "Windows Forms Programming in C#" by Chris Sells....Excellent book.
Theres a version for .NET 2.0 out now also.
Hope that helps
Mike
Everybody gotta be somebody
|
|
|
|
|
|