到底怎么调API啊!我连个MessageBox都调不出来。sysimport,dllimport都不能用。哪位能给个能用的sample啊!B2

解决方案 »

  1.   

    Beta2有所改善
    但是调用API是非常落后的方法,在C#中,使用MessageBox()和MessageBox.Show()是一样快的,为什么不用面向对象的方法呢?
      

  2.   

    我不知道你为什么用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);
    >  }
    > }
      

  3.   

    如果说以后API百分百没用了,那我就不用它了,但未必会没用吧。
    msgbox是个简单的入门例子,很多地方都见过它的sample,但我都做不出来。
    要加上/r:system.Win32.Interop.dll吗?