Forum > Windows

Usage of IMMNotificationClient to register endpoint notifications

(1/1)

Nevada Smith:
I am trying to use Windows Core API to register for notifications on audio device changes.

I am able to create a IMMDeviceEnumerator.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---DeviceEnum := CreateComObject(CLASS_IMMDeviceEnumerator) as IMMDeviceEnumerator;
As the next step, I need to use RegisterEndpointNotificationCallback to register for notifications. I am assuming I have to do something like, but I might be wrong.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---OleCheck(DeviceEnum.RegisterEndpointNotificationCallback(IMMNotificationClient(@NotificationClient)));
However, I do not know how to instantiate IMMNotificationClient.
1. If I have to use CreateComObject , I do not know the CLSID. I have gone through header files in Mingw, but I could not find the CLSID.
2. In certain C projects, they mock a C++ (COM) object starting with a struct and then by adding appropriate methods.

Please advise...

Nevada Smith:
This was sort of a stupid question. It was as simple as :


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TDeviceListener = class(TObject, IMMNotificationClient)
You have to implement the virtual methods from IUnknown from which IMMNotificationClient is derived.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TDeviceListener.QueryInterface(constref  iid: TGuid; out obj): HRESULT;  stdcall;begin     // Returning S_OK blinging is not entirely correct, but sort of does the job for proof-of-concept     Result := S_OK;end; function TDeviceListener._AddRef(): HRESULT; stdcall;begin  Inc(FRefCount);  Result:=FRefCount;end; function TDeviceListener._Release(): HRESULT; stdcall;begin  Dec(FRefCount);  Result:=FRefCount;end;                                                                            
And then use it  :D


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---OleCheck(DeviceEnum.RegisterEndpointNotificationCallback(Self));

trev:
Thanks for bothering return to let us know how you solved the issue. It may well help another user in the future.

PascalDragon:

--- Quote from: Nevada Smith on May 19, 2022, 07:52:33 pm ---This was sort of a stupid question. It was as simple as :


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TDeviceListener = class(TObject, IMMNotificationClient)
--- End quote ---

Best inherit from TInterfacedObject instead of TObject as that already provides suitable implementations for QueryInterface, _AddRef and _Release.

Navigation

[0] Message Index

Go to full version