Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.83/5 (4 votes)
I have the following C# code on Win7 64bit, Visual Studio 2008.

The class is to implement a virtual ListView.

C#
protected override void WndProc(ref Message m)
        {
            bool bHandled = false;

            switch (m.Msg)
            {
                case MessageId.OCM_NOTIFY:  // Reflected messages
                    NMHDR nm = (NMHDR) m.GetLParam(typeof(NMHDR));

                    switch (nm.code)
                    {
                       case CommCtrl.LVN_GETDISPINFO:
                            //do something
                            break;
                       case CommCtrl.LVN_ODCACHEHINT:
                            //do something
                            break;
                       case CommCtrl.LVN_ODFINDITEM:
                            //do something
                            break;

                     // ....


C#
public struct NMHDR
    {
        /// <summary>hwndFrom</summary>
        public IntPtr hwndFrom;
        /// <summary>idFrom</summary>
        public int idFrom;
        /// <summary>code</summary>
        public int code;
    }


C#
/// <summary>EXTERNALSYM LVN_FIRST</summary>
        public const int LVN_FIRST                = (0-100);    //listview

C#
/// <summary>EXTERNALSYM LVN_ODCACHEHINT</summary>
        public const int LVN_ODCACHEHINT            = (LVN_FIRST - 13);
        /// <summary>EXTERNALSYM LVN_GETDISPINFO</summary>
        public const int LVN_GETDISPINFO            = (LVN_FIRST - 77);
        /// <summary>EXTERNALSYM LVN_ODFINDITEM</summary>
        public const int LVN_ODFINDITEM             = (LVN_FIRST - 79);


It works well when I compile it as x86 platform. The
nm.code
is sometimes -13, or -77 or -79. But the
nm.code
is always 0 when I compile as x64. In this way, the following switch code will never be executed any more. Does anyone know why this happens?
Posted

1 solution

The problem here is that the structure of NMHDR has changed for x64. The idFrom field is now IntPtr:

C#
public struct NMHDR
    {
        /// <summary>hwndFrom</summary>
        public IntPtr hwndFrom;
        /// <summary>idFrom</summary>
        public IntPtr idFrom;
        /// <summary>code</summary>
        public int code;
    }


I recently had this issue and changing it as above got it working for me.

David
 
Share this answer
 
Comments
234dada 19-Jan-15 3:23am    
Thanks David. You saved me from a lot of headache. I had a similar issue running some part of the code i had written earlier in visual studio 2008 and win XP. had to move it to visual studio 2013 on windows 8.1. I used your solution and it worked perfectly. Kudos.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900