![](/img/trans.png)
[英]How to solve “error LNK2001: unresolved external symbol _CLSID_D2D1Blend” when using Direct2d Effects?
[英]MAPI Linking Static Library (LNK2019: Unresolved External Symbol)
我尝试使用Visual Studio 2017来利用Microsoft的MAPI(扩展MAPI)。
所以首先我创建了一个包含3个项目的解决方案:
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN
// Not auto generated
#define DLLEXPORT __declspec(dllexport)
#pragma once
namespace NativeWrapper
{
class DLLEXPORT InstanceManager
{
public:
InstanceManager();
int Init();
void UnInit();
~InstanceManager();
private:
bool _Initialized;
};
}
#pragma once
#include "stdafx.h"
#include "InstanceManager.h"
namespace NativeWrapper
{
InstanceManager::InstanceManager()
{
_Initialized = false;
}
int InstanceManager::Init()
{
if (!_Initialized)
{
MAPIINIT init = {
MAPI_INIT_VERSION,
MAPI_MULTITHREAD_NOTIFICATIONS
};
return MAPIInitialize(&init);
}
}
void InstanceManager::UnInit()
{
if (_Initialized)
{
MAPIUninitialize();
}
}
InstanceManager::~InstanceManager()
{
UnInit();
}
}
我还下载了MAPI开发所需的标头,并通过将相应的路径( C:\\Office 2010 Developer Resources\\Outlook 2010 MAPI Headers
)添加到其他包含目录中来引用它们。
#pragma once
#include "..\StaticLib1\NativeInstanceManager.h"
namespace MAPIManaged
{
ref class InstanceManager
{
public:
InstanceManager();
~InstanceManager();
int Init();
void UnInit();
private:
NativeWrapper::InstanceManager* _NativeObject;
};
}
#include "stdafx.h"
#include "InstanceManager.h"
namespace MAPIManaged
{
InstanceManager::InstanceManager()
{
_NativeObject = new NativeWrapper::InstanceManager();
}
InstanceManager::~InstanceManager()
{
delete _NativeObject;
}
int InstanceManager::Init()
{
return _NativeObject->Init();
}
void InstanceManager::UnInit()
{
_NativeObject->UnInit();
}
}
在(1)上也有一个Project-Reference。 我是通过右键单击Project 2并添加Project 1来完成的。
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var obj = new MAPIManaged.InstanceManager();
obj.Init();
}
}
}
在(2)上也有一个Project-Reference。 我是通过右键单击Project 3并添加Project 2来实现的。
尽管我引用了静态库,但出现以下错误:
Error LNK2019 unresolved external symbol "_MAPIUninitialize@0"
in function ""public: void __thiscall NativeWrapper::InstanceManager::UnInit(void)" (?UnInit@InstanceManager@NativeWrapper@@QAEXXZ)".
ClassLibrary1 PATH\WrapNative\ClassLibrary1\StaticLib1.lib(InstanceManager.obj) 1
Error LNK2019 unresolved external symbol "_MAPIInitialize@4"
in function ""public: int __thiscall NativeWrapper::InstanceManager::Init(void)" (?Init@InstanceManager@NativeWrapper@@QAEHXZ)".
ClassLibrary1 PATH\WrapNative\ClassLibrary1\StaticLib1.lib(InstanceManager.obj) 1
您永远不应静态链接到任何MAPI函数-您必须首先找到正确的MAPI dll并使用LoadLibrary / GetProcAddress。
查看MFCMAPI源代码 ,以获取有关如何完成此操作的示例。
扩大Dmitry的答案-唯一的mapi32.lib版本存在错误(缺少导出,错误的参数数量和类型等),并且十年来一直没有Microsoft的支持。 MSDN文章“ 链接到MAPI函数”对此进行了深入讨论,并提供了许多链接到MAPI的选项,所有这些选项归结为:1-找到正确的MAPI DLL加载,这很简单,涉及到对FGetComponentPath的调用。找到正确的MAPI实现。 实际上,您可以通过仅链接到系统mapi32.dll(本身是存根)来稍微简化此步骤,但是您会错过Outlook MAPI提供的未在系统存根中公开的导出。 2-找到后,使用LoadLibrary和GetProcAddress链接到导出。
本文还链接到Microsoft推荐的MAPIStubLibrary ,其中封装了上述逻辑。 最好使用此存根库代替手动滚动位置和链接逻辑。
免责声明:我是Microsoft员工,是MFCMAPI的作者,并且与Outlook开发团队一起是MAPI Stub库的合著者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.