|
I am trying to correlate oConn.Open with Perfmon counter...
dev
|
|
|
|
|
And ....?? My answer doesn't change.
|
|
|
|
|
I think it nonsense if some application can access parallel port without additional driver
but I must provide own driver. After attach an "dll viewer" to "portmon", I found exported function
called _inp and _outp inside msvcrt.dll or msvcr80.dll. It looks like same with _inp and _outp
function on turbo c++ compiler. When I try to call with
[DllImport("msvcrt.dll",EntryPoint = "_outp")]
public static void OutP(int address, int value);
there's no exception occurs, but my application always shutted down with errors.
Is someone there know what signature of "_outp" is? or know whats wrong with my program?
(my program just have two textboxes to input address and value and one button to execute)
No one can prevent me to learn something
|
|
|
|
|
hello
This article[^] tells me it's possible thread aborted before created file is assigned to variable "w" by looking at IL - I examined IL but not sure how we can arrive at that conclusion:
<br />
Aborting pure .NET code is less problematic, as long as try/finally blocks or using statements are incorporated to ensure proper cleanup takes place should a ThreadAbortException be thrown. However, even then, one can still be vulnerable to nasty surprises. For example, consider the following:<br />
<br />
using (StreamWriter w = File.CreateText ("myfile.txt"))<br />
<br />
w.Write ("Abort-Safe?");<br />
<br />
C#'s using statement is simply a syntactic shortcut, which in this case expands to the following:<br />
<br />
StreamWriter w;<br />
<br />
w = File.CreateText ("myfile.txt");<br />
<br />
try { w.Write ("Abort-Safe"); }<br />
<br />
finally { w.Dispose(); } <br />
<br />
It's possible for an Abort to fire after the StreamWriter is created, but before the try block begins. In fact, by digging into the IL, one can see that it's also possible for it to fire in between the StreamWriter being created and assigned to w:<br />
<br />
IL_0001: ldstr "myfile.txt"<br />
<br />
IL_0006: call class [mscorlib]System.IO.StreamWriter<br />
<br />
[mscorlib]System.IO.File::CreateText(string)<br />
<br />
IL_000b: stloc.0<br />
<br />
.try<br />
<br />
{<br />
<br />
...<br />
<br />
Either way, the Dispose method in the finally block is circumvented, resulting in an abandoned open file handle – preventing any subsequent attempts to create myfile.txt until the application domain ends.<br />
I can't see where in IL the variable "w" get assigned the created file stream writer.
devy
|
|
|
|
|
Here:
IL_000b: stloc.0
The reference to the stream writer is the return value of the call on the previous line, so that is what's in the accumulator.
The variable w is the first variable in the method, so that is allocated at position 0 in the stack frame.
The instruction stloc.0 stores the value of the accumulator at location 0.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks
Sounds like to understand this I need to know assembly and IL ...
devy
|
|
|
|
|
Not at all. You only have to realise that calling a method and assigning the result to a variable are two separate operations, so the thread can be aborted between those operations.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thanks
think i understand that - that create file stream and assigning it to variable "w" is not atomic and is indeed two-step operation.
But I wish I could read assembly and IL so I can ildasm then check on things myself.
devy
|
|
|
|
|
hi
how can i send bit's to usb in c# ?
thank's
|
|
|
|
|
There's nothing built in to C# to support this, you'd need to find a library you can consume to do that.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
can i get some direction ? i dont know from where to start ?
|
|
|
|
|
|
Hi,
years ago, when PC interfaces where just serial port and parallel port, it made sense to talk to the port, and make it send and receive the bits and bytes the peripheral manual told you to send and receive in order to operate some peripheral.
Nowadays you should focus on the peripheral device, and not on the interface or cable that is used. So your program should not address the USB bus, it should address the PC driver that goes with the peripheral. A commercial peripheral comes with such a driver; also microcontrollers and other electronics typically come with the drivers required to connect them to a PC. If your vendor cannot offer a driver, you have two choices: change product and vendor, or start developing your own driver (a major effort).
BTW: if your USB is used as an intermediate interface, the same applies. So USB-to-serial cables,
USB-to-parallel cables, USB-to-Ethernet cables, all have their own drivers, and you can forget the USB aspect of them alltogether: the serial port/parallel port/Ethernet will behave almost like its twin on the motherboard. And Vista has most of these drivers built-in too.
|
|
|
|
|
A very good and solid answer!
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hey.
I'm currently hijacking the WM_NCCALCSIZE function to define a custom caption and border areas.
But i'm having an issue with the form constantly resizing itself.
When I maximise the form, it fills the screen like I want it to, but when I restore it back, it's height and width properties are decreased.
I know where in the code it's happening, but I don't know how to stop it from constantly reducing in size, but rather maintain it's original size and simply "append" the non-client area. Any help would be appreciated
Here's the function for the WM_NCCALCSIZE calculations:
protected void WndNCCalcSize(ref Message m)
{
NativeMethods.NCCALCSIZE_PARAMS para = new NativeMethods.NCCALCSIZE_PARAMS();
NativeMethods.RECT winRect;
if (m.WParam == IntPtr.Zero)
winRect = (NativeMethods.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));
else
{
para = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
winRect = para.rgrc0;
}
IntPtr HDC = NativeMethods.GetWindowDC(this.Handle);
winRect.Top = winRect.Top + CaptionHeight;
winRect.Bottom = winRect.Bottom - 3;
winRect.Left = winRect.Left + 2;
winRect.Right = winRect.Right - 2;
this.BRect = winRect;
if (m.WParam == IntPtr.Zero)
Marshal.StructureToPtr(winRect, m.LParam, false);
else
{
para.rgrc0 = winRect;
Marshal.StructureToPtr(para, m.LParam, false);
}
NativeMethods.ReleaseDC(this.Handle, HDC);
m.Result = new IntPtr(NativeMethods.WVR_REDRAW);
base.WndProc(ref m);
}
Thanks.
|
|
|
|
|
Hello,
I have a richtextbox richTextBox1, and all I want to do is prevent the tab key from actually inserting a tab in the richTextBox1. instead I am catching when the tab key is pressed, and switching to the next control in my form, which I have been able to successfully do. How do I do this, I have tried using e.handled = true for the keydown and keyup events, to no success.
thanks!
Stephen
|
|
|
|
|
Hi,
First, set the AcceptsTab property of your richtextbox to true to ensure that keydown is raised on the tab key.
Then, you need to set
e.SuppressKeyPress = true
instead of e.handled.
|
|
|
|
|
Dear all,
I have one c# window form which contains datagridview controls,i have made
some columns visibility to fale.I have one button control when i click the
button another form opens and when i will close the second form i need to
show main form datagrid view control columns by seeting visible=true.
This is happing fine but the datagrid view is not refreshing.I tried with
datagridview.refresh() method also.
Please help me on this.
Regards
Veeresh
i want to join this group
|
|
|
|
|
Hello,
I have a listview in largeicon mode. If I press the right arrow when the rightmost item is selected in a row, nothing happens. I would like it to jump to the first item of the next row.
What I tried was cancelling the keydown event for he left and right arrows, and handling the selection manually (and calling ensurevisible()).
The problem with this is that I want to do some processing for the newly selected item.
My method will raise the selectionchanged events for every single item I visited. The default method only raised it when we 'settled' on an item (and sometimes in betwen )
If I keep the down arrow pressed, items will keep getting selected, and the listview will keep scrolling. This is good.
If I keep the right arrow pressed, I will keep processing all of them, which delays EnsureVisible(). This means that the selected item will be off screen for most of the time.
Any ideas?
|
|
|
|
|
Hello, I want to do packet filter program and I've found some articles about packet sniffing but I've a problem. I'm trying to create raw socket but I always get socket exception with error code 10013 (access denied). I''m using Windows Vista and VS 2008 Express.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Unspecified);
I try to run this code on VS 2005 and it was fine...no exception. So I don't know where the problem is.Anyway, any suggestions how to do packet filter in C# or how to block ports or internet acess(for specified program or for all)? Thanks.
|
|
|
|
|
Member 4680844 wrote: I''m using Windows Vista and VS 2008 Express.
Yeah, RAW packets are off-limits to all user accounts. THe only account that can create RAW packets only under an Administrator account. It's been that way since SP2 came out for Windows XP.
Member 4680844 wrote: I try to run this code on VS 2005 and it was fine...no exception.
Speaking of XP, was this code under 2005 perhaps running under Windows XP or XP SP1?? Under XP and XP SP1, normal user accounts could create RAW packets without any issues. The same code, running under the same account, will not work under XP SP2 and above.
|
|
|
|
|
Thanks for reply! But from you reply I understand that I can't create RAW socket under regular user account. But this is exactly what I need, because I've a laptop and I don't care about administrators, but when someone other uses the computer(logged as guest or some other user without administration rights) I want to block some internet pages or ports. I know that I can use some programs or firewalls but I want to do it by myself. And about the raw socket, I run the code on same machine(Vista SP1) but once compiled with VS 2008 and then with VS 2005 so I'm really confused about this issue. Anyway any ideas how to do packet filter? Thanks!
|
|
|
|
|
Member 4680844 wrote: I understand that I can't create RAW socket under regular user account. But this is exactly what I need
It's not going to happen if you run it under Windows. It's that simple. You need to run the code under a full admin account, or it's not going to work.
In order to get VS 2005 to work under Vista, you had to run it as an admin, otherwise it doesn't work very good.
|
|
|
|
|
Thanks for information! So I tried to do a service for this issue (using system account) and I'm able to read incoming packets. I'm able to get IP address from them and here comes the second issue. How to block/restrict/drop packets from specified IP? Is it possible to do it in C# or I must use C++ and how to accomplish it? Thanks.
|
|
|
|
|
Well, I hate to tell you this, but you're not intercepting anything. You're standing off to the side of the packet stream, watching them fly by.
You can't do what you want without writing a packet driver to stick into the network stack, which you can't do in C#. Well ... not nicely or efficiently anyway.
If you want to see what it takes to do this, look at these[^] open source firewall projects.
|
|
|
|