How to redefine a struct initially in the shared header file from my own source .cpp/.h ?

Answered How to redefine a struct initially in the shared header file from my own source .cpp/.h ?

  • Tuesday, September 25, 2012 6:35 AM
     
      Has Code

    I've an shared header file, foo.h, with the following

    typedef struct tagINFO {
        PINFO    info;
        FLAGS       flags;
        MASK        mask;
    } INFO;

    How can I redefine this typedef within my own .cpp or .h file?

    I can't modify that foo.h, as this is shared. The modification is just for my own experiment so it's not appropriate to alter the shared foo.h.

    Thanks.


    • Edited by Wood-MSDN Tuesday, September 25, 2012 7:36 AM
    •  

All Replies

  • Tuesday, September 25, 2012 10:37 AM
     
     Answered Has Code

    I propose you add it to another namespace, eg test, in one of your headers:

    namespace test
    {
        typedef struct tagINFO {
            PINFO    info;
            FLAGS       flags;
            MASK        mask;
        } INFO;
    }

  • Tuesday, September 25, 2012 2:26 PM
     
      Has Code

    How can I make your suggestion work for the following call?

    BOOL GetInfo(
      _In_   UINT32 id,

      _Inout_  UINT32 *infoCount,

      _Out_  INFO *info
    );

    For example my new tagINFO is now like below,

    namespace test { typedef struct tagINFO { PINFO info; FLAGS flags; MASK mask;

    UINT32 newField;

    } INFO; }

    Thanks.

  • Tuesday, September 25, 2012 3:09 PM
     
     
    You can not 'redefine' a typedef. Perhaps if you describe what you are trying to accomplish, people may suggest something.

    Yan

  • Tuesday, September 25, 2012 6:00 PM
     
     Answered Has Code

    Try this:

    typedef struct tagINFO2
    {
        . . . .
    } INFO2;
    
    #define INFO INFO2

    • Marked As Answer by Wood-MSDN Wednesday, September 26, 2012 3:41 PM
    •  
  • Tuesday, September 25, 2012 6:14 PM
     
     
    Do not follow this advice unless you understand everything that is going to happen (and this is what you want to happen). If the GetInfo function is compiled to work with the arrays if INFO structures and you are going to call it with array of INFO2 structures through this preprocessor trick, you may find things go out of hand very quickly.

    Yan

  • Wednesday, September 26, 2012 1:59 PM
     
      Has Code

    Hope I can explain it right. Basically, GetInfo function can return the following

        typedef struct tagINFO {
            PINFO    info;
            FLAGS       flags;
            MASK        mask;
    	UINT32    newField;     } INFO;
    
    However, my SDK header was old, and didn't match the new struct returned by GetInfo().

    So I need to create my own version of INFO matches what GetInfo() returns so the values returned won't mismatch to my old struct of INFO.

    In this case, would Viorel suggestion work?

    Thanks.

  • Wednesday, September 26, 2012 2:19 PM
     
     Answered
    Yes.

    Yan

    • Marked As Answer by Wood-MSDN Wednesday, September 26, 2012 3:41 PM
    •  
  • Thursday, September 27, 2012 9:59 AM
    Moderator
     
     Answered Has Code

    How can I make your suggestion work for the following call?

    BOOL GetInfo(
      _In_   UINT32 id,

      _Inout_  UINT32 *infoCount,

      _Out_  INFO *info
    );

    For example my new tagINFO is now like below,

    namespace test { typedef struct tagINFO { PINFO info; FLAGS flags; MASK mask;

    UINT32 newField;

    } INFO; }

    Thanks.

    Use "test::INFO" instead of "INFO".

    Or, add "using namespace test" to your code, following the include files. In this way, every "INFO" in the source file will be set to the redefined one.


    Damon Zheng [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, September 27, 2012 4:32 PM
     
     
    If it’s only for your experiment, go ahead and alter foo.h on your hard drive.  Make sure you rebuild all the modules that depend on it.
     
    -- David

    Efficiently read and post to forums with newsreaders: http://communitybridge.codeplex.com