谁能告诉我,是我犯错误的片段告诉我、谁能、片段

2023-09-07 04:07:48 作者:一首曲 谱出我内心的不安

 公共部分类Form1中:形态
{
  [的DllImport(coredll.dll中)]
  静态外部INT的SetWindowLong(IntPtr的的HWND,国际nIndex,INT dwNewLong);

  const int的GWL_WNDPROC = -4;

  市民代表INT WindProc(IntPtr的的HWND,UINT味精,长期的wParam,长LPARAM);

    公共Form1中()
    {
        的InitializeComponent();

        WindProc SampleProc =新WindProc(SubclassWndProc);

        SetWindowLong函数(这.handle的,GWL_WNDPROC,
            SampleProc.Method .MethodHandle.Value.ToInt32());

    }

公众诠释SubclassWndProc(IntPtr的HWND,UINT味精,长期的wParam,长LPARAM)
{
    返回1;
}
 

下面是我试图采取一种形式的窗口过程的样品,我就是这样做的在C ++中,我得到了windwproc easlily如果我尝试用C#.net 3.5一样我无法得到窗口过程,,调用SetWindowLong函数API,应用程序挂起,它会弹出一些不发送报告后...我已阅读,这是方式来获得窗口过程..请让我知道是我作出错误...

解决方案   

SampleProc.Method   .MethodHandle.Value.ToInt32()

只需使用 SampleProc 。如果失败,尝试编组到 FunctionPointer

public partial class Form1 : Form
{
  [DllImport("coredll.dll")]
  static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

  const int GWL_WNDPROC = -4;

  public delegate int WindProc(IntPtr hWnd, uint msg, long Wparam, long lparam);

    public Form1()
    {
        InitializeComponent();

        WindProc SampleProc = new WindProc (SubclassWndProc);

        SetWindowLong(this .Handle , GWL_WNDPROC,
            SampleProc.Method .MethodHandle.Value.ToInt32());

    }

public int SubclassWndProc(IntPtr  hwnd, uint  msg, long  Wparam, long  lparam)
{
    return 1;
}

Here is the sample which i was trying to take the window procedure of a form, this is how i do in C++ i get the windwproc easlily if i try the same in C# .net 3.5 i am unable to get the window proc,, after calling SetWindowLong API application hangs and it pops up some dont send report... i have read this is the way to get the window proc.. please let me know were i am making mistake...

解决方案 江歌去世第294天,她用命换来的室友说 我已经知错了,你们还要我怎样

SampleProc.Method .MethodHandle.Value.ToInt32()

Just use SampleProc. If that fails, try marshalling it to a FunctionPointer.