|
aloa
okay buddies =D my idea is to develop an ip-blocker. the user defines a set of ips that are blocked from the system.
my question is now: is this in c# actually possible or do i have to switch to c++?
regards
|
|
|
|
|
As discussed before, .NET is too high level for such a task at this time. There is a lot of native APIs and interfaces to both implement and consume. You should download and read the networking sections of the Microsoft Platform SDK[^]. There's a lot to understand. A firewall is a very low-level application and requires that you understand how the Microsoft networking protocols work together and with the network interface cards (NICs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
please introduce me a way to notify user that a process
request a socket in c#
koosha
|
|
|
|
|
.NET is too high-level for this sort of operation. This requires very low-level APIs and implementations with the Microsoft networking protocols, which also requires extremely efficient code with a small footprint - another reason not to use .NET.
There are already several commercial (typically free for home use) applications that do this already.
This has been discussed in the forums before. If you want to see how that thread progressed (to the same conclusion), please click "Search comments" directly above the message board.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
is there any messsage to notify user that a process
request a socket in c# or by win apis
koosha
|
|
|
|
|
Hi~
Lei wrote
"I have 2 forms, form1 contains a ListView. What I want to do is, when
clicking an item in the ListView, hide form1 and show form2. Code for
ListView's SelectedIndexChanged: { form2.Show(); this.Hide(); }. When I
click the item, form2 shows with form1's title and menu. I noticed that when mouse down, the SelectedIndexChanged event was triggered and bring form2 to front. But when mouse up, system redrawed the selected item and bring title and menu back to form1's. I tried to handle MouseDown and MouseUp event of ListView but they were never triggered. Now I used a tricky way to solve the problem: start a thread and use Control.Invoke to switch forms. It is not good, I think there must be a better solution. Thanks."
I am facing the same problem. Someone solve it with setting timer. However, is there any other way to solve it?
Thanks~
|
|
|
|
|
Don't use the SelectedIndexChanged event. It won't tell you if the user clicks on the currently selected item, either. Also, if the user is trying to use the direction pad or scroll wheel, the event will fire as they're scrolling between items; you probably want it to fire only when they press the Action button.
What you should do is set the Activation property to ItemActivation.OneClick, and handle the ItemActivate event. This also gives you keyboard/keypad interaction for free.
Don't you just love the complete, comprehensive nature of the documentation? In response to your post, I tried this out on both .NET CF 1.0 SP3 and on 2.0 Beta 1. At least 2.0 Beta 1 gives you a compiler warning. I've raised the issue on the Compact Framework newsgroup, and I hope that will encourage clearer documentation.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
It works!
Thank you very much!
|
|
|
|
|
How about treeview?
treeview got that same problem
there is no activation event handler in compact framework
|
|
|
|
|
Hi gurus,
I have 2 questions:
1) How can I attach a hwnd to a graphics?
When I do Graphics gr=new Graphics(m.HWnd) , I have the message "System.Drawing.Graphics.Graphics(System.IntPtr) is inaccessible due to its protection level"
2) What is the equivalent of the GetSystemMetrics() API in C#?
Best regards.
Thanks.
There is no spoon.
|
|
|
|
|
Graphics gr = Graphics.FromHwnd( m.HWnd ) If the HWnd is coming from a Windows Forms control, use ctl.CreateGraphics() instead.
As for GetSystemMetrics, that depends on what values you want. The simplest thing to do is often to use P/Invoke.
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetSystemMetrics( int metric );
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi,
For the graphics, I need to draw a button in the Non client area. I can get the handle of the non client area. I want to draw a button using the ControlPaint.DrawButton method wich need a Graphics as input.
ok for the dll import
There is no spoon.
|
|
|
|
|
When you receive the WM_NCPAINT notification message I mentioned to you before, the Message.WParam contains the HRGN (handle to a region) to be painted. You P/Invoke GetDCEx passing your window handle (HWND - the Handle property on all Control s), the HRGN mentioned above, and DCX_WINDOW|DCX_INTERSECTRGN ( =0x81 ). This is covered in the Platform SDK for the WM_NCPAINT message. IntelliSense will not help. You must read about the notification messages and APIs when working with this type of stuff.
The WM_NCPAINT documentation in the Platform SDK even includes a sample of calling GetDCEx .
The return value from GetDCEx is the HDC (handle to a device context) from which you create a Graphics object. Use the static Graphics.FromHdc method to get a Graphics instance for the non-client region.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath,
I have done what you said, but there is nothing. Maybe I have wrongly declared the things...
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, long flags);
in the WndProc method, I trap the WN_NCPAINT
Graphics gr=Graphics.FromHdc(GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN));
ControlPaint.DrawButton(gr, 50, 1, 5, 5, ButtonState.Normal);
nothing happens. it should draw a button 5x5 at pos (50, 1) in the title bar, but I see nothing. Maybe I don't use it well...
There is no spoon.
|
|
|
|
|
A DWORD translates to an int (or uint ), not a long . The value of DCX_WINDOW|DCX_INTERSECTRGN wouldn't, therefore, by read from the execution stack when calling GetDCEx - only 0 would be read and that wouldn't produce the results you want.
Also, don't bunch your method calls together so much. Try debugging that and you'll see that you can't check return values so it will be hard to know why a particular method failed.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, I have changed the long to an int
but I still have the error "An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll
Additional information: Out of memory."
when I try to do:
Graphics gr=Graphics.FromHdc(GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN));
I have now declared the functions like this:
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
and the constants:
private const int DCX_WINDOW=0x0001;
private const int DCX_INTERSECTRGN=0x0080;
while these constants are declared as long in the WinUser.h from the Platform SDK.
Also, Platform SDK declares the GetDCEx function like this:
HDC GetDCEx(
HWND hWnd,
HRGN hrgnClip,
DWORD flags
);
Maybe I'm wrong somewher in the C# translation...
There is no spoon.
|
|
|
|
|
A native long is 32 bits. A managed long is 64 bits (System.Int64 ). This is documented in the Platform SDK (and I know from many years of experience). If you want further proof, read Platform Invoke Data Types[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok for the length between Win32 and .NET.
I have written the declarations as you advised me, but I get an error when I execute the line
Graphics gr=Graphics.FromHdc(GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN));
There is no spoon.
|
|
|
|
|
It would help to know on which operation, which means - as I said before - you have to split them up.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have declared the following:
private const int DCX_WINDOW=0x0001;
private const int DCX_INTERSECTRGN=0x0080;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
I have trapped the WM_NCPAINT in the WndProc method of my System.Windows.Forms.Form derived window:
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT:
{
Debug.WriteLine("WM_NCPAINT");
Graphics gr=Graphics.FromHdc(GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN));
ControlPaint.DrawButton(gr, 60, 1, 5, 5, ButtonState.Normal);
break;
}
}
base.WndProc(ref m);
}
and I have the message "An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll
Additional information: Out of memory.", at the line
Graphics gr=Graphics.FromHdc(GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN));
There is no spoon.
|
|
|
|
|
As I said before, split the line:
IntPtr hdc = GetDCEx(m.HWnd, m.WParam, DCX_WINDOW|DCX_INTERSECTRGN);
Graphics g = Graphics.FromHdc(hdc); This is the very problem I mentioned earlier about combing such complex, compound statements together. Now which lines does the exception get thrown?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I still get the error
it seems the handle is null... When I call the GetDCEx I have 0x0 as result.
There is no spoon.
|
|
|
|
|
bouli wrote:
When I call the GetDCEx I have 0x0 as result
Check to make sure you have a valid handle to the window when you call GetDCEx .
- Nick Parker My Blog | My Articles
|
|
|
|
|
I always get a null handle
There is no spoon.
|
|
|
|
|
And for the 3rd time, on which line do you get the error after splitting the two methods on two separate lines?
Microsoft MVP, Visual C#
My Articles
|
|
|
|