[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

LVM_SORTITEMS

Posted on 2007-03-22
11
Medium Priority
?
967 Views
Last Modified: 2013-11-20
Urgent!

Can anybody help me call the LVM_SORTITEMS windows message in .NET?
I'm trying to make a call to the Win32 API directly through using SendMessage. Does anyone know how to do this?

Greatly appreciated.
0
Comment
Question by:maloriopolium
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 18777258
You can do that// =============================================================
// Comparison routine for sorting ListView on a column
// =============================================================
int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort )
{
      int iResult;

   // MessageBox( hwnd, "Doing sort compare", "SortMsg", MB_OK );
   
      switch( lParamSort )
   {
         case 0:                                                // sub-item 0; file name
            iResult = 0;
            break;

      case 1:                                                // sub-item 1; folder size
      case 2:                                                // sub-item 2; number of files
            if ( lParam1 > lParam2 )
               iResult = 1;
         else
         if ( lParam1 < lParam2 )
               iResult = -1;
         else
               iResult = 0;
         break;
   }


   
   return iResult;
}


SendMessage( hwndList, LVM_SORTITEMS,(WPARAM)(LPARAM)(nSomeId),(LPARAM)(PFNLVCOMPARE)ListViewCompareProc );
 like
0
 

Author Comment

by:maloriopolium
ID: 18777349
Hi jkr,

I am trying to do this in C# .NET. Can this be done? I know you can make various other Win32 API calls in C# but just not sure how to go about this one since one of the parameters is a pointer to a function (PFNLVCOMPARE)

Thanks.
0
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 18777388
Hm, I doubt that you'll be able to pass a function pointer to a C# function. What you could do is creating a "native" Win32 DLL that contains such a sor function and call it via P/Invoke. See http://www.codeproject.com/dotnet/PInvoke.asp ("Using Platform Invoke")
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Assisted Solution

by:alb66
alb66 earned 1000 total points
ID: 18778040
If you are using a ListView you can call the Sort() method.
See MSDN documentation at http://msdn2.microsoft.com/en-us/library/system.windows.forms.listview.sort(VS.71).aspx
0
 

Author Comment

by:maloriopolium
ID: 18784720
Thanks jkr,

I just read that article you linked, it sys,
"Callback functions and passing arrays as parameters involve some more complications and can be the subject for the next article."

which sort of implies that it IS possible to pass function pointers to C#?
Do you know or can anyone point me to something that discusses the passing of callback functions or function pointers as a parameter to a Win32 API function??

Much appreciated
0
 
LVL 86

Expert Comment

by:jkr
ID: 18785858
No, function pointer require native Win32 modules. Since C# is a P-code language (which means that it is interpreted to some extent), there are no memory addresses that resemble assembly code which could serve as a function pointer. That's why you need P/Invoke as an intermediate layer that provides these.
0
 

Author Comment

by:maloriopolium
ID: 18786874
Can you explain what it means by using P/Invoke? It seems that all I have to do is declare the attribute:
[DllImport("user32.dll")]

and then declare a
static extern int SendMessage(....)
function which should be that of the Win32 API function.
Is that all there is to using P/Invoke?

0
 
LVL 86

Expert Comment

by:jkr
ID: 18787147
Yes, that pretty much is it. However, I'd suggest to have the DLL that exposes the callback function itself call 'SendMessage()', since you need to have a native module pass that function pointer, managed modules won't be able to get that one.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question