## Recommended Posts

surfi    128
Hello. I am initializing the COM for using DirectSound. I am using the functions CoInitializeEx, CoCreateInstance (and later I will need CoUninitialize). But all of them cause a linking error of undefined reference to them. In addition, there is a first line in the error message that says: .drectve '/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" unrecognized The files specified for linking are "dsound.lib" and "dxguid.lib". Here is the code (still not error handling added, I know)
#include "CDevice.h"
#include <Dsound.h>
#include <iostream>

using std::cout;
using std::endl;

namespace snd {

CDevice::CDevice () {
HRESULT hr;

hr = CoInitializeEx (NULL, 0);
if (FAILED(hr)) { cout << "A" << endl; };

hr = CoCreateInstance (CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, IID_IDirectSound8, (LPVOID*)&lp_Direct_Sound);
if (FAILED(hr)) { cout << "B" << endl; }

hr = lp_Direct_Sound->Initialize (NULL);
if (FAILED(hr)) { cout << "C" << endl; }

HWND window_handler;
window_handler = GetForegroundWindow ();
hr = lp_Direct_Sound->SetCooperativeLevel (window_handler, DSSCL_PRIORITY);
if (FAILED(hr)) { cout << "D" << endl; };
}

CDevice::~CDevice () {
CoUninitialize ();
}

} // End of namespace


I tried before to init the COM by the indirect way, but now I need to do it this way to add effect support to the application. Does anyone knows what's the problem on here? Thanks in advance!

##### Share on other sites
S1CA    1418
Make sure you link with ole32.lib (which contains the imports for CoInitializeEx etc).

/DEFAULTLIB: is the linker option that specifies the default libraries to link against - any libraries you specify in the 'Input' section of the MSVC linker settings gets turned into a /DEFAULTLIB. Libraries which have directives to include other libraries can also insert /DEFAULTLIB's into your link settings.

If you're getting a warning or error about it, then either a library name or the /DEFAULTLIB switch has been specified in the wrong place (e.g. compilation settings, or a path rather than the input libraries) OR the version of the linker you're using doesn't understand that switch (either in your project or embedded in the lib you're linking with) - are you using an old compiler/linker (MSVC6 or an older version of the Intel compiler perhaps?) or maybe a non-MS compiler.

If it's just a warning you're getting, then in this case, it's nothing to worry about once you get things linking (you may need to explicitly link to uuid.lib though)

##### Share on other sites
surfi    128
Very helpful, since I didn't link ole32.lib (now I know). I'm still having a warning message about uuid.lib (which I am now linking explicitly), but the program is finally linking and working. And about the compiler, you were right, it is not MVS. It is DevC++. Well, thanks again!