I'm looking for a way to turn on my computer's Bluetooth using the Windows API only. I didn't see any function in BluetoothApis.h for this. If you know any way (maybe using the Device API), I would love to hear it!
This is the setting I want to turn on using the Windows API:
I don't know about Win32 API, but it can be done easily via Windows Runtime API Windows.Devices.Radios. The RadioState enum can be set to On, Off or Disabled.
A UWP example is here.
For Win32 apps it is still possible to access the Windows Runtime API, for example by compiling with VC++ /ZM flag ("Consume Windows Runtime Extension") and invoking Windows::Foundation::Initialize(); on startup, as explained in the Microsoft's blog: How to access the Windows 10 APIs from C++.
Related
I Want to know if Windows CE 7.0 has same API and functionality with normal Windows system programming.
For example, i have to deal with serial(RS-232), TCP/IP, select() and so on in Windows CE 7.0.
Can i use all of API same as normal Windows?
Or there are some Difference between them ?
The API are similar, but you should expect some differences.
For example serial port drivers may not support asynchronous read/writes. This is supported in the OS (since ver 7.0), but I have seen no drivers actually using it.
Also socket API is similar but, as you know, evil hides in details.
As a general rule you can't take for granted that software running on Windows desktop (or "normal" if you prefer :)) will just need a rebuild to run on CE.
It will need at least a rebuild (and sometimes this may be clumsy if you are using different releases of Visual Studio).
We wrote a COM in-proc Server(dll)(say x.dll) which is dynamically linking to a library(say y.dll) which is using win32 API's. We have observed a different behavior of the same win32 API when launched from windows8 Desktop Apps and Metro Apps.
When the COM in-proc Server dll(x.dll) is loaded from desktop Apps, all the win32 API in library(y.dll) are working fine.But when x.dll in launched from metroApps all the win32 API in y.dll are failing.
Is this the default behaviour for Windows8 win32 API ? It would be good if some one can provide me any documentation related to using win32 API in dll's which can be launched from both desktop and MetroApps.
Thank You
Only a subset of the Windows API is available to a Windows Store app. The MSDN documentation for each API function specifies whether the function may be called from a Desktop app or from a Windows Store app. For example, the following appears at the bottom of the documentation for GetProcAddress:
Minimum supported client Windows XP [desktop apps | Windows Store apps]
This function may be called from both Desktop apps and Windows Store apps. If a function does not say that it is supported in a Windows Store app, it may not be called from a Windows Store app. For example, LoadLibrary does not say that it is callable from a Windows Store app, so it cannot be called. (Note that while there are ways to call unsupported functions, doing so necessarily yields undefined behavior.)
Also note that Windows Store apps run with low privileges and have restricted access to the system.
I have a Windows message loop. I need to detect when the screen powers back up. Is there a windows message?
detect power state change contains the C# way, I need the C++ way, using win32 API.
If there isn't a Windows message, how do I poll for screen monitor power state?
There is a Windows message WM_POWERBROADCAST. There Windows API has a lot of support for power management. See the section on Windows Power Management at MSDN for the details.
For newer windows versions (starting with windows 8) you should use GUID_CONSOLE_DISPLAY_STATE instead of GUID_MONITOR_POWER_ON
I am looking for a programmically API on how to restart any device that allows enable/disable in the device manager,
such as Audio devices and Network adapter
You will have to use SetupApi / ConfigManager API. But be aware that under x64 you app. must be also x64 to enable/disable device (so you cannot do it in Delphi directly right now - first I thought that it's a problem with file/registry redirection for x86-app under x64, but it didn't help). Device enumeration works fine. There was something about it in one article on MSDN but I cannot find it right now. I've made FP/Lazarus x64 application for enable/disable devices under x64 OS.
You can download WDK and look for source code of DevCon (C:\WinDDK\7600.16385.1\src\setup\devcon). In cmds.cpp there is function ControlCallback which enables/disables device using SetupApi). But first you need to enumerate device classes (by GUID or ClassName), and then enumerate device instances or open device by DeviceInstanceId string. It's in C but it should be easy to learn how to use that API.
Not sure what you are doing, but maybe it would be easier to use that devcon.exe (don't know if license permits it) and enable/disable devices by it?
I have no experience with it but I think you can use the DeviceIoControl API.
Is there any way to programmatically disable a device? (preferably in .net, win32, or batch).
Most hits on google suggest using devcon but it does not seem to be working on Windows Vista/7 64bit.
How do I disable a system device? has a solution using SetupDiSetClassInstallParams but it also doesn't work for Vista64.
The 32-bit version of devcon doesn't completely work in WoW64 emulation; I've seen it fail to disable devices as well. The Windows Driver Kit includes a 64-bit version of devcon, which works. It also includes the source code to devcon, so you can see that devcon is just a wrapper for the Setup API.
When you tried calling into the Setup API directly, was it from a 32-bit or 64-bit process? Based on experiences using devcon, I suspect that you need to call into the Setup API from a 64-bit process.