How to redefine a struct initially in the shared header file from my own source .cpp/.h ?
-
Tuesday, September 25, 2012 6:35 AM
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
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; }
- Proposed As Answer by Renjith V RamachandranMicrosoft Community Contributor Tuesday, September 25, 2012 2:04 PM
- Marked As Answer by Damon ZhengMicrosoft Contingent Staff, Moderator Monday, October 01, 2012 5:01 AM
-
Tuesday, September 25, 2012 2:26 PM
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 PMYou 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
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 PMDo 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
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
Yes.Yan
- Marked As Answer by Wood-MSDN Wednesday, September 26, 2012 3:41 PM
-
Thursday, September 27, 2012 9:59 AMModerator
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
- Edited by Damon ZhengMicrosoft Contingent Staff, Moderator Thursday, September 27, 2012 10:10 AM
- Marked As Answer by Damon ZhengMicrosoft Contingent Staff, Moderator Monday, October 01, 2012 5:01 AM
-
Thursday, September 27, 2012 4:32 PM

