From: Emmanuel Stapf [ES] on
Brian Muth wrote:
> Also, what version of VS are you using?

I've been using VS2005 on one end, and the Windows SDK v6.1 on the other.

Manu
From: Barry Schwarz on
On Mon, 29 Dec 2008 12:56:06 -0800, "Emmanuel Stapf [ES]"
<manus(a)newsgroups.nospam> wrote:

>The old definition look like:
>
>typedef struct tagDEC {
> USHORT wReserved;
> union {
> struct {
> BYTE scale;
> BYTE sign;
> };
> USHORT signscale;
> };
> ULONG Hi32;
>...
>} DECIMAL;

scale is a member of an unnamed struct which in turn is a member of an
unnamed union. Therefore if you have a DECIMAL* dec you could use
dec->scale since there are no intervening names.

>
>
>The new one like:
>
>typedef struct tagDEC {
> USHORT wReserved;
> union {
> struct {
> BYTE scale;
> BYTE sign;
> } DUMMYSTRUCTNAME;
> USHORT signscale;
> } DUMMYUNIONNAME;
> ULONG Hi32;
>...
>} DECIMAL;

scale is a member of the struct name DUMMYSTRUCTNAME which in turn is
a member of the union name DUMMYUNIONNAME. Given the same dec as
above, you need to use dec->DUMMYUNIONNAME.DUMMYSTRUCTNAME.scale.
Since names in all caps are frequently macros, it might be possible to
define those macros as empty (or perhaps as a single blank) which
would render the above typedef equivalent to the first.

>
>I have to compile my code using -DNONAMELESSUNION but can't recall if I
>still need to do that.

It depends on why you were doing it in the first place.

>
>Regards,
>Manu
>
>
>David Lowndes wrote:
>>> I had some code that looks like:
>>>
>>> DECIMAL dec;
>>>
>>> ... dec->scale ...

Since DECIMAL is a structure type and not a pointer type, this code
cannot compile successfully.

>>> which compiled fine until I use the latest Platform SDK (v6.1) for
>>> which I get the following error:
>>>
>>> error C2039: 'scale' : is not a member of 'tagDEC'
>>> C:\Program Files\Microsoft
>>> SDKs\Windows\v6.1\Include\wtypes.h(1068) : see declaration of 'tagDEC'
>>>
>>> What is the proper way to have this code compile fine on older version
>>> of the wtypes.h header and the new ones?

You could define two macros: VERSION and FILLER. The first (which you
would set as a compile parameter) would indicate which version and the
second would compensate for the difference the structure definition.
Something like
#if VERSION == 6.1
#define FILLER(x) DUMMYUNIONNAME.DUMMYSTRUCTNAME.x
#else
#define FILLER(x) x
#endif
and then you can code
dec->FILLER(scale)

--
Remove del for email
From: Emmanuel Stapf [ES] on
>> I have to compile my code using -DNONAMELESSUNION but can't recall if I
>> still need to do that.
>
> It depends on why you were doing it in the first place.

I just rechecked and found that I used this macro so that code would
compile the same between Borland and Microsoft when using the
TV_INSERTSTRUCT struct which structure must had its definition change
the same way tagDEC got changed this time around.

>> David Lowndes wrote:
>>>> I had some code that looks like:
>>>>
>>>> DECIMAL dec;
>>>>
>>>> ... dec->scale ...
>
> Since DECIMAL is a structure type and not a pointer type, this code
> cannot compile successfully.

It was indeed a typo in my sample, I meant DECIMAL *dec;

> You could define two macros: VERSION and FILLER. The first (which you
> would set as a compile parameter) would indicate which version and the
> second would compensate for the difference the structure definition.
> Something like
> #if VERSION == 6.1
> #define FILLER(x) DUMMYUNIONNAME.DUMMYSTRUCTNAME.x
> #else
> #define FILLER(x) x
> #endif
> and then you can code
> dec->FILLER(scale)

Is there a way to get the version directly from the Microsoft headers? I
do not know in advance which combination of C compiler and windows sdk
headers I have to compile.

Thanks,
Manu

From: Alex Blekhman on
"Emmanuel Stapf [ES]" wrote:
> The old definition look like:
>
> typedef struct tagDEC {
> USHORT wReserved;
> union {
> struct {
> BYTE scale;
> BYTE sign;
> };
> USHORT signscale;
> };
> ULONG Hi32;
> ...
> } DECIMAL;
>
>
> The new one like:
>
> typedef struct tagDEC {
> USHORT wReserved;
> union {
> struct {
> BYTE scale;
> BYTE sign;
> } DUMMYSTRUCTNAME;
> USHORT signscale;
> } DUMMYUNIONNAME;
> ULONG Hi32;
> ...
> } DECIMAL;
>
> I have to compile my code using -DNONAMELESSUNION but can't
> recall if I still need to do that.

You need to compile with NONAMELESSUNION symbol defined if you use
a compiler that doesn't support nameless unions/structs. AFAIK,
every modern compiler supports it, so you should be able to
compile your code without a problem. I don't have PSDK v6.1 right
now, but it seems that MS forgot to include the definition of
DUMMYSTRUCTNAME. Search PSDK headers for this name, maybe you'll
find it somewhere. If not, thne you can easily define
DUMMYSTRUCTNAME by yourself:

// Put this code before #include <Windows.h>
//
#ifndef DUMMYSTRUCTNAME
#ifdef NONAMELESSSTRUCT
#define DUMMYSTRUCTNAME s
#define DUMMYSTRUCTNAME2 s2
#define DUMMYSTRUCTNAME3 s3
#define DUMMYSTRUCTNAME4 s4
#define DUMMYSTRUCTNAME5 s5
#else
#define DUMMYSTRUCTNAME
#define DUMMYSTRUCTNAME2
#define DUMMYSTRUCTNAME3
#define DUMMYSTRUCTNAME4
#define DUMMYSTRUCTNAME5
#endif
#endif // DUMMYSTRUCTNAME

The above definition is the same as DUMMYUNIONNAME.

HTH
Alex