The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Passing Function Pointer to SendMessage with P/Invoke

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Peter G Provost

Posts: 849
Nickname: pprovost
Registered: Aug, 2003

Peter G Provost is a Solution Architect for Interlink Group in Denver, CO.
Passing Function Pointer to SendMessage with P/Invoke Posted: Aug 5, 2003 11:15 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Peter G Provost.
Original Post: Passing Function Pointer to SendMessage with P/Invoke
Feed Title: Peter Provost's Geek Noise
Feed URL: /error.aspx?aspxerrorpath=/Rss.aspx
Feed Description: Technology news, development articles, Microsoft .NET, and other stuff...
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Peter G Provost
Latest Posts From Peter Provost's Geek Noise

Advertisement

I decided to try sorting the list before tackling positions. From my Win32 and MFC days, I knew exactly how to do this. Or so I thought.

As soon as I tried to pass a delegate as the LPARAM of SendMessage, I started crashing the Explorer.exe process. Does anyone out there know what is wrong with this code?

public delegate int CompareFunc(int lParam1, int lParam2, int lParamSort);
[DllImport("user32.dll", EntryPoint="SendMessage")] 

public static extern int SendMessage(IntPtr hWnd, uint Msg, uint wParam, [MarshalAs(UnmanagedType.FunctionPtr)] CompareFunc compareFunc);
[DllImport("user32.dll",EntryPoint="FindWindow")]
private static extern int FindWindow(string _ClassName, string _WindowName);
[DllImport ("user32.dll")]
public static extern IntPtr GetWindow( IntPtr handle, int cmd );
private void button1_Click(object sender, System.EventArgs e)
{
 // const int LVA_DEFAULT = 0x0000;
 const int LVM_FIRST = 0x1000;      // ListView messages
 // const int LVM_ARRANGE = (LVM_FIRST + 22);
 const int LVM_SORTITEMS = (LVM_FIRST + 48);
 const int GW_CHILD = 5;
 int tmp = FindWindow( "ProgMan", null );
 IntPtr handle = new IntPtr(tmp);
 handle = GetWindow( handle, GW_CHILD );
 handle = GetWindow( handle, GW_CHILD );
 CompareFunc f = new CompareFunc(Compare);
 SendMessage( handle, LVM_SORTITEMS, 0, f );
}
public static int Compare( int lp1, int lp2, int lpSort )
{
 return 0;
}
>

Read: Passing Function Pointer to SendMessage with P/Invoke

Topic: My favorite session thus far... Previous Topic   Next Topic Topic: Old Comments Are Gone

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use