首页 > 解决方案 > 使用 mapi.h 函数

问题描述

我想从 mapi.h 头文件中调用 MAPISendMail 函数。在我的 c++ 动态库项目中,我有 MathLibrary.h 文件,其中包含以下代码:

#ifdef MATHLIBRARY_EXPORTS
#define MATHLIBRARY_API __declspec(dllexport)
#else
#define MATHLIBRARY_API __declspec(dllimport)
#endif

#include <windows.h>
#include <mapi.h>
extern "C" MATHLIBRARY_API ULONG MAPISendMail(LHANDLE lhSession,
    ULONG_PTR ulUIParam,
    lpMapiMessage lpMessage, 
    FLAGS flFlags,
    ULONG ulReserved);

MathLibrary.cpp 文件:

#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include <utility>
#include <limits.h>
#include "MathLibrary.h"
#include <fstream>
#include <string>


// DLL internal state variables:
static unsigned long long previous_;  // Previous value, if any
static unsigned long long current_;   // Current sequence value
static unsigned index_;               // Current seq. position

ULONG MAPISendMail(LHANDLE lhSession,
    ULONG_PTR ulUIParam,
    lpMapiMessage lpMessage,
    FLAGS flFlags,
    ULONG ulReserved)
{
     //HERE I WOULD LIKE TO READ MAIL ATTACHMENT FILE PATH
    MessageBoxW(NULL, L"MAPISendMail!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
    
    std::ofstream outfile;
    outfile.open("test.txt", std::ios_base::app); // append instead of overwrite
    outfile << "Mapisenddocuments";
    return 0;
}

我收到此错误:

错误 C2373 'MAPISendMail':重新定义;不同的类型修饰符 DllTestHeader

我的目标是创建将使用 Mapi 函数来获取和处理电子邮件附件文件路径的 dll。

标签: c++

解决方案


推荐阅读