Results 1 to 11 of 11

Thread: Help with a structure declaration please

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Help with a structure declaration please

    FROM MSDN...
    JOYCAPS
    The JOYCAPS structure contains information about the joystick capabilities.

    typedef struct {
    WORD wMid;
    WORD wPid;
    CHAR szPname[32];
    UINT wXmin;
    UINT wXmax;
    UINT wYmin;
    UINT wYmax;
    UINT wZmin;
    UINT wZmax;
    UINT wNumButtons;
    UINT wPeriodMin;
    UINT wPeriodMax;
    UINT wRmin;
    UINT wRmax;
    UINT wUmin;
    UINT wUmax;
    UINT wVmin;
    UINT wVmax;
    UINT wCaps;
    UINT wMaxAxes;
    UINT wNumAxes;
    UINT wMaxButtons;
    CHAR szRegKey[32];
    CHAR szOEMVxD[260];
    } JOYCAPS;
    Can someone tell me how to declare this structure in VB please?

    I am trying to update an API call taht was originally coded in VB6 and now I have translated that into VB.net. But the extended version of that structure is as outlined above and I need to use that instead.

    I cannot find any examples of VB.net code for this. I think I'd need to use some kind of <attribute> tag but I am at a loss.

    Maybe one of you gurus can help? Its mainly the 3 CHAR arrays that I am having trouble with.
    I don't live here any more.

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Instead of char arrays put StringBuilders and set it's max capacity to the desired numbers
    \m/\m/

  3. #3
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    You could also have members of your structure as arrays of Byte's where the structure has CHAR arrays and then do the conversion to a string for your use...not real efficient, but would probably work well enough...

    HTH

    Hume

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I couldn't use stringbuilders, but the helpful error message that it prompted told me to use strings instead and initialise them in a certain manner, which I did.

    This is what I now have:

    VB Code:
    1. Private Structure JOYCAPS
    2.         Dim Mid As Short
    3.         Dim Pid As Short
    4.         Dim Pname As String
    5.         Dim Xmin As Integer
    6.         Dim Xmax As Integer
    7.         Dim Ymin As Integer
    8.         Dim Ymax As Integer
    9.         Dim Zmin As Integer
    10.         Dim Zmax As Integer
    11.         Dim NumButtons As Integer
    12.         Dim PeriodMin As Integer
    13.         Dim PeriodMax As Integer
    14.         Dim Rmin As Integer
    15.         Dim Rmax As Integer
    16.         Dim Umin As Integer
    17.         Dim Umax As Integer
    18.         Dim Vmin As Integer
    19.         Dim Vmax As Integer
    20.         Dim Caps As Integer
    21.         Dim MaxAxes As Integer
    22.         Dim NumAxes As Integer
    23.         Dim MaxButtons As Integer
    24.         Dim RegKey As String
    25.         Dim OEMVxD As String
    26.     End Structure

    But when I call the function with this structure (after initialising relevant properties) I get a return (error) code of 165. I have no idea what this code means and apparently no means of finding out. It could be anything from an unexpected data structure, to ANYTHING.

    I can't believe MSDN just leaves this structure like this without further info.

    Any ideas guys?
    I don't live here any more.

  5. #5
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Try this...Make your RegKey an Array of Bytes (and any other strings as well, assuming this is a C Type structure)

    ...
    RegKey(32) as Byte
    ...

    Then inside whatever routine you are writing, you will need to assemble a string based on the Byte indexes using the ASC function

    Also, the UINT could give you problems as well, since this is an unsigned INT which VB doesn't have. It is not the same as an Integer or Short.

    Lastly, I'm not sure if it will let you have a Structure member named Mid (since this is an intrinsic VB function)

    HTH

    Hume

  6. #6
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Sorry, should use the Chr function, not the Asc...

  7. #7
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Also, the UINT could give you problems as well, since this is an unsigned INT which VB doesn't have. It is not the same as an Integer or Short.
    Not true, System.uint16 and system.uint32. I would try using these for the WORD and UINT variables as Short and Integer are both signed variables.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  8. #8

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    I'm not bothered about the actual contents of the char arrays. I just need to get the structure compatible with the API call first. I tried your suggestion, it compiles without error, but it still returns the mystery 165 code.

    Most puzzling.
    I don't live here any more.

  9. #9
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    Have you looked at this line

    Dim Mid As Short

    Mid seems to be a keyword, maybe that is messing you up? Not sure.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  10. #10
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Sean,

    How do I do that in VB6.0? VB.NET, no problem, but I'm not sure how to access that in 6.0...

  11. #11
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Whoops, wrong forum. Thought this one was in Visual Bsaic Classic...sheepish grin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width