调用 MAPIUninitialize 后应用程序崩溃一次 api

Application crashes once after I call MAPIUninitialize api

所以,我一直在和 MAPIAPI 一起工作。每当我调用 MAPIUninitializeapi 时,我的应用程序就会崩溃。在进一步调试中,我发现,IMAPISession::OpenMsgStore 是崩溃的原因,每当在程序运行时执行 OpenMsgStore 函数时,我的应用程序恰好在 MAPIUninitialize 被触发后崩溃。这类似于下面提到的这个线程中的讨论,其中 soln 不可用。

https://peach.ease.lsoft.com/scripts/wa-PEACH.exe?A2=MAPI-L;e6f3847a.0801&S=

我已经检查了我的程序是否有内存泄漏,我确定存在 none 而且,如果我评论那个特定的 api,我的程序不会崩溃,我不明白原因对于崩溃。我已经尝试了所有可能的选择。有人可以帮忙吗?

这很可能意味着您仍有活动的 MAPI 对象。也有可能是 MAPIInitialize / MAPIUninitialize 的顺序太快,当您尝试关闭它时,普通 Office 运行-时间仍在(异步)初始化。

此外,并非所有商店都生而平等 - IMAP4 可能是最差的。

不清楚何时何地使用这些方法。是副线程吗?

无论如何,这是 MSDN 的声明:

A client must also invoke MAPIInitialize on every thread before using any MAPI objects and MAPIUninitialize when that use is complete. These calls should be made even if the objects to be used are passed to the thread from an external source. MAPIInitialize and MAPIUninitialize can be called from anywhere except from within a Win32 DllMain function, a function that is invoked by the system when processes and threads are initialized and terminated, or upon calls to the LoadLibrary and FreeLibrary functions.

我建议使用 MFCMAPI 源代码 - 您可以 运行 在调试器下查看问题是否仍然可重现。

感谢您的精彩建议。我已经解决了这个问题,我的应用程序实际上调用了 golang 的 c++ dll 中定义的 mapi api。因此,每个定义为 DLL 函数的 mapi api 都有不同的线程 ID,当我使用 runtime.LockOSThread() / runtime.UnlockOSThread 将 DLL 函数调用绑定到同一个线程时() ,它开始工作,不再崩溃。

参考:https://golang.org/pkg/runtime/#LockOSThread