如何创建 MAPI32.dll 存根以便能够“作为附件发送”来自 MS Word?
Microsoft Word 具有“作为附件发送”功能,可在 Outlook 中创建带有附件的新邮件。
我想用自定义邮件代理替换 Outlook,但我不知道如何实现这一点。现在我的邮件代理只是一个运行的程序,并以文件名作为参数。
据我所知,“作为附件发送”正在使用一些称为 MAPI 的 DLL/API。我需要更改我的应用程序,以便它不仅接受文件名参数,而且可以接收 MS Word 在“作为附件发送”时使用的 MAPI(?) 调用。
此外,我需要通过创建自己的 MAPI32.dll 存根来更改默认邮件代理,该存根仅重定向到我的应用程序。
如果有人能提供有关如何实现这一目标的更多信息,我将不胜感激!
Microsoft Word has "send as attachment" functionality which creates a new message in Outlook with the document attached.
I would like to replace Outlook with a custom mail agent, but I do not know how to achieve this. Now my mail agent is simply a program that runs, and takes a file name as parameter.
As far as I know, "send as attachment" is using some DLL/API called MAPI. I would need to change my app so that it does not simply accept file name arguments, but can receive MAPI(?) calls MS Word uses when "sending as attachment".
Further, I need to change the default mail agent by creating my own MAPI32.dll stub which simply redirects to my app.
I'd appreciate if anyone had more info on how this could be achieved!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,回答我自己的问题。我需要构建一个定义了“MAPISendDocuments”和/或“MAPISendMail”函数的 DLL。
该 DLL 可以有任何名称,并在 HKLM/Software/Clients/Mail/MyMailApp/DLLPath 的注册表中引用。
找到使用 Delphi 的示例...
OK, to answer my own question. I need to build a DLL with "MAPISendDocuments" and/or "MAPISendMail" functions defined.
This DLL can have any name, and is referenced in the registry at HKLM/Software/Clients/Mail/MyMailApp/DLLPath.
Found examples using Delphi...
在编写自己的mapi实现时,创建一个具有正确导出和调用约定的dll至关重要,以便系统存根mapi dll(c:\windows\system32\mapi32.dll,应与mapistub.dll相同)将调用传递给您的 dll。 MAPI 函数使用 __stdcall 调用约定进行调用。同样重要的是设置正确的注册表项,以便系统存根选择您的mapi dll,看起来您已经找到了正确的注册表项,以便在您的应用程序进行mapi 调用时指定要使用的特定mapi dll。
我最近做了这件事:编写了我自己的 Mapi DLL 骨架,并且在让系统存根调用我的扩展 Mapi 函数时遇到了很多麻烦。关键是mapi32.dll在“foo@x”入口点上调用GetProcAddress,而不是mapi接口中的“foo”入口点,以测试您的dll是否与扩展mapi“兼容”(我认为简单mapi 称它不使用“foo@x”,而是使用普通的“foo”入口点名称)。我还必须在我的项目中“As C”而不是“As C++”编译我的骨架库接口文件,以便使所有符号名称正确。
例如,MAPIInitialize 应在源代码中这样声明:
并且您需要指定一个包含如下条目的 .def 文件:
对于简单的 mapi 调用(与扩展的 mapi 调用相反),您可能不需要“双出口”。为了查看工作的 mapi 实现的导出是什么样子,您可以执行以下操作(如果您的系统上安装了 Outlook):(
或者替换您在注册表中找到的路径 HKLM\Software\Clients\邮件\Microsoft Outlook\DLLPathEx)
When writing your own mapi implementation it is critical to create a dll with both the proper exports and calling conventions in order for the system stub mapi dll (c:\windows\system32\mapi32.dll, should be the same as mapistub.dll) to pass calls through to your dll. MAPI functions are called with the __stdcall calling convention. Also critical is setting the right registry keys in order for you mapi dll to be chosen by the system stub, it looks like you've already found the right one in order to specify a particular mapi dll be used when your applicaion makes mapi calls.
I did this exact thing just recently: wrote my own skeleton mapi dll, and had a lot of trouble getting the system stub to call my extended mapi functions. The key was that mapi32.dll calls GetProcAddress on the "foo@x" entry point, not the "foo" entrypoint in the mapi interface in order to test whether or not your dll is "compliant" with extended mapi (I think for simple mapi calls it does not use the "foo@x" but the plain "foo" entrypoint name). I also had to compile my skeleton library interface file in my project "As C" and not "As C++" in order to get all the symbol names right.
For example, MAPIInitialize should be declared like this in your source code:
and you'll need to specify a .def file with entries like this:
For simple mapi calls (as opposed to extended mapi calls), you may not need the "double export". In order to see what the exports look like for a working mapi implementation, you can do this (if you have outlook installed on your system):
(or substitute the path you find in the registry in
HKLM\Software\Clients\Mail\Microsoft Outlook\DLLPathEx
)