I've been playing around with Vista's CoreAudio stuff, in particular IAudionSessionEvents, with the goal of monitoring the default audio session for changes to volume caused by loaded code.
However, it looks like as soon as you install an IAudioSessionEvents listener SndVol lists the program with all associated volume controls. As a good portion of the time no code has been loaded that will actually play anything, this is less than ideal.
Basically, is there some way to monitor the default audio session without causing SndVol to list it?
A solution for Vista is preferred, but something depending on new apis provided in Windows 7 is better than nothing.
Larry Osterman pointed out the ISessionManager2 and IAudioSessionNotification interfaces added in Windows 7. However, I never receive notice of new session. Is anyone aware of gotchas or problems with this API under Windows 7 build 7000?
Code registering IAudioSessionNotifications, omitting lots of error checking code*:
BOOL success = false;
HRESULT hr;
IMMDeviceEnumerator *pEnumerator = NULL;
IMMDevice *pDevice = NULL;
IAudioSessionManager2* pManager = NULL;
IClassFactory* pFactory = NULL;
hr = CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pManager);
listener = NULL;
hr = CoGetClassObject(CLSID_CustomFactory, CLSCTX_ALL, NULL, __uuidof(IClassFactory), (void**)&pFactory);
hr = pFactory->CreateInstance(NULL, __uuidof(IAudioSessionNotification), (void**)&listener);
hr = pManager->RegisterSessionNotification(listener);
*While not the purpose of this question, constructive critic of my COM code is welcome.
If you want to monitor the audio session stuff, you should use the IAudioSessionManager interface to retrieve your IAudioSessionControl object. A session only shows up in SndVol when it transitions from the inactive to the active state - that happens when when someone calls IAudioClient::Start() - as long as you don't call IAudioClient::Start you shouldn't get a session slider.
In Windows 7, there are a new set of APIs (IAudioSessionManager2) that allow you to listen for session creation and destruction.
Also for Windows 7, there is the AUDCLNT_SESSIONFLAGS_HIDE flag (the documentation for this hasn't been updated yet but it's in the headers)
Related
I implemented two different solution to discover service on my BLE device. One use a handler then return what .discoverService have found, the other one is really similar but give the size of the service discovered list that is always 0. I tried it with my realme buds 2 as test and some other device publically visible. The result is always 0. What can the problem be?
Handler(Looper.getMainLooper()).post {
var temp = bluetoothGatt?.discoverServices()
addGlog("discordservice() returned ${temp.toString()}")
}
addGlog("handler discover service reached an end")
val gattServices: List<BluetoothGattService> = gatt.getServices()
addGlog("Services count: " + gattServices.size)
for (gattService in gattServices) {
val serviceUUID = gattService.uuid.toString()
addGlog("Service uuid $serviceUUID")
}
edit: AddGlog is a simple log function to print results
answer: The code is not wrong but it take some time to discover those services so i put this code in a button. In this way there is 3-4 second of time between connecting with the device and make a discoveryservice operation. So a button make the conneting operations and another one the service discovery operations. I am sorry if my answer is pretty lame but I am still a noob on this topic
I am using Microsoft.ML.OnnxRuntime.DirectML nuget package for image classification like this:
var options = new SessionOptions();
options.AppendExecutionProvider_DML( 1 ); // deviceId goes here
var session = new InferenceSession( _modelPath, options );
And I have one big problem: in IIS integrated video card has deviceId 0 and discrete has deviceId 1. But when my app is running under Kestrel, integrated has deviceId 1 and discrete has deviceId 0, and this is opposite to what Task Manager shows in "GPU engine" column when scoring is in progress.
And right now my integrated card can not be used with this package as it throws this exception (and this is pointless anyway):
Exception Info: Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:RuntimeException] D:\5\s\onnxruntime\core\providers\dml\dml_provider_factory.cc(110)\onnxruntime.DLL!00007FF8C074118F: (caller: 00007FF8C07411C7) Exception(941) tid(35b8) 887A0020 An internal issue prevented the driver from carrying out the specified operation. The driver's state is probably suspect, and the application should not continue.
So I need a reliable way to detect deviceId for discrete video card.
Ok, I have found a workaround for now.
I can check witch video card is integrated/discrete using this method
How get GPU information in C#?
and then I can use Vortice.DXGI nuget package to find out which deviceId each video card has - it is basically index
DXGI.CreateDXGIFactory1( out IDXGIFactory1 factory );
factory.EnumAdapters1( 0, out var adapter0 );
factory.EnumAdapters1( 1, out var adapter1 );
factory.EnumAdapters1( 2, out var adapter2 );
There have been a few posts on this issue without any solutions announced.
Wanting to access internal movesense sensor data (ECG, Acc…) but without using the Android or iOS platforms ( as suggested by a movesense presentation https://www.movesense.com/wp-content/uploads/2018/11/2018-11-06-Using-Movesense-CustomGATTService.pdf ), I have failed to do so for at least 1 week.
I can successfully create my own GATT characteristics and subscribe to them from outside the movesense device. This is easily done by augmenting the samples/custom_gattsvc_app with a few lines :
Definition :
const uint16_t myCharUUID16 = 0x2A58; // this new characteristic will appear in the service as the third one in the sample
In CustomGATTSvcClient::configGattSvc() :
WB_RES::GattProperty myCharProp = WB_RES::GattProperty::INDICATE;
myChar.props = wb::MakeArray<WB_RES::GattProperty>( &myCharProp, 1);
myChar.uuid = wb::MakeArray<uint8_t>( reinterpret_cast<const uint8_t*>(&myCharUUID16), 2);
customGattSvc.chars = wb::MakeArray<WB_RES::GattChar>(characteristics, 3); // 3 here since there are 3 characteristics now
Accessing
You can now see and subscribe with a BTLE client (bluetility…) to the new service even if it does not do anything for now.
The problems start here for me :
In CustomGATTSvcClient::onGetResult() I try to force a subscription to ECG or Acc since onGetResult() is called by CustomGATTSvcClient::onPostResult() once all the BT services are created :
int32_t sampleRate = 10;
asyncSubscribe(WB_RES::LOCAL::MEAS_ACC_SAMPLERATE(),AsyncRequestOptions::Empty, sampleRate);
I do not implement onSubscribeResult()
In onNotify() you should be able to intercept the call from the whiteboard with the new data every 1/10 second by
switch (resourceId.getConstId()) {
case WB_RES::LOCAL::MEAS_ACC_SAMPLERATE::ID:
{
// To see a blinking LED on each new Acc data
asyncPut(WB_RES::LOCAL::COMPONENT_LED(),AsyncRequestOptions::Empty, myFlippingBool);
myFlippingBool = ! myFlippingBool;
}
What I have observed :
A. When I asyncSubscribe() the ECG or Acc, the sample’s WB_RES::LOCAL::MEAS_TEMP::LID is no longer called and no updates are dispatched to a BT client even after a successful subscription to the 0x2A1C characteristic. This means that all Notifications are disabled by a resource conflict ?
B. When subscribing ( as before ) or even by :
wb::Result result = getResource("Meas/Acc/10", mMyAccResourceId);
result = asyncSubscribe(mMyAccResourceId);
The onNotify() method is never called as the LED does not blink ( even directly after onNotify() implementation without the switch / case )
There is a lack of documentation on CustomGatt and it seems it blocks many people in integrating the sensor on other platforms ( Raspberry Pi or generic processors running a BT stack ).
I have tried before to access the movesense platform with direct AT commands from a rudimentary microcontroller and a BT module without success (Movesense direct access to GATT endpoints ), so now I’m turning to a Raspberry solution + Qt without success.
Thank you for any example or answers to this question !
At least 10 Hz is not supported. What happens with Meas\Acc\13 ?
In MT4, there exists a stage/state: when we switch from AccountA to AccountB, when Connection is established and init() and start() are triggered by MT4; but before the "blinnnggg" (sound) when all the historical/outstanding trades are loaded from Server.
Switch Account>Establish Connection>Trigger Init()/Start() events>Start Downloading of Outstanding/Historical trades>Completed Downloading (issue "bliinng" sound).
I need to know (in MQL4) that all the trades are completed downloaded from the tradeServer --to know that the account is truly empty -vs- still downloading history from tradeServer.
Any pointer will be appreciated. I've explored IsTradeAllowed() IsContextBusy() and IsConnected(). All these are in "normal" state and the init() and start() events are all fired ok. But I cannot figure out if the history/outstanding trade lists has completed downloading.
UPDATE: The final workaround I finally implemented was to use the OrdersHistoryTotal(). Apparently this number will be ZERO (0) during downloading of order history. And it will NEVER be zero (due to initial deposit). So, I ended-up using this as a "flag".
Observation
As the problem was posted, there seems no such "integrated" method for MT4-Terminal.
IsTradeAllowed() reflects an administrative state of the account/access to the execution of the Trading Services { IsTradeAllowed | !IsTradeAllowed }
IsConnected() reflects a technical state of the visibility / login credentials / connection used upon an attempt to setup/maintain an online connection between a localhost <-> Server { IsConnected() | !IsConnected() }
init() {...} is a one-stop setup facility, that is/was being called once an MT4-programme { ExpertAdvisor | Script | TechnicalIndicator } was launched on a localhost machine. This facility is strongly advised to be non-blocking and non-re-entrant. A change from the user account_A to another user account_B is typically ( via an MT4-configuration options ) a reason to stop an execution of a previously loaded MQL4-code ( be it an EA / a Script / a Technical Indicator ) )
start() {...} is an event-handler facility, that endlessly waits, for a next occurrence of an FX-Market Event appearance ( being propagated down the line by the Broker MT4-Server automation ) that is being announced via an established connection downwards, to the MT4-Terminal process, being run on a localhost machine.
A Workaround Solution
As understood, the problem may be detected and handled indirectly.
While the MT4 platform seems to have no direct method to distinguish between the complete / in-complete refresh of the list of { current | historical } trades, let me propose a method of an indirect detection thereof.
Try to launch a "signal"-trade ( a pending order, placed geometrically well far away, in the PriceDOMAIN, from the current Ask/Bid-levels ).
Once this trade would be end-to-end registered ( Server-side acknowledged ), the local-side would have confirmed the valid state of the db.POOL
Making this a request/response pattern between localhost/MT4-Server processes, the localhost int init(){...} / int start(){...} functionality may thus reflect a moment, when the both sides have synchronised state of the records in db.POOL
My application deletes virtual printer when user uninstalls the application.
Application's installation and Uninstallation can be done using user interaction(wizard) or by setting group policy in Windows server 2003(domain admin sets the policy in server and the domain user in client PC need to update the group policy and restart the Client PC for installation or uninstallation of the application).
The follwing code in the application deletes printer and printer driver when uninstalling the application.
void CPrinterDriver::DeletePrinterIfExists()
{
// Delete old printer driver if existing
ControlSpoolService(TRUE);
HANDLE hPrinter = NULL;
PRINTER_DEFAULTS pDefaults = { NULL, NULL, PRINTER_ALL_ACCESS };
// Ignore error codes
OpenPrinter(m_driverInfo.pName, &hPrinter, &pDefaults);
if (hPrinter)
{
// deleting jobs
SetPrinter(hPrinter, 0, NULL, PRINTER_CONTROL_PURGE);
// Delete printer
DeletePrinter(hPrinter);
// Get printer driver name and delete it
DWORD dwNeeded = 0;
GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded);
if (dwNeeded)
{
PRINTER_INFO_2 *pi2 = (PRINTER_INFO_2 *)GlobalAlloc(GPTR, sizeof(PRINTER_INFO_2)*dwNeeded);
if (pi2)
{
GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);
DeletePrinterDriver(NULL, NULL, pi2->pDriverName);
GlobalFree(pi2);
}
}
ClosePrinter(hPrinter);
}
}
The above code works well in Windows 7 in both cases(user interactive installation and using group policy) of uninstallation. In Windows 8, it works well using user interactive installation and uninstallation.
But in Windows 8 the above OpenPrinter() is returing ERROR_INVALID_PRINTER_NAME.
We found that the OpenPrinter() is called using the "SYSTEM" account.
Kindly help.
We found that during system startup, group policy is trying to uninstall the printer before the available printers list in the PC is populated (list is populated under the below registry key.If the list is not populated the below key does not exists).
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers"
Hence we added delay of 2 minutes(not less than 2 mins) before calling openPrinter().
After the delay the registry key exists and the OpenPrinter() succeeded.
Thus we are able to uninstall the printer.
Note: Microsoft claims that Windows 8 boot time is reduced to 7 secs for certain supported hardware. But inserting delay of 2 mins degrades the boot performance of the Windows 8 PC.
For more details regarding the improvement in the boot time of Windwos 8 OS please refer the below link.
http://blogs.msdn.com/b/b8/archive/2012/05/22/designing-for-pcs-that-boot-faster-than-ever-before.aspx
Hence delay of 2 mins can be terated as a workaround.
Need to check the behaviour in the Windows 8 OS release after 10/26.
If you suffer from the issue where:
the registry key for the shared (network) printer is missing and
the API gives you the invalid printer name error
Then you can try opening the printer by its full UNC path.
So when opening MYPRINTER does not work, then open it as \\MYSERVER\MYPRINTER .
Of course this still assumes that you can already print to this printer normally from other applications!