I do not think that there is a direct way to do this using the OS - this is a function that may (or may not) be present on the sound card. Some sound cards have a loopback interface - Creative calls it “What U Hear”. You simply select this as an input, not a microphone, and record it using the usual waveInOpen (), which you already know about.
If the sound card does not have this feature, I think you're out of luck, except to do something crazy, how to make your own driver. Or you can convince your users to use the cable from the speaker output to the line input :)
source share