Advertisement Jump to content
Sign in to follow this  

(c to vb) 1-byte aligned struct in VB?

This topic is 4560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to port an IOCTL sample over from C to VB, but i'm hence my little knowledge of C, i got stuck. (it's the IOCTL sample from PPJoy to simulate a joystick) This is my (current) problem:
'#pragma pack(push,1)        /* All fields in structure must be byte aligned. */
'typedef struct
' unsigned long  Signature;              /* Signature to identify packet to PPJoy IOCTL */
' char           NumAnalog;              /* Num of analog values we pass */
' long           Analog[NUM_ANALOG];     /* Analog values */
' char           NumDigital;             /* Num of digital values we pass */
' char           Digital[NUM_DIGITAL];   /* Digital values */
'#pragma pack(pop)
can someone trie to explain to me what i should do to create an equalent in VB? After the struct is set etc. it's used like this:

Share this post

Link to post
Share on other sites
VB6. I created a type like this:

NumAnalog as byte
Analog(NUM_ANALOG) as long
NumDigital as byte
Digital(NUM_DIGITAL) as byte
end type

and i checked, it's the same size as the C struct.
Any ideas?

Share this post

Link to post
Share on other sites
Try this:

Signature As Long
NumAnalog As Byte
Analog(NUM_ANALOG) As Long
NumDigital As Byte
Digital(NUM_DIGITAL) As Byte
End Type

Public Declare Function DeviceIoControl Lib "kernel32.dll" _
(ByRef hDevice As Long, _
ByVal dwIoControlCode As Long, _
ByRef lpInBuffer As JOYSTICK_STATE, _
ByVal nInBufferSize As Long, _
ByRef lpOutBuffer As Long, _
ByVal nOutBufferSize As Long, _
ByRef lpBytesReturned As Long, _
ByRef lpOverlapped As Long) As Long

' and this to call it
DeviceIoControl(h, IOCTL_PPORTJOY_SET_STATE, JoyState, Len(JoyState), 0, 0, RetSize, 0)

Share this post

Link to post
Share on other sites
hmm, still doesn't work. i'm beginning to think something else is wrong, maybe the part where i get the handle (C version above, VB version below):
'DevName= "\\\\.\\PPJoyIOCTL1";
DevName = "\\.\PPJoyIOCTL1"

h = CreateFile(DevName, GENERIC_WRITE, FILE_SHARE_WRITE, ByVal CLng(0), OPEN_EXISTING, 0, ByVal CLng(0))
i do get a handle in return, so i think it's weird if this is why it fails.
As allways, any help is greatly apreciated!

[Edited by - -Fruz- on July 29, 2006 7:29:31 PM]

Share this post

Link to post
Share on other sites
Why do you need to interface with the hardware directly? Reading a joystick is much easier using joyGetPosEx

If you have to use direct hardware interfacing, you'd do it like ronkfist said except that I think the handle should by ByVal and not ByRef - ByRef is only for things passed as pointers, and the handle is not passed as a pointer (even though it IS a pointer). VB6 comes with a tool that has the prototypes for everything, and you should check that, because I'm certainly not sure

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!