locked
struct inheritance - the PIDL problem RRS feed

  • Question

  • are there any C++ inheritance features available to struct type objects?  That is C style structs where a vtable is not used.

    I am writing a lot of code to implement PIDLs in a shell namespace extension. PIDLs are structs that start with a 2 byte field containing the size of the struct.  And then all the fields of the specific struct follow that length field. There is a functional hierarchy of these PIDL structs that can be ideally supported by class inheritance. But since the PIDL is allocated using CoTaskMemAlloc and stored in the windows shell, there is no room for a vtable. And hence no C++ style inheritance.

    an example:

    A PIDL that represents a text file has some fields in common with the PIDL of an exe file or a database table.  All of these structs have a GetItemName method in common. How to call the GetItemName method of a specific struct using the pointer to the base struct they all have in common?

    another example:

    A shell namespace extension implments the IShellFolder2 interface. The GetDetailsOf function of that interface returns column heading and column data for the details view seen in windows explorer.  A PIDL is passed to GetDetailsOf and the function then decides what column data to return based on the actual type of the input PIDL.  The code basically says if the input PIDL is this type of PIDL, cast the PIDL to a pointer of that struct and then call a method on the struct to get the details view data. Do this for each type of PIDL. Tedious.

    How to use C++ to implement virtual function style inheritance on C style structs?

    Thursday, June 14, 2012 9:56 PM

Answers

    • Marked as answer by Steve Richter Friday, June 15, 2012 12:25 PM
    Friday, June 15, 2012 1:47 AM
  • On 6/14/2012 5:56 PM, Steve Richter wrote:

    A shell namespace extension implments the IShellFolder2 interface. The GetDetailsOf function of that interface returns column heading and column data for the details view seen in windows explorer.  A PIDL is passed to GetDetailsOf and the function then decides what column data to return based on the actual type of the input PIDL.  The code basically says if the input PIDL is this type of PIDL, cast the PIDL to a pointer of that struct and then call a method on the struct to get the details view data. Do this for each type of PIDL. Tedious.

    So write this tedious code once, and have it create a C++ class representing the right type of PIDL. Do it on interface boundary - when PIDL comes in from the system, wrap it in a suitable C++ class right away; when you need to return PIDL to the system, have the C++ class manufacture one. These classes can then form the usual hierarchy.


    Igor Tandetnik

    • Marked as answer by Steve Richter Friday, June 15, 2012 12:25 PM
    Friday, June 15, 2012 2:03 AM

All replies

    • Marked as answer by Steve Richter Friday, June 15, 2012 12:25 PM
    Friday, June 15, 2012 1:47 AM
  • On 6/14/2012 5:56 PM, Steve Richter wrote:

    A shell namespace extension implments the IShellFolder2 interface. The GetDetailsOf function of that interface returns column heading and column data for the details view seen in windows explorer.  A PIDL is passed to GetDetailsOf and the function then decides what column data to return based on the actual type of the input PIDL.  The code basically says if the input PIDL is this type of PIDL, cast the PIDL to a pointer of that struct and then call a method on the struct to get the details view data. Do this for each type of PIDL. Tedious.

    So write this tedious code once, and have it create a C++ class representing the right type of PIDL. Do it on interface boundary - when PIDL comes in from the system, wrap it in a suitable C++ class right away; when you need to return PIDL to the system, have the C++ class manufacture one. These classes can then form the usual hierarchy.


    Igor Tandetnik

    • Marked as answer by Steve Richter Friday, June 15, 2012 12:25 PM
    Friday, June 15, 2012 2:03 AM
  • So write this tedious code once, and have it create a C++ class representing the right type of PIDL. Do it on interface boundary - when PIDL comes in from the system, wrap it in a suitable C++ class right away; when you need to return PIDL to the system, have the C++ class manufacture one. These classes can then form the usual hierarchy.



    good idea. thanks.

    Friday, June 15, 2012 12:25 PM