digitalmars.D - win32 and struct aligment
- bobef <bobef_member pathlink.com> Jun 02 2005
- Brad Beveridge <brad somewhere.net> Jun 02 2005
- bobef <bobef_member pathlink.com> Jun 02 2005
- Brad Beveridge <brad somewhere.net> Jun 02 2005
- bobef <bobef_member pathlink.com> Jun 02 2005
- "Andrew Fedoniouk" <news terrainformatica.com> Jun 02 2005
- bobef <bobef_member pathlink.com> Jun 02 2005
- "Regan Heath" <regan netwin.co.nz> Jun 02 2005
- "Regan Heath" <regan netwin.co.nz> Jun 02 2005
- bobef <bobef_member pathlink.com> Jun 02 2005
- "Regan Heath" <regan netwin.co.nz> Jun 02 2005
- "Regan Heath" <regan netwin.co.nz> Jun 02 2005
- "Andrew Fedoniouk" <news terrainformatica.com> Jun 02 2005
- "Walter" <newshound digitalmars.com> Jun 02 2005
- "Andrew Fedoniouk" <news terrainformatica.com> Jun 02 2005
- bobef <bobef_member pathlink.com> Jun 03 2005
- "Walter" <newshound digitalmars.com> Jun 03 2005
- Brad Beveridge <brad somewhere.net> Jun 03 2005
- bobef <bobef_member pathlink.com> Jun 04 2005
I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as
align(1). So I defined it this way
align(1) struct NMPGSCROLL
{
NMHDR hdr;
WORD fwKeys;
RECT rcParent;
int iDir;
int iXpos;
int iYpos;
int iScroll;
}
but when I have
NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam);
s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also
if I have like that
NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam);
s.alignof is 1 but values are still messed up.
Any suggestions what may be wrong?
Jun 02 2005
bobef wrote:I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
32 bit machines), so it makes sense that NMPGSCROLL *s has alignof 4, also it makes sense that if lParam is actually a pointer then its lowest 2 bits will be zero - ie, it is also aligned on 4 byte boundrys. My only thoughts are 1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent 2) do the s.iScroll.offsetof, etc, numbers add up? Brad
Jun 02 2005
no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
I can't understand the question... Mixture of bad english and bad D... In article <d7nkfi$227p$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
32 bit machines), so it makes sense that NMPGSCROLL *s has alignof 4, also it makes sense that if lParam is actually a pointer then its lowest 2 bits will be zero - ie, it is also aligned on 4 byte boundrys. My only thoughts are 1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent 2) do the s.iScroll.offsetof, etc, numbers add up? Brad
Jun 02 2005
bobef wrote:no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad
Jun 02 2005
struct RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
}
and LONG is alias for int
rcParent.alignof says 4
In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...
bobef wrote:
no property 'offsetof' for type 'int'
This is what I get....
1) What is the packing/alignment of RECT & does the align actually
effect the packing of rcParent
http://digitalmars.com/d/struct.html
What I was trying to say before - you have a type of RECT in your
struct. I think that RECT may be another structure. I was trying to
ask you to check that the RECT structure wasn't being padded out.
For example, assume that RECT is align 4, and is
struct RECT
{
char x,y;
}
There will be 2 bytes of padding after x & y. Now, when you embed RECT
inside of your other struct, does the align(1) directive also remove the
padding from RECT? I don't know, but I would hope that it does.
Brad
Jun 02 2005
typedef struct {
NMHDR hdr;
BOOL fwKeys; // <<<<<<<<<<<<<<<<<
RECT rcParent;
int iDir;
int iXpos;
int iYpos;
int iScroll;
}NMPGSCROLL,
BOOL is not WORD.
align(1) struct NMPGSCROLL
{
NMHDR hdr;
WORD fwKeys; // <<<<<<<<<<<<<<<<<<
RECT rcParent;
int iDir;
int iXpos;
int iYpos;
int iScroll;
}
"bobef" <bobef_member pathlink.com> wrote in message
news:d7nqij$28cl$1 digitaldaemon.com...
struct RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
}
and LONG is alias for int
rcParent.alignof says 4
In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...
bobef wrote:
no property 'offsetof' for type 'int'
This is what I get....
1) What is the packing/alignment of RECT & does the align actually
effect the packing of rcParent
http://digitalmars.com/d/struct.html
What I was trying to say before - you have a type of RECT in your
struct. I think that RECT may be another structure. I was trying to
ask you to check that the RECT structure wasn't being padded out.
For example, assume that RECT is align 4, and is
struct RECT
{
char x,y;
}
There will be 2 bytes of padding after x & y. Now, when you embed RECT
inside of your other struct, does the align(1) directive also remove the
padding from RECT? I don't know, but I would hope that it does.
Brad
Jun 02 2005
MSDN says it is BOOL but it is WORD in the ms platform sdk 2003 headers... Both of them doesn't work :) In article <d7nrme$29cl$1 digitaldaemon.com>, Andrew Fedoniouk says...typedef struct { NMHDR hdr; BOOL fwKeys; // <<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }NMPGSCROLL, BOOL is not WORD. align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; // <<<<<<<<<<<<<<<<<< RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } "bobef" <bobef_member pathlink.com> wrote in message news:d7nqij$28cl$1 digitaldaemon.com...struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad
Jun 02 2005
I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad
Jun 02 2005
On Fri, 03 Jun 2005 08:55:14 +1200, Regan Heath <regan netwin.co.nz> wrote:I've had a number of these problems, I think it's just none of those things that happens when you port from C to D.
Erg ... "none" == "one" (cold fingers, early morning..) ReganThe way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad
Jun 02 2005
How to print the aligment in C? Also DMC headers miss the pager control so I
write it myself and I guess I will end up with the same problem in C. I've
downloaded some japanese windows api translation and it was done in the same way
I did it. I don't if they made it work.
align(1):
struct _16 {
NMHDR hdr;
WORD fwKeys;
RECT rcParent;
int iDir;
int iXpos;
int iYpos;
int iScroll;
}
alias _16 NMPGSCROLL;
alias _16* LPNMPGSCROLL;
In article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...
I've had a number of these problems, I think it's just none of those
things that happens when you port from C to D.
The way I go about solving them is by printing the alignment, offset and
size of every member of the struct using D, then doing the same using C.
One important point to note is that your D code is linking with the DMC
libraries so if the struct you are using comes from within a DMC library
you should really use DMC to compile your C. (I got bit by the differences
between findfirst in MSVC and DMC)
Regan
On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com>
wrote:
struct RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
}
and LONG is alias for int
rcParent.alignof says 4
In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...
bobef wrote:
no property 'offsetof' for type 'int'
This is what I get....
1) What is the packing/alignment of RECT & does the align actually
effect the packing of rcParent
http://digitalmars.com/d/struct.html
What I was trying to say before - you have a type of RECT in your
struct. I think that RECT may be another structure. I was trying to
ask you to check that the RECT structure wasn't being padded out.
For example, assume that RECT is align 4, and is
struct RECT
{
char x,y;
}
There will be 2 bytes of padding after x & y. Now, when you embed RECT
inside of your other struct, does the align(1) directive also remove the
padding from RECT? I don't know, but I would hope that it does.
Brad
Jun 02 2005
On Thu, 2 Jun 2005 21:20:49 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:How to print the aligment in C?
#include <stdlib.h> #include <stdio.h> #define print_member(base,x) { printf(#x"%*s = (%02d) 0x%08x-0x%08x,%d\n",10-strlen(#x),"",(int)&x-(int)&base,&x,((int)&x)+siz of(x)-1,sizeof(x)); } typedef struct test { int a; short b; char c; } TEST; void main() { TEST tmp; print_member(tmp,tmp.a); print_member(tmp,tmp.b); print_member(tmp,tmp.c); } replace TEST with the struct to test.Also DMC headers miss the pager control so I write it myself and I guess I will end up with the same problem in C.
Wrote it in C? then compiled to a lib? or.. what did you compile it with?I've downloaded some japanese windows api translation and it was done in the same way I did it. I don't if they made it work. align(1): struct _16 { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } alias _16 NMPGSCROLL; alias _16* LPNMPGSCROLL;
I would have preferred (not that it makes a difference): struct NMPGSCROLL { ..etc.. } alias NMPGSCROLL* LPNMPGSCROLL; ReganIn article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...I've had a number of these problems, I think it's just none of those things that happens when you port from C to D. The way I go about solving them is by printing the alignment, offset and size of every member of the struct using D, then doing the same using C. One important point to note is that your D code is linking with the DMC libraries so if the struct you are using comes from within a DMC library you should really use DMC to compile your C. (I got bit by the differences between findfirst in MSVC and DMC) Regan On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef <bobef_member pathlink.com> wrote:struct RECT { LONG left; LONG top; LONG right; LONG bottom; } and LONG is alias for int rcParent.alignof says 4 In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...bobef wrote:no property 'offsetof' for type 'int' This is what I get....1) What is the packing/alignment of RECT & does the align actually effect the packing of rcParent
http://digitalmars.com/d/struct.html What I was trying to say before - you have a type of RECT in your struct. I think that RECT may be another structure. I was trying to ask you to check that the RECT structure wasn't being padded out. For example, assume that RECT is align 4, and is struct RECT { char x,y; } There will be 2 bytes of padding after x & y. Now, when you embed RECT inside of your other struct, does the align(1) directive also remove the padding from RECT? I don't know, but I would hope that it does. Brad
Jun 02 2005
I also noted in the MSVC header richedit.h, this:
#ifdef _WIN32
# define _WPAD /##/
#else
# define _WPAD WORD
#endif
where _WPAD is used in the:
typedef struct _nmhdr
{
HWND hwndFrom;
_WPAD _wPad1;
UINT idFrom;
_WPAD _wPad2;
UINT code;
_WPAD _wPad3;
} NMHDR;
struct.
Regan
On Thu, 2 Jun 2005 21:20:49 +0000 (UTC), bobef <bobef_member pathlink.com>
wrote:
How to print the aligment in C? Also DMC headers miss the pager control
so I
write it myself and I guess I will end up with the same problem in C.
I've
downloaded some japanese windows api translation and it was done in the
same way
I did it. I don't if they made it work.
align(1):
struct _16 {
NMHDR hdr;
WORD fwKeys;
RECT rcParent;
int iDir;
int iXpos;
int iYpos;
int iScroll;
}
alias _16 NMPGSCROLL;
alias _16* LPNMPGSCROLL;
In article <opsrrgecsx23k2f5 nrage.netwin.co.nz>, Regan Heath says...
I've had a number of these problems, I think it's just none of those
things that happens when you port from C to D.
The way I go about solving them is by printing the alignment, offset and
size of every member of the struct using D, then doing the same using C.
One important point to note is that your D code is linking with the DMC
libraries so if the struct you are using comes from within a DMC library
you should really use DMC to compile your C. (I got bit by the
differences
between findfirst in MSVC and DMC)
Regan
On Thu, 2 Jun 2005 20:35:31 +0000 (UTC), bobef
<bobef_member pathlink.com>
wrote:
struct RECT
{
LONG left;
LONG top;
LONG right;
LONG bottom;
}
and LONG is alias for int
rcParent.alignof says 4
In article <d7np1t$26up$1 digitaldaemon.com>, Brad Beveridge says...
bobef wrote:
no property 'offsetof' for type 'int'
This is what I get....
1) What is the packing/alignment of RECT & does the align actually
effect the packing of rcParent
http://digitalmars.com/d/struct.html
What I was trying to say before - you have a type of RECT in your
struct. I think that RECT may be another structure. I was trying to
ask you to check that the RECT structure wasn't being padded out.
For example, assume that RECT is align 4, and is
struct RECT
{
char x,y;
}
There will be 2 bytes of padding after x & y. Now, when you embed
RECT
inside of your other struct, does the align(1) directive also remove
the
padding from RECT? I don't know, but I would hope that it does.
Brad
Jun 02 2005
Check alignment of NMHDR. Andrew. "bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure is defined as align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is 4. Also if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
Jun 02 2005
"bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure is
align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is
if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Jun 02 2005
"Walter" <newshound digitalmars.com> wrote in message news:d7nv6c$2cgp$1 digitaldaemon.com..."bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure is
align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is
if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Good one!
Jun 02 2005
In article <d7ob83$2li3$1 digitaldaemon.com>, Andrew Fedoniouk says..."Walter" <newshound digitalmars.com> wrote in message news:d7nv6c$2cgp$1 digitaldaemon.com..."bobef" <bobef_member pathlink.com> wrote in message news:d7nk3e$21qj$1 digitaldaemon.com...I have the folloing problem: in win32 headers NMPGSCROLL structure is
align(1). So I defined it this way align(1) struct NMPGSCROLL { NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; } but when I have NMPGSCROLL *s=(cast(NMPGSCROLL*)lParam); s.iScroll is messed up no matter if align is 1 and s.alignof says it is
if I have like that NMPGSCROLL s=*(cast(NMPGSCROLL*)lParam); s.alignof is 1 but values are still messed up. Any suggestions what may be wrong?
If you want the *members* to be aligned a certain way, rather than the struct itself, put the align directive inside the struct: struct NMPGSCROLL { align(1): NMHDR hdr; WORD fwKeys; RECT rcParent; int iDir; int iXpos; int iYpos; int iScroll; }
Good one!
Good one but it still works the same (wrong) way... Can't I realign it myself? something like char[4] a=cast(char[4])s.iScroll and then change bytes positions? I don't have any idea what this aligment thing is and what is it's use except it is ruining my code :)
Jun 03 2005
"bobef" <bobef_member pathlink.com> wrote in message news:d7p8fh$9qe$1 digitaldaemon.com...Good one but it still works the same (wrong) way...
It works (i.e. produces the same result) as the C compiler's alignment directives on the same struct.Can't I realign it myself? something like char[4] a=cast(char[4])s.iScroll and then change bytes positions?
???I don't have any idea what this aligment thing is and what is it's use
is ruining my code :)
Why are you using it? Exactly what are you trying to achieve?
Jun 03 2005
Walter wrote:"bobef" <bobef_member pathlink.com> wrote in messageI don't have any idea what this aligment thing is and what is it's use
except itis ruining my code :)
Why are you using it? Exactly what are you trying to achieve?
then that structure won't be tightly packed I don't think - in which case, telling D to pack the structure may be a bit broken :) Brad
Jun 03 2005
In article <d7qql5$1j2t$1 digitaldaemon.com>, Walter says...I don't have any idea what this aligment thing is and what is it's use
is ruining my code :)
Why are you using it? Exactly what are you trying to achieve?
I am not using it because it doesn't work or at least I don't know how to make it work, but I need it because I need a Pager Control and definition of NMPGSCROLL, or whatever it was, in the ms headers have #include <pshpack1.h> and #include <poppack.h> around it, which says #pragma(pack,1), which I believe, should be equivalent of D's align(1). This is why. But all numbers are messed up! damn.
Jun 04 2005









bobef <bobef_member pathlink.com> 