我正在创建一个ATL Com DLL。
在链接时,我收到以下错误
dllmain.obj:错误LNK2001:未解析的外部符号LIBID_ATLProject4Lib
以下是涉及的文件
#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>
#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 : 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);
}
答案 0 :(得分:1)
在一个源文件中,写下#define INITGUID
然后#include "ATLProject4_i.h"
。
如果我没记错的话,向导会生成一个名为initguid.cpp
的文件,其中只包含这两行,并将其添加到项目中。你好像想念你的。
这是它的工作原理。 MIDL生成的头文件(通常为IDLFileName_i.h
)包含一堆DEFINE_GUID
个调用。 DEFINE_GUID
是一个宏,在未定义extern
时扩展为全局变量声明(使用INITGUID
),在extern
时扩展为定义(不包含INITGUID
) }已定义。