Code sample based on Windows APIs in order to format USB storage devices

Hi all,
I’m looking for a code sample based on Windows APIs, able to format at least USB storage volumes, else any storage volume.
I tried Shell commands, including diskpart, but I’m facing a lot of problems such as “Volume not found”, errors in format process, etc.
I didn’t find what I’m looking for in MBS plugins, but the doc is so huge…

Thanks for any sample or link, even if code is in C++ or VB, it may be of any help for me.

Jean-Luc