There is a sample called
AMCap
in the
DirectShow
samples of the Windows SDK that teaches you how it's done.
Download the Windows SDK here -
Windows SDK[
^]
AMCap is available in the following path -
[SDK Install Directory]\ Samples\ Multimedia\ DirectShow\ Capture\ AmCap