我在使用DirectSoundCapture组件,下面程序是从DIRECTX的例子中考来的。
原来的例子程序用C写的,编译链接都没问题。
// Get interface for capture buffer notification.
    if ( FAILED( hr = lpdscb->QueryInterface( IID_IDirectSoundNotify, 
            ( VOID ** )&lpdsnInput ) ) )
        return FALSE;     // Set capture buffer notifications.
    if ( FAILED( hr = lpdsnInput->SetNotificationPositions(
    NUMCAPTUREEVENTS, rgdscbpn ) ) )
    {
        lpdsnInput->Release();
        return FALSE;
    }
我把这段移植到我的类函数中,link报错:
Linking...
DDSound.obj : error LNK2001: unresolved external symbol _IID_IDirectSoundNotify
Debug/sndplay.exe : fatal error LNK1120: 1 unresolved externals

解决方案 »

  1.   

    Header: Declared in dsound.h.
    Import Library: Use dsound.lib
      

  2.   

    #define INITGUID before all header
    or
    #include "objbase.h"
    #include "initguid.h"
      

  3.   

    可原来的例子程序为什么没事呢?下面是从另一个帖子找来的。
    我估计是默认预编译头文件的问题。HOWTO: Avoid Error LNK2001 Unresolved External Using DEFINE_GUID
    The information in this article applies to:
    Microsoft Visual C++ 2.0
    Microsoft Visual C++ 2.1
    Microsoft Visual C++ 4.0
    Microsoft Visual C++ 4.1
    Microsoft Visual C++, 32-bit Enterprise Edition 4.2
    Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    Microsoft Visual C++, 32-bit Professional Edition 4.2
    Microsoft Visual C++, 32-bit Professional Edition 5.0
    Microsoft Visual C++, 32-bit Professional Edition 6.0
    Microsoft Visual C++, 32-bit Learning Edition 6.0This article was previously published under Q130869 
    SUMMARY
    A GUID must be initialized exactly once. For this reason, there are two different versions of the DEFINE_GUID macro. One version just declares an external reference to the symbol name. The other version actually initializes the symbol name to the value of the GUID. If you receive an LNK2001 error for the symbol name of the GUID, the GUID was not initialized. You can make sure your GUID gets initialized in one of two ways: 
    If you are using precompiled header files, include the INITGUID.H header file before defining the GUID in the implementation file where it should be initialized. (AppWizard-generated MFC projects use precompiled headers by default.) 
    If you are not using precompiled headers, define INITGUID before including OBJBASE.H. (OBJBASE.H is included by OLE2.H.)
    MORE INFORMATION
    Here is the definition of DEFINE_GUID as it appears in OBJBASE.H: 
          #ifndef INITGUID
          #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, \ 
                                    b4, b5, b6, b7, b8)
              EXTERN_C const GUID FAR name
          #else      #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, \ 
                                    b4, b5, b6, b7, b8)
             EXTERN_C const GUID name \ 
                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
          #endif // INITGUID

    Note that if the symbol INITGUID is not defined, DEFINE_GUID simply defines an external reference to the name. In INITGUID.H, you find (among other things): 
          #undef DEFINE_GUID      // Other code . . .      #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, \ 
                                    b4, b5, b6, b7, b8)
             EXTERN_C const GUID __based(__segname("_CODE")) name \ 
                      = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }

    By including INITGUID.H after OBJBASE.H, DEFINE_GUID is modified to actually initialize the GUID. NOTE: It is important to make sure that this is done exactly once for each DLL or EXE. If you try to initialize the GUID in two different implementation files and then link them together, you get this error: LNK2005 <symbol> already defined.
      

  4.   

    1:你试一下把debug(编译器)调整一下
    2:你把IID_IDirectSoundNotify的标识符拷构过来
    3:lpdscb->QueryInterface( IID_IDirectSoundNotify,(VOID**)&lpdsnInput ) 改成lpdscb->QueryInterface( __uuidof(IID_IDirectSoundNotify),(void**)&lpdsnInput ) 
      

  5.   

    #include "initguid.h"  加在哪里合适呢?我做了一个类CDDSound封装DIRECTX的某些功能。
    如果将#include "initguid.h"
         #include "dsound.h"
    加在ddsound.h 中则报一堆LNK2005 <symbol> already defined.
    如果加在.cpp中则报LINK2001如果只加在stdafx.h中则报
    StdAfx.obj : error LNK2005: _IID_IDirectSoundNotify already defined in DDSound.obj
      

  6.   

    luoqy(QYcsdn)
    #include "initguid.h"似乎只能加在 #include "dsound.h"之前,并且是
    “dsound.h”第一次被编译的的地方,否则没用。
    我原来将   #include "dsound.h"放在CDDSound类的头文件中的,试着把
    其中的#pragma once,然后在出现IID_IDirectSoundNotify的.cpp前加入
         #include "initguid.h"
         #include "dsound.h"
    仍然报error LNK2001: unresolved external symbol IID_IDirectSoundNotify
      

  7.   

    加在stdafx.h中:
    #include "objbase.h"
    #include "initguid.h"#include "dsound.h"不要加在stdafx.h中
      

  8.   

    谢谢 paul2002() 以及各位,我加分!
    不得已我把 定义从dsound.h中挖出来
    const GUID   IID_IDirectSoundNotify={ 0xb0210783, 0x89cd, 0x11d0, {0xaf, 0x8, 0x0, 0xa0, 0xc9, 0x25, 0xcd, 0x16}};
    编译过了。用你最后的指导试验一下,结果报一堆LINK2005;
    当时设置是这样的:
    stdafx.h中: 
    ...
    #include <mmsystem.h>
    #include "objbase.h"
    #include "initguid.h"#pragma comment(lib, "winmm.lib")
    #pragma comment(lib, "dsound.lib")
    ...
    我的类定义在DDsound.h中:
    ...
    #include "dsound.h"   //********class CDDSound  
    {
    ...
    在DDsound.cpp中:
    #include "DDsound.h"这个类要在APP中有一个各处都可调用的对象,所以在那里:
    ...
    #include "resource.h"       // main symbols
    #include "DDsound.h"/////////////////////////////////////////////////////////////////////////////
    // CSndplayApp:
    // See sndplay.cpp for the implementation of this class
    //class CSndplayApp : public CWinApp
    ...
      

  9.   

    在DDsound.cpp中#include "dsound.h"
    如果你的CDDSound类中要声明IDirectSoundNotify的指针,你可已在头文件开始处:
    struct IDirectSoundNotify;
      

  10.   

    DSound 需要连接 dxerr9.lib winmm.lib dsound.lib dxguid.lib ...
    看起来你好象没有连接 dxguid.lib