【问题标题】:error LNK2001: unresolved external symbol LIBID_错误 LNK2001:未解析的外部符号 LIBID_
【发布时间】:2014-09-27 18:16:40
【问题描述】:

我正在创建一个 ATL Com DLL。

在链接期间我收到以下错误

dllmain.obj:错误 LNK2001:无法解析的外部符号 LIBID_ATLProject4Lib

以下是涉及的文件

stdafx.h

#include "targetver.h"

#define _ATL_APARTMENT_THREADED

#define _ATL_NO_AUTOMATIC_NAMESPACE

#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS  // some CString constructors will be explicit


#define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW

#include "resource.h"

#include <atlbase.h>
#include <atlctl.h>
#include <atlcom.h>

ATLProject4.cpp

#include "stdafx.h"
#include "resource.h"
#include "ATLProject4_i.h"
#include "dllmain.h"


using namespace ATL;

class CAppModule : 
    public CComModule
{
};

// Used to determine whether the DLL can be unloaded by OLE.
STDAPI DllCanUnloadNow(void)
{
            return _AtlModule.DllCanUnloadNow();
    }

// Returns a class factory to create an object of the requested type.
STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
{
        return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

// DllRegisterServer - Adds entries to the system registry.
STDAPI DllRegisterServer(void)
{
    // registers object, typelib and all interfaces in typelib
    HRESULT hr = _AtlModule.DllRegisterServer();
        return hr;
}

// DllUnregisterServer - Removes entries from the system registry.
STDAPI DllUnregisterServer(void)
{
    HRESULT hr = _AtlModule.DllUnregisterServer();
        return hr;
}

// DllInstall - Adds/Removes entries to the system registry per user per machine.
STDAPI DllInstall(BOOL bInstall, _In_opt_  LPCWSTR pszCmdLine)
{
    HRESULT hr = E_FAIL;
    static const wchar_t szUserSwitch[] = L"user";

    if (pszCmdLine != NULL)
    {
        if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
        {
            ATL::AtlSetPerUserRegistration(true);
        }
    }

    if (bInstall)
    {   
        hr = DllRegisterServer();
        if (FAILED(hr))
        {
            DllUnregisterServer();
        }
    }
    else
    {
        hr = DllUnregisterServer();
    }

    return hr;
}

dllmain.cpp

// dllmain.cpp : Implementation of DllMain.

   #include "stdafx.h"
#include "resource.h"
#include "ATLProject4_i.h"
#include "dllmain.h"

CATLProject4Module _AtlModule;

// DLL Entry Point
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    hInstance;
    return _AtlModule.DllMain(dwReason, lpReserved); 
}

【问题讨论】:

  • 它所说的多重定义的符号是什么?
  • @user1793036 现在我得到一个不同的错误
  • 使用项目向导创建一个新项目,然后与您的项目进行比较。

标签: visual-studio-2012 com mfc atl


【解决方案1】:

在一个源文件中,写入#define INITGUID,然后写入#include "ATLProject4_i.h"

如果我没记错的话,向导会生成一个名为 initguid.cpp 的文件,其中仅包含这两行,并将其添加到项目中。你似乎错过了你的。

这就是它的工作原理。 MIDL 生成的头文件(通常为IDLFileName_i.h)包含一堆DEFINE_GUID 调用。 DEFINE_GUID 是一个宏,当INITGUID 未定义时扩展为全局变量声明(使用extern),当INITGUID 已定义时扩展为定义(没有extern)。

【讨论】:

  • 当我在 dllmain.h 中有声明 DECLARE_LIBID(LIBID_ATLProject4Lib) 时出现错误如果我评论这部分,它会正确链接。但是当我无法注册时。我尝试了你的建议,但没有奏效
  • 当我在 ATLProject4.cpp 中包含 #include "ATLProject4_i.c" 时,我可以注册它确实注册了。
猜你喜欢
  • 1970-01-01
  • 2012-05-03
  • 2018-08-14
  • 2018-08-24
  • 2020-08-21
  • 2016-09-04
  • 2013-08-19
相关资源
最近更新 更多