I want to try something simple with Direct Sound. Just want to know if it's possible.
Or maybe I need some other API?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.Sign up to join this community
If you are for some reason dead set on C, OpenAL may be the audio API to choose as it is a pure C API. OpenAL is a very low-level API. I'm unsure how it compares to DirectSound as I'm used to working with more complete frameworks/engines/games which tend to use something like FMOD or Wwise rather than trying to roll their own high-level audio manipulation library. Depending on what you're trying to do, a library like one of those might be a better option for you, too.
There are ways to bind DirectSound to C, and there at one point was even an official C binding for many DX components (no idea if it's still maintained), but in general this is not the way to go.
Short version: use C++ or use OpenAL.
It's not only possible, it's actually been done.
OK, I wouldn't go so far as to call out early id Software code as the epitome of good coding standards, but it does demonstrate that using DirectX in pure C isn't something that exists on a theoretical level, but rather something that has shipped in popular working commercial products.
Despite that you may have problems.
In the DirectInput example, typing out all of the wrapper macros can be a total pain-in-the-ass. In the DirectSound example, earlier versions of MSVC didn't have autocomplete on the lpVtbl member, which can also be a total pain-in-the-ass (I haven't bothered checking with more recent versions).
There are other places in other DirectX APIs where some C++ isms have crept in, notably in the D3DX math stuff, and which can be awkward (but not impossible) if you wish to use them from C.
Nonetheless, fundamentally DirectX is a COM-based API, and while COM may look on the surface as if it is C++ based, it's actually not - a COM interface isn't a class, it's a struct, and full C compatibility exists (COM as-designed is intended to be language-neutral). I suggest checking out the Wikipedia article on COM for further info.
Ofcourse. DirectX is written in plain C. Sure, there are some C++ extension libraries for help on math-related stuff (matrices, vectors etc), but those are typically not long-lived (early deprecated), and rightfully so. Hence you shouldn't even be using those C++ libraries; at least not if you want your code to become deprecated over time.