0

I am trying to get in touch with the DirectX SDK. I managed to install it, created a new Win32 Console Project and added following lines

#include <iostream>
#include <xaudio2.h>

int main(int argc, char *argv[]){
IXAudio2* pXAudio = 0;
IXAudio2MasteringVoice *pXAudioMasterVoice = 0;
HRESULT hr;

CoInitializeEx(NULL, COINIT_MULTITHREADED);

hr = XAudio2Create(&pXAudio, 0, XAUDIO2_DEFAULT_PROCESSOR);
if(FAILED(hr)){
    CoUninitialize();
    return hr;
}

hr = pXAudio->CreateMasteringVoice(&pXAudioMasterVoice);
if(FAILED(hr)){
    pXAudio->Release();
    CoUninitialize();
    return hr;
}

CoUninitialize();
std::cout << "Done!" << std::endl;
}

The documentation says, that there is no xaudio2.lib to link to, but it is a COM-object, but I get LNK2019 - unresolved external symbol "__imp__XAudio2Create@12"

Here is the documentation.

Thank you for any hints.

bash.d
  • 13,029
  • 3
  • 29
  • 42
  • XAudio2Create is not COM, it's a standard DLL export. You *do* need to link with Xaudio2.lib. – Simon Mourier Apr 11 '13 at 14:32
  • Please read the "Remarks" section under the link I provided. Additionally there is NO `.lib` in the SDK folder. – bash.d Apr 11 '13 at 14:37
  • I don't know what they mean by that. Using COM only would necessitate a CLSID (I don't see any provided in the .h). xaudio2.lib is available in %Program Files%\Windows Kits\8.0\Lib\win8\um with the Windows 8 SDK. – Simon Mourier Apr 11 '13 at 14:50
  • Gonna have a look at this... – bash.d Apr 11 '13 at 14:51

2 Answers2

2

super late to the party, but I got this to work by following the windows examples here and ensuring my includes like this:

#include <xaudio2.h>
#pragma comment(lib,"xaudio2.lib")
Bernarnald
  • 101
  • 1
  • 4
0

XAudio2Create is not COM, it's a standard DLL export, so you do need to link with Xaudio2.lib. This library is available in %Program Files%\Windows Kits\8.0\Lib\win8\um (installed with the Windows 8 SDK).

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • XAudio in Windows 8.x is version 2.8, which no longer uses COM to instantiate it. XAudio 2.7 and earlier (which are for Windows 7 and earlier) DO use COM. See [here](https://msdn.microsoft.com/en-us/library/windows/desktop/ee415802%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396) for more info. – Sam Jan 28 '16 at 10:51