const
IID_IMMDevice : TGUID = '{D666063F-1587-4E43-81F1-B948E807363F}';
IID_IMMDeviceCollection : TGUID = '{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}';
type
IMMDevice = interface(IUnknown)
['{D666063F-1587-4E43-81F1-B948E807363F}'] //[IID_IMMDevice]
function Activate(const refId: TGUID; dwClsCtx: DWORD; pActivationParams: PInteger; out pEndpointVolume: IAudioEndpointVolume): HRESULT; stdCall;
function OpenPropertyStore(stgmAccess: DWORD; out ppProperties: IPropertyStore): HRESULT; stdcall;
function GetId(out ppstrId: PLPWSTR): HRESULT; stdcall;
function GetState(out State: Integer): HRESULT; stdcall;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MMDeviceCollection: IMMDeviceCollection;
MMDeviceEnumerator: IMMDeviceEnumerator;
hr,hr1,hr2,hr3: HResult;
count : UINT;
i:UINT;
devicename:string;
myDevice:IMMDevice;
ident:plpwstr;
ident2:PWideString;
identUTF8:UTF8String;
identstr:ansistring;
Status,laenge:integer;
test:boolean;
begin
hr := CoCreateInstance(CLSID_MMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, MMDeviceEnumerator);
hr := MMDeviceEnumerator.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, MMDeviceCollection);
ShowMessage(SysErrorMessage(hr));
hr := MMDeviceCollection.GetCount(count);
form1.caption:=inttostr(count);
if count=0
then Form1.ListBox1.Items.add('keine eRender-Devices gefunden')
else
for i:=0 to count-1 do
begin
hr:=MMDeviceCollection.Item(i,myDevice);
hr1:=mydevice.GetState(Status);
hr2:=mydevice.GetId(ident);
hr3:=mydevice.GetId(@ident2); //Error: Can't assign values to an address
hr3:=mydevice.GetId(ident2^); //Warning: Local variable "ident2" does not seem to be initialized
sowie
Error: Call by var for arg no. 1 has to match exactly: Got "WideString" expected "PLPWStr"
laenge:=length(ident^^);
identutf8:=ident^^;
//test:=LPWSTR2String(identstr, ident^);
Form1.ListBox1.Items.add(inttostr(i)+' 1 ident: '+(ident^^)+' |2: '+widestring(ident^^)+' |3: '+leftstr(widechartostring(ident^),6)+' |4: '+identutf8+' |5: '+utf8toansi(ident^^)+' |6: '+utf8toansi(identutf8)+' | Länge: '+inttostr(laenge)+' | Status: '+inttostr(Status));//identstr+
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
MMDeviceCollection: IMMDeviceCollection;
MMDeviceEnumerator: IMMDeviceEnumerator;
hr: HRESULT;
count : UINT;
begin
hr := CoCreateInstance(CLSID_MMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, MMDeviceEnumerator);
if hr <> ERROR_SUCCESS then ShowMessage(SysErrorMessage(hr));
MMDeviceCollection := nil; // wegen dem OUT-Parameter *1
hr := MMDeviceEnumerator.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, MMDeviceCollection);
if hr <> ERROR_SUCCESS then ShowMessage(SysErrorMessage(hr));
hr := MMDeviceCollection.GetCount(count);
if hr <> ERROR_SUCCESS then ShowMessage(SysErrorMessage(hr));
end;