Linking to DirectSound

BlitzMax Forums/BlitzMax Beginners Area/Linking to DirectSound

Can anyone see why I cant get the SetCooperativeLevel method to work in directsound? This has been bugging me for hours.

Strict

Import Pub.Win32

Const DSSCL_NORMAL               = $00000001
Const DSSCL_PRIORITY             = $00000002
Const DSSCL_EXCLUSIVE            = $00000003
Const DSSCL_WRITEPRIMARY         = $00000004

Extern "win32"

Function GetActiveWindow()

Type IDirectSound8 Extends IUnknown


	Method CreateSoundBuffer( pcDSBufferDesc, ppDSBuffer Ptr, pUnkOuter)
	'Method GetCaps( pDSCaps )
	'Method DuplicateSoundBuffer( pDSBufferOriginal, ppDSBufferDuplicate Ptr)
	Method SetCooperativeLevel( hWnd, dwLevel )		
	'Method Compact()
	'Method GetSpeakerConfig( pdwSpeakerConfig )
	'Method SetSpeakerConfig( dwSpeakerConfig )
	'Method Initialize( pcGuidDevice )
	'Method VerifyCertification( pdwCertified )

Rem
    STDMETHOD(CreateSoundBuffer)    (THIS_ LPCDSBUFFERDESC, LPDIRECTSOUNDBUFFER *, LPUNKNOWN) PURE;
    STDMETHOD(GetCaps)              (THIS_ LPDSCAPS) PURE;
    STDMETHOD(DuplicateSoundBuffer) (THIS_ LPDIRECTSOUNDBUFFER, LPDIRECTSOUNDBUFFER *) PURE;
    STDMETHOD(SetCooperativeLevel)  (THIS_ HWND, DWORD) PURE;
    STDMETHOD(Compact)              (THIS) PURE;
    STDMETHOD(GetSpeakerConfig)     (THIS_ LPDWORD) PURE;
    STDMETHOD(SetSpeakerConfig)     (THIS_ DWORD) PURE;
    STDMETHOD(Initialize)           (THIS_ LPGUID) PURE;
End Rem

End Type

End Extern


 


Function PrintDSoundError(errornumber)
	Local txt$
	Select errornumber
		Case $00000000
			txt$="DS_OK"
		Case $00000007
			txt$="DSERR_OUTOFMEMORY"
		Case $000001AE
			txt$="DSERR_NOINTERFACE"
		Case $0878000A
			txt$="DSERR_NO_VIRTUALIZATION"
		Case $08980014
			txt$="DSERR_INCOMPLETE"
		Case $80004001
			txt$="DSERR_UNSUPPORTED"
		Case $80004005
			txt$="DSERR_GENERIC"
		Case $80070005
			txt$="DSERR_ACCESSDENIED"
		Case $80070057
			txt$="DSERR_INVALIDPARAM"
		Case $8878001E
			txt$="DSERR_CONTROLUNAVAIL"
		Case $88780032
			txt$="DSERR_INVALIDCALL"
		Case $88780046
			txt$="DSERR_PRIOLEVELNEEDED"
		Case $88780064
			txt$="DSERR_BADFORMAT"
		Case $88780078
			txt$="DSERR_NODRIVER"
		Case $88780082
			txt$="DSERR_ALREADYINITIALIZED"
		Case $88780096
			txt$="DSERR_BUFFERLOST"
		Case $887800A0
			txt$="DSERR_OTHERAPPHASPRIO"
		Case $887800AA
			txt$="DSERR_UNINITIALIZED"
		Case $887810B4
			txt$="DSERR_BUFFERTOOSMALL"
		Case $887810BE
			txt$="DSERR_DS8_REQUIRED"
		Case $887810C8
			txt$="DSERR_SENDLOOP"
		Case $887810D2
			txt$="DSERR_BADSENDBUFFERGUID"
		Case $887810DC
			txt$="DSERR_FXUNAVAILABLE"
		Case $88781161
			txt$="DSERR_OBJECTNOTFOUND"
		Default
			txt$="UNKNOWN!"
	End Select
	Print "DSound Message = "+Chr$(34)+txt$+Chr$(34)
End Function





Global dsoundLib=LoadLibraryA( "DSOUND" )
If Not dsoundLib Return
Global DirectSoundCreate8( guid, ppDS8:IDirectSound8 Ptr, outer )"win32"=GetProcAddress( dsoundLib,"DirectSoundCreate8" )




'------------------------------------------------------------------------------------------------------
Local Result


Graphics(640,480,0)

Local hWnd = GetActiveWindow()
Print "hWnd = "+hWnd

' test it
Global Interface:IDirectSound8
result = DirectSoundCreate8( Null, Varptr(Interface:IDirectSound8), Null )
PrintDSoundError(result)

result = Interface.SetCooperativeLevel( hWnd, DSSCL_NORMAL )
PrintDSoundError(result)



FEATURE REQUEST... It would be nice if Graphics() returned the hWnd.

The SetCooperativeLevel method is the fourth method in the virtual function table, by commenting out the two methods above it the compiler thinks it is the second and most likely invoking GetCaps instead.

skidracer I could kiss you, works perfectly now, thanks mate :)

I assumed it was referenced by name, shows what I know