More WinAPI Stuff

Archives Forums/Win32 Discussion/More WinAPI Stuff

_PJ_(Posted 2009) [#1]
]I figured this was perhaps the best place for this as ythe discussion had moved on...

Okay.,.. I am not good at this.

I have managed to obtain the following info on joyGetDevCaps() from MSDN,


joyGetDevCaps(
  UINT_PTR  uJoyID, 
  LPJOYCAPS pjc,    
  UINT      cbjc    
);



typedef struct { 
    WORD wMid; 
    WORD wPid; 
    TCHAR szPname[MAXPNAMELEN]; 
    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; 
    TCHAR szRegKey[MAXPNAMELEN]; 
    TCHAR szOEMVxD[MAX_JOYSTICKOEMVXDNAME]; 
} JOYCAPS;


I understand a 'Structure' to be equivalent in C to a Blitz 'Custom Type', however, I am not sure how to actually extract the 'fields'.

I've gotten only so far with the Decls:
.lib "WinAPI.dll"
GetController(uJoyID,pjc,cbjc):"joyGetDevCaps"

(Which I'm totally proud of the fact the function shows up in the Blitz IDE, tregardless of it working or not!!!)

To test this, I made the extremely simple bb code:

Print GetController(0,0,0)


Which results in an "Illegal Type Conversion".
I'm guessing it's because I need some form of syntax to point to the fields I want, not just leave the parameters as they are, but I have no clue how to go about this.

Apologies for my complete ignorance, but any pointers would be really helpful!


_PJ_(Posted 2009) [#2]
Surely someone has made decls files for functions that are based on Structs before?
Please, any suggestions would be helpful, I'm at a total loss myself.


Warner(Posted 2009) [#3]
Well, it has been a while since I did this type of stuff, but I think for the pointer type parameters, you could create a bank:
uJoyID = createbank(1)
cbjc = size of JOYCAPS structure above
pjc = createbank( cbjc )

Print GetController(uJoyID, pjc, cbjc)


It could be possible to use a Type as well, but I never did that, so I don't know.

You can find the size of JOYCAPS by adding up the bytes of each field. Word/UInt=2 byte (or maybe UINT=4 bytes, well try it and if it doesn't work, then Google it). And I think that the TCHARS should be 16 bytes in length, because a quick Google search gave me MAXPNAMELEN=16.

What is important, is that the bank size isn't too small. If it is too big, it is a waste of memory, but not a reason for errors. So, as a test, you might as well make it a very large bank. Then, if it works, you can calculate the length more precise.

Then, in your declaration, you should add an asterix after the pointer type parameters. I can valguely remember that at some point it didn't work anymore, but it should be something along the lines of this:
.lib "WinAPI.dll"
  GetController(uJoyID*, pjc*, cbjc):"joyGetDevCaps"


After calling GetController, and no error is showing up, you can read the bank, using PeekShort (for Words) PeekInt(for integers)
If there is a string, then you should read it byte-by-byte until you find a zero. That is a null-terminated string. Each byte is an ascii code.
repeat
c = PeekByte(bank, i)
if c = 0 then exit
write chr$(c)
i = i + 1
forever


Instead, as a test, you can read all the bytes in the bank and print them out. If there is a joystick name in there, you should be able to see it:
for i = 0 to banksize - 1
   if i mod 30 = 0 then print
   c = peekbyte(bank, i)
   write chr$(c)
next


Hopefully this helps, good luck!