我不知道你为什么用sysimport不行,下面是几个月前我在msnews对相同问题的答复: Q: > is there a preferred method of using win32 api > function calls (ie hooking > messages) in C# code? i suppose i'm asking if there > is an equivalent .NET > component for hooking messages to the win32 way of > calling SetWindowsHookEx, > etc. > > thanks, > davidA: > I'm not sure, maybe you can use PInvoke. Following > is a example from the > book .NET Presenting: > > using System; > > class TestPInvoke > { > [sysimport(dll="user32.dll",name="MessageBoxA")] > public static extern int PopupBox(int hWnd, string > strMsg, > string strCaption, int nType); > > public static void Main() > { > int nMsgBoxResult; > nMsgBoxResult=PopupBox(0,"Hello C#","PInvoke",0); > } > } >
但是调用API是非常落后的方法,在C#中,使用MessageBox()和MessageBox.Show()是一样快的,为什么不用面向对象的方法呢?
Q:
> is there a preferred method of using win32 api
> function calls (ie hooking
> messages) in C# code? i suppose i'm asking if there
> is an equivalent .NET
> component for hooking messages to the win32 way of
> calling SetWindowsHookEx,
> etc.
>
> thanks,
> davidA:
> I'm not sure, maybe you can use PInvoke. Following
> is a example from the
> book .NET Presenting:
>
> using System;
>
> class TestPInvoke
> {
> [sysimport(dll="user32.dll",name="MessageBoxA")]
> public static extern int PopupBox(int hWnd, string
> strMsg,
> string strCaption, int nType);
>
> public static void Main()
> {
> int nMsgBoxResult;
> nMsgBoxResult=PopupBox(0,"Hello C#","PInvoke",0);
> }
> }
>
msgbox是个简单的入门例子,很多地方都见过它的sample,但我都做不出来。
要加上/r:system.Win32.Interop.dll吗?