I've tried to find a way to detect when a new device (like a USB) is inserted into a computer, but everything I've seen required MFC, which I don't have. Is there a way to do this without MFC? If not, I understand, but I haven't seen anything of the like in my Google searches.
Thanks,
C++ by itself does not have any platform-dependent hardware-level functionality. You will need to use some API, like Win32 or MFC or .NET on Windows.
You can do this using libusb and there's a port of libusb for win32, so you might have some luck using that instead of MFC, with the added bonus of being more portable.
Handle the WM_DEVICECHANGE message.
See http://msdn.microsoft.com/en-us/library/aa363480(v=vs.85).aspx
EDIT: Of course, this is Windows only, which the OP didn't specify. There's no way to do this without external libraries or platform specific APIs.
Related
I am wondering how can I ask Windows and retrieve a list over current input devices?
Language is C++.
The goal is to select from the list in a program I am making.
Tried searching a bit, but found nothing..
Please help :)
Thank you.
For the sake of future reference, it might be worth mentioning the RtAudio library, which is also written in C++ and is multiplatform on Windows, OS-X and Linux.
On Windows you can compile it either using the ASIO SDK (in case your devices have an ASIO driver), DirectSound (part of DirectX, old and deprecated, but still working), or WASAPI (introduced in Windows Vista).
With RtAudio you can manage devices very easily with class method calls such as:
RtAudio::startStream();
RtAudio::stopStream();
RtAudio::getDeviceCount();
RtAudio::getDefaultInputDevice();
RtAudio::getDeviceInfo(uint deviceID);
You can also manage output devices in the same fashion.
This can be done through the WaveIn Windows API. Since there is already a post with code to enumarate and retrieve the names of input devices here I won't make a new one.
I am looking to communicate via RFCOMM to another Bluetooth device. I want to use C++ (VS2008) for the application. I already know of the 32feet library, but was unsure if it would work for C++. Does anyone know of a good starting point for this kind of project? Or possibly 32feet samples written in C++? I want a simple, easy to use API for Bluetooth using C++.
This question is rather old, I know.
Just wanted to update, that Qt Framework has now Qt Bluetooth for C++ that looks very promising -- http://doc.qt.io/qt-5/qtbluetooth-module.html
You can do Bluetooth programming using BT sockets into the OS Bluetooth stack. This page discusses socket usage:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa362928(v=vs.85).aspx
This page has links to download Bluetooth SDK from Microsoft:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363058(v=vs.85).aspx
Building apps using the Microsoft stack works fairly well (XP and Vista work great, trying to run the same apps under Windows 7-64bit does not work so well...)
The real advantage to 32feet.net is that the Bluetooth support on Windows is heavily Balkanized - you never know on a given machine whether it is using the Microsoft, Broadcom, Toshiba, BlueSolei, or some other stack. While these are all mostly compatible over-the-air, the APIs are completely different for each. Building with 32feet.net lets your application run on a larger subset of machines... That said, I have not tried building it into a C++ application - sorry.
I'm currently working on a cross-platform application (Win/OSX/iOS) which has a C++ (with Boost) back end. On iOS and OSX I'm using the Cocoa Net Service Browser Delegate functions to discover an embedded device via mDNS, then pass the information to the back end to create the objects it needs to communicate with it.
I wanted to take a similar approach with my Windows MFC front end and I found this article which seemed to do exactly what I want. However, it seems that using the Bonjour SDK has some really nasty side effects - forcing you to static link to MFC and in my case the only way I can get it to link properly is to not use debug DLLs at all, which is not ideal.
So, the Bonjour SDK isn't really any good for me because it imposes too many restrictions on my project. With Cocoa I'm actually using very little of the functionality - just didFindService and netServiceDidResolveAddress really. All I want to do is find the devices of a given type and get their IP addresses.
Can anyone suggest another way around this that will work with an MFC front end on Windows?
From what I have been able to gather from researching this topic just goto http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-333.10/ and grab the source. There is a VC project file which will let you build the dll how you want.
Specifically I am talking about using AIM and sending instant messages to an existing AIM screename. How would I accomplish this? I am trying to do it the simplest way possible -efficiency is not that important.
I thought maybe all I would have to do is open a socket connections some how but I am probably wrong.
I would use libpurple. It's a multi-platform C library that supports many IM services, including AIM.
Check out the source for GAIM/Pidgin, which runs on a variety of platforms including windows. It uses a modified version of libfaim.
I'm writing a windowed program in C++, but I would like to have the option to pop up a console to output to from inside the program (such as various things that go on behind the scenes of my program, to see that everything is acting correctly). Is there an easy way to do this?
EDIT:
In this particular case I'm using sfml on windows, but for the purposes of this question it can be any API or platform (and platform independent solutions are best)
If you are talking about MS Windows, which your question does not make clear, you can use the AllocConsole API to create a console. for your app.
Edit: You say that it could be any platform, but this is not so as many platforms have no concept of a console. For this reason, a cross-platform solution is not possible.
There are Windows API functions to deal with console management. This might be a good starting point.
Its easy to just open a console with system("cmd.exe"); But the communication part is not so easy. My intuitive feeling tells me that there exists a third party that satisfied your need. Might be worth looking at win32api or AllocConsole API (if you are using .NET) before experimenting with 3rd party libs.