when I use
hr := g_pJoystick.CreateEffect(GUID_ConstantForce,@eff,g _pEffect,Nil);
it return -2147024809 to hr. How can I fix it.
I use clootie Directx9.0c header.
Sorry for my bad english I come from Thailand. 0^0
**************************************************
[pascal]function TJoyst.InitDirectInput: HRESULT;
var hr: HRESULT;
diprg: TDIPROPDWORD;
rgdwAxes: Array[0..1] of DWORD;
rglDirection: Array[0..1] of LongInt;
cf : Array[0..0] of DICONSTANTFORCE;
eff : DIEFFECT;
begin
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
hr := DirectInput8Create( HInstance, DIRECTINPUT_VERSION,
IID_IDirectInput8, g_pDI, nil );
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
// Look for a simple joystick we can use for this sample program.
hr := g_pDI.EnumDevices( DI8DEVCLASS_GAMECTRL,
EnumFFDevicesCallback,
nil,DIEDFL_ATTACHEDONLY or DIEDFL_FORCEFEEDBACK );
if FAILED( hr ) then
begin
Result := hr;
Application.MessageBox( 'Force feedback device not found. The sample will now exit.',
'DirectInput Sample',
MB_ICONERROR or MB_OK );
Exit;
end;
// Make sure we got a joystick
if g_pJoystick = nil then
begin
Application.MessageBox( 'Joystick not found. The sample will now exit.',
'DirectInput Sample',
MB_ICONERROR or MB_OK );
Close;
Result := S_OK;
Exit;
end;
// Set the data format to "simple joystick" - a predefined data format
//
// A data format specifies which controls on a device we are interested in,
// and how they should be reported. This tells DInput that we will be
// passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
hr := g_pJoystick.SetDataFormat( c_dfDIJoystick );
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
hr := g_pJoystick.SetCooperativeLevel( Handle, DISCL_EXCLUSIVE or DISCL_FOREGROUND );
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
diprg.diph.dwSize := sizeof(TDIPROPDWORD);
diprg.diph.dwHeaderSize := sizeof(TDIPropHeader);
diprg.diph.dwHow := DIPH_DEVICE;
diprg.diph.dwObj := 0; // Specify the enumerated axis
diprg.dwData := 0;
// Set the range for the axis
hr := g_pJoystick.SetProperty( DIPROP_AUTOCENTER, diprg.diph );
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
// Enumerate the axes of the joyctick and set the range of each axis. Note:
// we could just use the defaults, but we're just trying to show an example
// of enumerating device objects (axes, buttons, etc.).
g_pJoystick.EnumObjects( EnumAxesCallback,@g_dwNumForceFeedbackAxis, DIDFT_AXIS );
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
if( g_dwNumForceFeedbackAxis > 2 ) then
g_dwNumForceFeedbackAxis := 2;
// Determine how many axis the joystick has (so we don't error out setting
// properties for unavailable axis)
rgdwAxes[0] := DIJOFS_X;
rgdwAxes[1] := DIJOFS_Y;
rglDirection[0]:= 0;
rglDirection[1]:= 0;
//cf[0] := ;
ZeroMemory( @eff, sizeof(eff) );
eff.dwSize := sizeof(DIEFFECT);
eff.dwFlags := DIEFF_CARTESIAN or DIEFF_OBJECTOFFSETS;
eff.dwDuration := INFINITE;
eff.dwSamplePeriod := 0;
eff.dwGain := DI_FFNOMINALMAX;
eff.dwTriggerButton := DIEB_NOTRIGGER;
eff.dwTriggerRepeatInterval := 0;
eff.cAxes := g_dwNumForceFeedbackAxis;
eff.rgdwAxes := @rgdwAxes;
eff.rglDirection := @rglDirection;
eff.lpEnvelope := 0;
eff.cbTypeSpecificParams := sizeof(DICONSTANTFORCE);
eff.lpvTypeSpecificParams := @cf;
//eff.dwStartDelay := 0;
g_diDevCaps.dwSize := SizeOf(TDIDevCaps);
hr := g_pJoystick.CreateEffect( GUID_ConstantForce,@eff,g_pEffect,Nil);
if FAILED( hr ) then
begin
Result := hr;
Exit;
end;
Result := S_OK;
end;[/pascal]
Bookmarks