From: Karl E. Peterson on
I have a bad feeling about this one. Trying to translate the following
structure:

typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, *PRAWINPUT, *LPRAWINPUT;

typedef struct tagRAWMOUSE {
USHORT usFlags;
union {
ULONG ulButtons;
struct {
USHORT usButtonFlags;
USHORT usButtonData;
} ;
} ;
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformation;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;

Source: http://msdn.microsoft.com/en-us/library/ms645562(v=VS.85).aspx

.... into something a little more VBish:

Private Type RAWINPUTHEADER
dwType As Long
dwSize As Long
hDevice As Long
wParam As Long
End Type

Private Type RAWINPUTMOUSE
hdr As RAWINPUTHEADER
Flags As Integer
ButtonFlags As Integer
ButtonData As Integer
RawButtons As Long
LastX As Long
LastY As Long
ExtraInfo As Long
End Type

It's supposedly being handed to me in a buffer, and it's looking like
I'll need to reconstruct it manually, because of those three
consecutive 16-bit values. The required buffer size is 38, as well,
which reinforces this fear. (The VB incarnation of that structure is
40 bytes long.)

Damn thing is, the values I'm getting are just non-sensical once you
get past the header element (first four values). For example:

=================================================================================
lpBuffer = &h70F0060 nBytes = 40
070F0060 0000 00 00 00 00 28 00 00 00-3B 00 0B 00 00 00 00 00
.....(...;.......
070F0070 0010 00 00 00 00 00 00 00 00-00 00 00 00 01 00 00 00
.................
070F0080 0020 00 00 00 00 00 00 00 00-
.........
=================================================================================

rim.hdr.dwType = 0
rim.hdr.dwSize = 40
rim.hdr.hDevice = 720955
rim.hdr.wParam = 0
rim.Flags= 0
rim.ButtonFlags = 0
rim.ButtonData = 0
rim.RawButtons = 0
rim.LastX = 65536
rim.LastY = 0
rim.ExtraInfo = 0

Did I mistranslate, or misunderstand, the structure?

Thanks...

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Karl E. Peterson on
Once again proving the notion that for a solution to *whack* you upside
the head, there's no quicker way than to ask for help! :-)

Well, yeah, VB does dword align that structure. And, remarkably(?), so
does Windows. I just passed a pointer to the structure to
GetRawInputData, and it filled it up nicely. Jeeeez, just shows how
easy it is to overthink some of this stuff.

Ah well...


Karl E. Peterson used his keyboard to write :
> I have a bad feeling about this one. Trying to translate the following
> structure:
>
> typedef struct tagRAWINPUT {
> RAWINPUTHEADER header;
> union {
> RAWMOUSE mouse;
> RAWKEYBOARD keyboard;
> RAWHID hid;
> } data;
> } RAWINPUT, *PRAWINPUT, *LPRAWINPUT;
>
> typedef struct tagRAWMOUSE {
> USHORT usFlags;
> union {
> ULONG ulButtons;
> struct {
> USHORT usButtonFlags;
> USHORT usButtonData;
> } ;
> } ;
> ULONG ulRawButtons;
> LONG lLastX;
> LONG lLastY;
> ULONG ulExtraInformation;
> } RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
>
> Source: http://msdn.microsoft.com/en-us/library/ms645562(v=VS.85).aspx
>
> ... into something a little more VBish:
>
> Private Type RAWINPUTHEADER
> dwType As Long
> dwSize As Long
> hDevice As Long
> wParam As Long
> End Type
>
> Private Type RAWINPUTMOUSE
> hdr As RAWINPUTHEADER
> Flags As Integer
> ButtonFlags As Integer
> ButtonData As Integer
> RawButtons As Long
> LastX As Long
> LastY As Long
> ExtraInfo As Long
> End Type
>
> It's supposedly being handed to me in a buffer, and it's looking like I'll
> need to reconstruct it manually, because of those three consecutive 16-bit
> values. The required buffer size is 38, as well, which reinforces this fear.
> (The VB incarnation of that structure is 40 bytes long.)
>
> Damn thing is, the values I'm getting are just non-sensical once you get past
> the header element (first four values). For example:
>
> =================================================================================
> lpBuffer = &h70F0060 nBytes = 40
> 070F0060 0000 00 00 00 00 28 00 00 00-3B 00 0B 00 00 00 00 00
> ....(...;.......
> 070F0070 0010 00 00 00 00 00 00 00 00-00 00 00 00 01 00 00 00
> ................
> 070F0080 0020 00 00 00 00 00 00 00 00- ........
> =================================================================================
>
> rim.hdr.dwType = 0
> rim.hdr.dwSize = 40
> rim.hdr.hDevice = 720955
> rim.hdr.wParam = 0
> rim.Flags= 0
> rim.ButtonFlags = 0
> rim.ButtonData = 0
> rim.RawButtons = 0
> rim.LastX = 65536
> rim.LastY = 0
> rim.ExtraInfo = 0
>
> Did I mistranslate, or misunderstand, the structure?
>
> Thanks...

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Kevin Provance on
I'll trade you projects. I'm working on a way to make CDECL API calls work
through VB, which for the most part, I've done...but since massive callbacks
are involved, along with pointers to UDTs, the smallest inconsistancy in
code causes the whole project to blow up.

I don't know why I bother really. I could just write the damned thing in
Delphi and be done with it.


"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:i25bec$eni$1(a)news.eternal-september.org...
: Once again proving the notion that for a solution to *whack* you upside
: the head, there's no quicker way than to ask for help! :-)
:
: Well, yeah, VB does dword align that structure. And, remarkably(?), so
: does Windows. I just passed a pointer to the structure to
: GetRawInputData, and it filled it up nicely. Jeeeez, just shows how
: easy it is to overthink some of this stuff.
:
: Ah well...
:
:
: Karl E. Peterson used his keyboard to write :
: > I have a bad feeling about this one. Trying to translate the following
: > structure:
: >
: > typedef struct tagRAWINPUT {
: > RAWINPUTHEADER header;
: > union {
: > RAWMOUSE mouse;
: > RAWKEYBOARD keyboard;
: > RAWHID hid;
: > } data;
: > } RAWINPUT, *PRAWINPUT, *LPRAWINPUT;
: >
: > typedef struct tagRAWMOUSE {
: > USHORT usFlags;
: > union {
: > ULONG ulButtons;
: > struct {
: > USHORT usButtonFlags;
: > USHORT usButtonData;
: > } ;
: > } ;
: > ULONG ulRawButtons;
: > LONG lLastX;
: > LONG lLastY;
: > ULONG ulExtraInformation;
: > } RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;
: >
: > Source: http://msdn.microsoft.com/en-us/library/ms645562(v=VS.85).aspx
: >
: > ... into something a little more VBish:
: >
: > Private Type RAWINPUTHEADER
: > dwType As Long
: > dwSize As Long
: > hDevice As Long
: > wParam As Long
: > End Type
: >
: > Private Type RAWINPUTMOUSE
: > hdr As RAWINPUTHEADER
: > Flags As Integer
: > ButtonFlags As Integer
: > ButtonData As Integer
: > RawButtons As Long
: > LastX As Long
: > LastY As Long
: > ExtraInfo As Long
: > End Type
: >
: > It's supposedly being handed to me in a buffer, and it's looking like
I'll
: > need to reconstruct it manually, because of those three consecutive
16-bit
: > values. The required buffer size is 38, as well, which reinforces this
fear.
: > (The VB incarnation of that structure is 40 bytes long.)
: >
: > Damn thing is, the values I'm getting are just non-sensical once you get
past
: > the header element (first four values). For example:
: >
: >
=================================================================================
: > lpBuffer = &h70F0060 nBytes = 40
: > 070F0060 0000 00 00 00 00 28 00 00 00-3B 00 0B 00 00 00 00 00
: > ....(...;.......
: > 070F0070 0010 00 00 00 00 00 00 00 00-00 00 00 00 01 00 00 00
: > ................
: > 070F0080 0020 00 00 00 00 00 00 00 00-
.........
: >
=================================================================================
: >
: > rim.hdr.dwType = 0
: > rim.hdr.dwSize = 40
: > rim.hdr.hDevice = 720955
: > rim.hdr.wParam = 0
: > rim.Flags= 0
: > rim.ButtonFlags = 0
: > rim.ButtonData = 0
: > rim.RawButtons = 0
: > rim.LastX = 65536
: > rim.LastY = 0
: > rim.ExtraInfo = 0
: >
: > Did I mistranslate, or misunderstand, the structure?
: >
: > Thanks...
:
: --
: .NET: It's About Trust!
: http://vfred.mvps.org
:
:

From: Karl E. Peterson on
Kevin Provance was thinking very hard :
> I'll trade you projects. I'm working on a way to make CDECL API calls work
> through VB, which for the most part, I've done...but since massive callbacks
> are involved, along with pointers to UDTs, the smallest inconsistancy in
> code causes the whole project to blow up.

I feel that pain. I really should've known how Windows would align
that structure, too. It was the translation to VB that caused the
confusion.

> I don't know why I bother really. I could just write the damned thing in
> Delphi and be done with it.

<chuckle>

--
..NET: It's About Trust!
http://vfred.mvps.org