I think the problem is the use of TGUID instead of PGUID in your structures
and functions.  The MSDN page mentions the parameter can be NULL which would
indicate a pointer.

 

Changed TGUID to PGUID and the function at least doesn't crash.  Need to
test further if it actually works with a real GUID.

 

Many thanks.

 

Ross.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Cameron Hart
Sent: Thursday, 27 May 2010 10:54 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

Try this

 

You would call it with a null GUID to retrieve the default handler.

 

Uses ActiveX;

Var WaveDeviceId : cardinal

WaveDeviceId:= DSGUIDToWaveDeviceID(nil, GUID_NULL,
DIRECTSOUNDDEVICE_DATAFLOW_RENDER);

 

 

 

//**************************************************************************
******************/

// DOWNLOAD CLOOTIE LIBRARY FROM
http://www.clootie.ru/delphi/download_dx92.html TO USE THIS  /

//**************************************************************************
******************/

unit DSGuidToWaveDevice;

 

interface

 

uses

  DirectSound, ActiveX, Windows;

 

type

  DIRECTSOUNDDEVICE_DATAFLOW = (DIRECTSOUNDDEVICE_DATAFLOW_RENDER,
DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE);

  DIRECTSOUNDDEVICE_TYPE = (DIRECTSOUNDDEVICE_TYPE_EMULATED,
DIRECTSOUNDDEVICE_TYPE_VXD, DIRECTSOUNDDEVICE_TYPE_WDM);

 

  DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA = Record

    Type_: DIRECTSOUNDDEVICE_TYPE;

    DataFlow: DIRECTSOUNDDEVICE_DATAFLOW;

    DeviceId: TGUID;

    Description: PChar;

    Module: PChar;

    Interface_: PChar;

    WaveDeviceId: ULONG;

  end;

  PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA =
^DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA;

 

  Function DSGUIDToWaveDeviceID(aDSIntf : IUnknown; aGUID: TGUID; aDataFlow
: DIRECTSOUNDDEVICE_DATAFLOW): Cardinal;

 

  //this doesnt work however you can get a pointer to this function yourself
as per below

  //function DLLGetClassObject(const CLSID, IID: TGUID; var Obj): HResult;
stdcall; external DirectSoundDLL name 'DLLGetClassObject';

 

const

  DSPROPSETID_DirectSoundDevice: TGUID =
'{84624F82-25EC-11d1-A4D8-00C04FC28ACA}';

  CLSID_DirectSoundPrivate: TGUID =
'{11AB3EC0-25EC-11d1-A4D8-00C04FC28ACA}';

  EmptyDescription: DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA =
(Type_: DIRECTSOUNDDEVICE_TYPE_EMULATED;

 
DataFlow: DIRECTSOUNDDEVICE_DATAFLOW_RENDER;

 
DeviceId: '{00000000-0000-0000-0000-000000000000}';

 
Description: '';

 
Module: '';

 
Interface_: '';

 
WaveDeviceId: 0);

 

 

implementation

 

Function DSGUIDToWaveDeviceID(aDSIntf : IUnknown; aGUID: TGUID; aDataFlow :
DIRECTSOUNDDEVICE_DATAFLOW): Cardinal;

var PropSet : IKsPropertySet;

  DeviceDescription : DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA;

  PDeviceDescription : PDSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA;

  lReturned : ULONG;

  DSoundDLL : HMODULE;

  lDllGetClassObject : TDLLGetClassObject;

  Factory: IClassFactory;

begin

  //aDSIntf is an interface you already have of i.e. IDirectSound or
IDirectSoudnBuffer etc

  if Assigned(aDSIntf) then

    aDSIntf.QueryInterface(IID_IKsPropertySet, PropSet)

  else begin

    DSoundDLL := LoadLibrary(DirectSoundDll);   //load the library

    lDllGetClassObject := GetProcAddress(DSoundDLL,'DllGetClassObject');
//get reference to the function

    lDllGetClassObject(CLSID_DirectSoundPrivate, IClassFactory, Factory);
//use the function to create class factory

    Factory.CreateInstance(nil, IID_IKsPropertySet, PropSet);  //use the
factory to create IKsPropertySet interface

  end;

 

  DeviceDescription := EmptyDescription;

  DeviceDescription.DataFlow := aDataFlow;

  DeviceDescription.DeviceId := aGUID;

 

  PropSet.Get(DSPROPSETID_DirectSoundDevice,1,

            nil,

            0,

            @DeviceDescription,

            sizeof(DeviceDescription),

            lReturned);

 

  Result := DeviceDescription.WaveDeviceId;

 

end;

 

 

end.

 

 

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Thursday, 27 May 2010 10:47 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

Instead of the QueryInterface, I tried this.

 

const

  CLSID_DirectSoundPrivate: TGUID =
'{11AB3EC0-25EC-11d1-A4D8-00C04FC28ACA}';

 

CoCreateInstance(CLSID_DirectSoundPrivate,nil,CLSCTX_INPROC_SERVER,IID_IKsPr
opertySet,PropSet);

 

But I get "the specified class is not registered in the registration
database".

 

Interfaces are like a foreign language to me.  It looks way more complicated
than it should be.

 

Ross.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Cameron Hart
Sent: Thursday, 27 May 2010 12:25 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

The interface you want is actually "IKsPropertySet".  Clootie defines this
for you just doesn't take you as far as using it.

 

Make sure you download the library from
http://www.clootie.ru/delphi/download_dx92.html and not the DX10 library.

 

The unit below is what you need.  i just knocked this together now so you
will need to test it.  Shouldn't be far off. You might need to check my
conversion from the headers.

 

 

//**************************************************************************
******************/

// DOWNLOAD CLOOTIE LIBRARY FROM
http://www.clootie.ru/delphi/download_dx92.html TO USE THIS  /

//**************************************************************************
******************/

unit DSGuidToWaveDevice;

 

interface

 

uses

  DirectSound, ActiveX, Windows;

 

type

  DIRECTSOUNDDEVICE_DATAFLOW = (DIRECTSOUNDDEVICE_DATAFLOW_RENDER,
DIRECTSOUNDDEVICE_DATAFLOW_CAPTURE);

  DIRECTSOUNDDEVICE_TYPE = (DIRECTSOUNDDEVICE_TYPE_EMULATED,
DIRECTSOUNDDEVICE_TYPE_VXD, DIRECTSOUNDDEVICE_TYPE_WDM);

 

  DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA = Record

    Type_: DIRECTSOUNDDEVICE_TYPE;

    DataFlow: DIRECTSOUNDDEVICE_DATAFLOW;

    DeviceId: TGUID;

    Description: PChar;

    Module: PChar;

    Interface_: PChar;

    WaveDeviceId: ULONG;

  end;

 

  Function DSGUIDToWaveDeviceID(aDSIntf : IUnknown; aGUID: TGUID; aDataFlow
: DIRECTSOUNDDEVICE_DATAFLOW): Cardinal;

 

const

  DSPROPSETID_DirectSoundDevice: TGUID =
'{84624F82-25EC-11d1-A4D8-00C04FC28ACA}';

 

implementation

 

Function DSGUIDToWaveDeviceID(aDSIntf : IUnknown; aDataFlow :
DIRECTSOUNDDEVICE_DATAFLOW): Cardinal;

var PropSet : IKsPropertySet;

  DeviceDescription : DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION_A_DATA;

  lReturned : ULONG;

 

begin

  //aDSIntf is an interface you already have of i.e. IDirectSound or
IDirectSoudnBuffer etc

  //aDSIntf.QueryInterface(IID_IKsPropertySet, PropSet);

 

  DeviceDescription.DataFlow := aDataFlow;

  DeviceDescription.DeviceId := aGUID;

 

  PropSet.Get(DSPROPSETID_DirectSoundDevice,1,

            nil,

            0,

            @DeviceDescription,

            sizeof(DeviceDescription),

            lReturned);

 

  Result := DeviceDescription.WaveDeviceId;

 

end;

 

 

end.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Wednesday, 26 May 2010 10:00 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

If you are referring to the Clootie page, I just downloaded the headers from
there and it's the same file as I've got.

 

I'm pretty sure no one has done this yet for Delphi, or at least published
it.  I spend 2 or 3 hours searching the net yesterday.  I only found one
instance of some C++ code.

 

If you google "delphi DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION" or "delphi
CLSID_DirectSoundPrivate", you get only 3 or 4 pages which don't have
anything to do with Delphi.  It's not a commonly used interface.

 

Ross.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Cameron Hart
Sent: Wednesday, 26 May 2010 8:41 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

I have googled it further for you again with the term "directx 9 delphi
pas".  lots of libraries returned that look promising.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Wednesday, 26 May 2010 6:53 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

I've already got a file called DirectSound.pas which is similar to those on
the internet but none of them have this particular interface which I believe
was introduced in DirectX 9.

 

Cheers,

Ross.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Cameron Hart
Sent: Wednesday, 26 May 2010 6:29 p.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] Anyone with 5 minutes spare time?

 

Just to clarify, directsound.pas (or similar units floating on the net)
should give you interfaces to the Dsound.dll.  this is what you need to do
things like below.

 

From: delphi-boun...@delphi.org.nz [mailto:delphi-boun...@delphi.org.nz] On
Behalf Of Ross Levis
Sent: Wednesday, 26 May 2010 5:40 p.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: [DUG] Anyone with 5 minutes spare time?

 

Hi everyone.

 

I've never used interfaces in Windows before and I've got no idea how to do
this, so I'm wondering if someone would like to whip up a Delphi function
for me.  I don't think it would take more than 5 or 10 minutes.  I searched
the internet extensively and C++ code exists but nothing for Delphi.

 

http://msdn.microsoft.com/en-us/library/ee418863(v=VS.85).aspx

 

I need to access the DSPROPERTY_DIRECTSOUNDDEVICE_DESCRIPTION properties on
the above page and specifically return the WaveDeviceID from a given GUID.
I have the GUID and need the WaveDeviceID.  ie.

 

Function DSGUIDToWaveDeviceID(GUID: TGUID; DataFlow: ??): Cardinal;

 

Very much appreciated J

 

Ross.

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-requ...@delphi.org.nz with Subject: 
unsubscribe

Reply via email to