Okay, I'll start off by saying that I'm not too experienced in using audio-related C/C++ libraries, so unless somebody else responds to your post with better information, my advice would be to do searches like: "C++ duration of mp3 file", "C++ duration of wav file" and you'll find results and suggested libraries/techniques to use.
ffmpeg is built on a set of libraries that you could call instead of spinning up a new process. If you want to use ffmpeg as a library, apparently you need to link to against libavcodec
(and maybe a few others?).
In addition to the above link, I would also check out: https://stackoverflow.com/questions/2641460/ffmpeg-c-api-documentation-tutorial
Explore both those links, and I think you'll find documentation/tutorials on how to actually use the functionality of ffmpeg directly as a library.
I also found this link: https://stackoverflow.com/questions/6451814/how-to-use-libavcodec-ffmpeg-to-find-duration-of-video-file
That being said, even if you do eventually figure out how to get the above to work, I feel like it is using a sledgehammer on a fly, because ffmpeg/libav can do an enormous amount of multimedia stuff, and it sounds like you only need to a small portion of it. It may be simpler to use two libraries, one for reading/writing wav files, and one for reading/writing mp3 files. Depending on how simple the header format of a wav file or mp3 file is, you maybe able to directly read from the headers themselves to get the information you're looking for (open the file in binary mode).