Receiving notification when device registry property changes - c++

I need to receive current power state of a device. I was able to retrieve it using the code below:
ULONG ulRegDataType;
CM_POWER_DATA powerData;
ULONG ulLength;
auto ret = CM_Get_DevNode_Registry_PropertyW(devInst, CM_DRP_DEVICE_POWER_DATA, &ulRegDataType, &powerData, &ulLength, 0);
I wasn't able, however, to install notification callback with CM_Register_Notification that would notify me about the property change. I tried both CM_NOTIFY_FILTER_FLAG_ALL_INTERFACE_CLASSES and CM_NOTIFY_FILTER_FLAG_ALL_DEVICE_INSTANCES but the callback is never called when device enters D3 state.

Related

How to get a "Camera removed" event in MFCaptureEngine

Is there any possibility to get an information that a camera was removed during preview in IMFCaptureEngine?
I am using a code from this sample CaptureEngine video capture sample. There is an EventCallback connected to the MFCaptureEngine instance:
hr = m_pEngine->Initialize(m_pCallback, pAttributes, NULL, pUnk);
But no event is received in the callback function after the webcam is removed.
I tried to add an extra callback function for engine's IMFMediaSource, which should, as I was expecting, generate MEVideoCaptureDeviceRemoved event. Look at the code called after MFCaptureEngine instance is initialized:
m_pEngine->GetSource(&pCapSource);
pCapSource->GetCaptureDeviceSource(MF_CAPTURE_ENGINE_DEVICE_TYPE_VIDEO, &pMediaSource);
pMediaSource.QueryInterface(&m_pSourceEventGenerator);
hr = m_pSourceEventGenerator->BeginGetEvent(OnSourceCB, NULL);
The hr value is MF_E_MULTIPLE_SUBSCRIBERS, which gives me a sence, because there are mixed two callbacks objects (first for the MFCaptureEngine as a whole, second for IMediaSource only).
Why I don't get any information about the device was removed? How can I get this information?
PS. I know the WM_DEVICECHANGE message, but I would like to avoid this if possible to get an event from media foundation.
You expectedly hit MF_E_MULTIPLE_SUBSCRIBERS because it's capture engine who is the subscriber here. The engine is supposed to handle the event internally and forward it to the owner in the form of IMFMediaEvent of extended type MF_CAPTURE_ENGINE_ERROR, with HRESULT code indicated by IMFMediaEvent::GetStatus call of MF_E_VIDEO_RECORDING_DEVICE_INVALIDATED (0xC00D3EA2): "The video recording device is no longer present.".
You receive the event in your IMFCaptureEngineOnEventCallback implementation supplied to capture engine on initialization step.

c++ enable accessibility inspection in Google Chrome

I'm trying to access text of Google Chrome's webpage to read it and offer some actions (for example, remind). Everything works good, but I need to enable accessibility inspection programmatically. I use this code:
wchar_t className[100];
GetClassName(hwnd, className, 100) == 0 || wcscmp(className, L"Chrome_WidgetWin_1");
CComPtr<IAccessible> pAccMain;
HRESULT hr = ::AccessibleObjectFromWindow(hWndChrome, 1, IID_IAccessible, (void**)(&pAccMain));
CComPtr<IAccessible> pAccMain2;
::AccessibleObjectFromWindow(hWndChrome, OBJID_CLIENT, IID_IAccessible, (void**)(&pAccMain2));
And nothing happens until I run browser with --force-renderer-accessibility parameter or manually change accessibility settings located in chrome://accessibility.
What am i doing wrong?
Found this info: "Chrome calls NotifyWinEvent with EVENT_SYSTEM_ALERT and the custom object id of 1. If it subsequently receives a WM_GETOBJECT call for that custom object id, it assumes that assistive technology is running". Does anybody know how to implement this?
Use SetWinEventHook, e.g.
HWINEVENTHOOK hook = SetWinEventHook(EVENT_SYSTEM_ALERT, EVENT_SYSTEM_ALERT,NULL, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT)
Then in your WinEventProc, you'll be given a hWnd, idObject, and idChild when Chrome sends the EVENT_SYSTEM_ALERT.
If idObject == 1 then call AccessibleObjectFromEvent(), passing it those hWnd, idObject, and idChild arguments.
AccessibleObjectFromEvent will then send the WM_GETOBJECT. From the docs::
Applications never send this message directly. Microsoft Active Accessibility sends this message in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow.
By using AccEvent I can see that Google Chrome only appears to send the EVENT_SYSTEM_ALERT when it starts, e.g. opening a new tab doesn't trigger it, so you'd need to have done the SetWinEventHook() before Chrome is launched.

When Skype ICallChannelManagerEvents gets fired

I am working on App to App communication using skype. My Requirement is When one skype user place Call/Video Call I wanted to use application stream to send message from One App Plugged in Skype to other App plugged in Skype.
In Separate Sample App I am able to send and receive message using Application Stream from One App to Other App but I wanted to Activate Application Stream When User place call.
Skype4COM expose these three event for ICallChannelManager
ICallChannelManagerEvents::Channels
ICallChannelManagerEvents::Created
ICallChannelManagerEvents::Message
I have registered these three events
hr = m_pCallChannelMgr.CreateInstance(__uuidof(CallChannelManager));
hr = SinkSkypeCallChannelMgrEvents::DispEventAdvise(m_pCallChannelMgr);
hr = m_pCallChannelMgr->CreateApplication(L"");
VARIANT_BOOL flag = m_pCallChannelMgr->GetCreated();
while(true )
{
if ( VARIANT_TRUE == flag) break;
flag = m_pCallChannelMgr->GetCreated();
Sleep(1000);
}
hr = m_pCallChannelMgr->Connect(m_Skypeptr);
when m_pCallChannelMgr->CreateApplication(); is called it fires ICallChannelManagerEvents::Created event.
I am Not sure about,When Other when two event ICallChannelManagerEvents::Channels and ICallChannelManagerEvents::Message gets fired.
Plz help me on this.
Problem Resolved when there is already a call in process and your plugin starts to hook in to Skype ICallChannelManagerEvents gets fired.

Monitoring Screensaver activity fails on Windows 7

Good afternoon, i have a section of code i am using to monitor screen saver activity in Windows XP onwards, this currently works correctly on all Windows OS's except for Windows 7, i am aware that certain screen saver parameters to the SystemParametersInfo function are not available in Windows 7 but thought that SPI_GETSCREENSAVERRUNNING was available, the code is as follows:
BOOL bScrnSvrRunning = FALSE;
BOOL bResult = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &boolScreenSaverRunning, 0);
The function always returns true for bResult but bScrnSvrRunning is always false,
does anyone have any idea what might cause this?
If you really want to monitor the screen saver activity you can consider to use System Event Notification Service (SENS). The System Event Notification Service monitors and dispatches there, so it can notify your application about the starting (see ISensLogon::StartScreenSaver) and stopping (see ISensLogon::StopScreenSaver) of the screen saver many events. An example how to use SENS you can find here (see also here and here).
You are using the wrong parameter "slot". Look closely at the declaration of SystemParametersInfo:
BOOL WINAPI SystemParametersInfo(
__in UINT uiAction,
__in UINT uiParam,
__inout PVOID pvParam,
__in UINT fWinIni
);
And let me quote the info for SPI_GETSCREENSAVERRUNNING:
Determines whether a screen saver is currently running on the window station of the calling process. The pvParam parameter must point to a BOOL variable that receives TRUE if a screen saver is currently running, or FALSE otherwise.
pvParam is the one that recieves the info, so you must supply your bool in the pvParam parameter:
BOOL bScrnSvrRunning = FALSE;
BOOL bResult = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &boolScreenSaverRunning, 0);

Changing string after hooking WM_SETTEXT

I have setup a hook on WM_SETTEXT message using WH_CALLWNDPROC.
In hook procedure
CWPSTRUCT* info = (CWPSTRUCT*) lParam;
wchar_t *wsz = NULL;
switch(info->message)
{
case WM_SETTEXT:
wsz = (wchar_t *) info->lParam;
//info->lParam = (LPARAM) L"Hello";
//SendMessage(info->hWnd,WM_SETTEXT,0,(LPARAM)L"HEllo");
//SetWindowText(info->hWnd,L"Hello");
break;
}
Is it possible to change the string as done above in the code.
I tried by using APIs like
SendMessage(info->hWnd,WM_SETTEXT,0,(LPARAM)L"HEllo");
SetWindowText(info->hWnd,L"Hello");
But none of them working.Idea here is to hook WM_SETTEXT message and change the string before it reached destination window.
No, the WH_CALLWNDPROC doesn't allow you to modify messages, the documentation for CallWndProc directly states this.
The WH_GETMESSAGE does allow you to modify the message. See the documentation for GetMsgProc. However, this probably won't work for what you want since it only messages that are retrieved with GetMessage() or PeekMessage() and send messages call the WndProc directly rather than using the message queue.
The way to do what you want is to use the WH_CBT hook and listed for HCBT_CREATEWND events. Then subclass the window as it is created and handle the WM_SETTEXT message.