c# - 当 c# Outlook 插件使用 c++ 库中的函数时崩溃

标签 c# c++ outlook

我写了一个加载c++库的outlook插件,插件可以看到库中的函数,但是在使用时,它崩溃了。

这是我的 C++ 库代码:

//测试DLL.h

#pragma once

using namespace System;

namespace TestDLL {

public ref class MyClass
{
public:
    int Add(int a, int b);
};
}

//测试DLL.cpp

#include "stdafx.h"

#include "TestDLL.h"

namespace TestDLL  {

int MyClass::Add(int a, int b) 
{
    return a + b;
}
}

这是我的插件代码:

using TestDLL;

public partial class ThisAddIn
{
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Thread t = new Thread(new ThreadStart(Test));
        t.Start();
    }

    private void Test()
    {
        MyClass myClass = new MyClass();
        int res = myClass.Add(12, 25);

        MessageBox.Show("res:" + res);

    }

    private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    {
    }

如果我尝试使用 C# 表单应用程序,它会起作用。那么这里发生了什么?

最佳答案

Outlook 的位数应与非托管 DLL 的位数相对应。您不能将 x86 dll 加载到 x64 进程中。

关于c# - 当 c# Outlook 插件使用 c++ 库中的函数时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28363922/

相关文章:

c# - 谷歌新闻 rss 参数 num 100 只返回 30 个结果

c++ - C++ 的 Option/Maybe 类

c++ - 在 C++ 中将包含方法定义的类声明放在头文件中是否被认为是错误的形式?

vba - 通过自动调整将 Excel 范围发送到电子邮件正文

html - Div 填充/背景颜色在 Outlook 中不起作用

C# Outlook Mailitem ContextMenu 和 Ribbon 不能一起工作(只能单独使用)

c# - 服务栈 4.5.14 & .Net Core 2.0

c# - 如何在 ItemsControl 中设置从 ItemTemplate 到托管容器的绑定(bind)? (UWP)

c# - wcf中的单例模式

c++ - 没有匹配的函数调用