Migrating vs extension project from 2019 to 2022

Som Prakash Tiwari 1 Reputation point
2022-03-11T12:49:17.57+00:00

Hi,
I am migrating the extension project from VS2019 to VS2022.
I found that IVSMDPropertyGrid.SetSelectedObjects was changed in VS2022.

VS2019: SetSelectedObjects(Int32, Int32)
this.grid.SetSelectedObjects(1, (Int32)ppUnk);

VS2022: SetSelectedObjects(Int32, IntPtr[])
this.grid.SetSelectedObjects(1, new IntPtr[] { ppUnk });

Where parameter is changed from Int32 to IntPtr[]. I updated the code to handle array, but it failed with error 0x80004005.

                                    IntPtr p = Marshal.GetIUnknownForObject(this);

                IntPtr ppUnk = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(IntPtr)));
                Marshal.WriteIntPtr(ppUnk, p);
                this.BindProperties();

                **this.grid.SetSelectedObjects(1, new IntPtr[] { ppUnk });** 

                this.grid.Refresh();

Need help on the migration.

Thanks in advance.

Regards,
Som

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,794 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Som Prakash Tiwari 1 Reputation point
    2022-03-14T07:20:53.637+00:00

    I found the solution of the issues, below code resolves the error.

                                        IntPtr[] intPtrs = new IntPtr[1];
                    Marshal.Copy(ppUnk, intPtrs, 0, 1);
                    this.grid.SetSelectedObjects(1, intPtrs);
    
    0 comments No comments