PDA

View Full Version : DirectInput is wierd



Useless Hacker
03-12-2002, 10:21 AM
I've been trying to implement action mapping in my AlphaInput engine, but I'm a little puzzled about a few things.

Microsoft define the DIACTION stucture with a field named uAppData of type UINT_PTR. In the Delphi (JEDI) version (DirectInput8.pas), the uAppData member of TDIAction is defined as a pointer. According to the DirectX help file, uAppData should be a pointer to a value to be returned in the uAppData member of the DIDDEVICEDATA structure. However, in the C++ sample program, Multimapper, they pass various constant values in the uAppData member, not pointers, and the value which is returned is exactly the same piece of data. So, what exactly is a UINT_PTR, and should I just use a DWORD instead of a pointer?

Clootie
03-12-2002, 06:32 PM
UINT_PTR is integer with SizeOf(UINT_PTR)=SizeOf(Pointer). So basically it was designed to allow programmers pass either integer or pointer to something with variables of this type.

The bold line here - where are DirectX versions [beta & private] for 64bit processors.

Useless Hacker
04-12-2002, 10:50 AM
So it shouldn't be defined as Pointer in the JEDI headers? I've changed it to LongWord and it works fine.

Summers Gone
04-12-2002, 05:39 PM
PCardinal would be the closest, but Pointer is not wrong. As it doesn't matter what you reference there as long it's 4 Bytes (for 32 Bit Systems).
Like a Delphi Comp or something else.

Edit :
LongWord is wrong, it's double wrong too ... ;)

Useless Hacker
04-12-2002, 07:05 PM
LongWord is wrong, it's double wrong too ... ;)
Why? Maybe it should be a Cardinal, but not a PCardinal since then I can only pass pointers to cardinals. I think the problem only arises because Delphi is more strongly typed than C++, which seems to let you pass whatever you like.

Summers Gone
04-12-2002, 07:43 PM
Why? Maybe it should be a CardinalRight.

but not a PCardinal since then I can only pass pointers to cardinals.
Sure a PCardinal, passing a Pointer to Cardinal is exactly what you are supposed to do :
"Address of an application-defined UINT value to be returned ... "

Useless Hacker
04-12-2002, 08:00 PM
"Address of an application-defined UINT value to be returned ... "
This is what I originally thought. But MS's tutorial and demo program doesn't pass a pointer, it passes a #DEFINE'ed constant, which Delphi won't let you do because Cardinal and Pointer are different types.

Summers Gone
04-12-2002, 08:13 PM
const DefinedConstant : Cardinal = 2123;
{or const DefinedConstant = 2123; }
var DIAction : TDIAction;
begin
DIAction.uAppData := Pointer(DefinedConstant);
end;

This Syntax Highlighting Colors are a Joke !

Useless Hacker
04-12-2002, 08:39 PM
Yeah, except I don't really like putting all those typecasts in there, especially when there is a whole array of TDIAction things.

(Btw, you do know that
const DefinedConstant : Cardinal = 2123;
is not the same as
const DefinedConstant = 2123;
?

The first one is a typed constant, which is kept in memory, and the second is just a constant value that the compiler will replace references to with its value, which is why you cannot take the addess of the second type.)

Summers Gone
04-12-2002, 08:50 PM
Yes I know the difference. But the difference is of no importance here as
the Typecast is not used to get the Address of the constant, it's just a Typecast. It's only a Number after all, it's totally in your hands how you use it.