当我在VBA中使用C#回调函数时,它显示;“未找到入口点”;

当我在VBA中使用C#回调函数时,它显示;“未找到入口点”;,c#,vba,callback,C#,Vba,Callback,我想在VBA中使用C#回调函数。但当我调用C#函数时,它显示“未找到入口点” 我怎样才能修好它? 谢谢 PS:我选中了使组件COM可见并注册COM inter 环境:MS Office Excel 2007、MS Visual Studio 2008 VBA代码: Declare Function Result Lib"C:\Users\admin\Desktop\myprog\New_DLL_Test\New_DLL_Test\bin\Debug\New_DLL_Test.dll" Alias

我想在VBA中使用C#回调函数。但当我调用C#函数时,它显示“未找到入口点”

我怎样才能修好它? 谢谢

PS:我选中了使组件COM可见并注册COM inter 环境:MS Office Excel 2007、MS Visual Studio 2008

VBA代码:

Declare Function Result Lib"C:\Users\admin\Desktop\myprog\New_DLL_Test\New_DLL_Test\bin\Debug\New_DLL_Test.dll" Alias "Msg" (ByVal p As Long) As Integer

Function Disp()
   MsgBox x
End Function

Sub AddResult(ByVal p As Long)
    Dim x As Long   
    x = Result(p)
    Debug.Print x
End Sub

Sub testnow_Click()
    Call AddResult(AddressOf Disp)
End Sub
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace New_DLL_Test
{
    [Guid("f1286974-0f1a-466c-8389-dd1ab7e3eed2"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
    interface Msginterface
    {
        int Msg;
    }
    public unsafe class MsgProcess
    {
        public int Msg(int* p)
        {
           return add(p,1);
        }
        public int add(int* p, int j)
        {
            return j+1;
        }
    }

}
C#代码:

Declare Function Result Lib"C:\Users\admin\Desktop\myprog\New_DLL_Test\New_DLL_Test\bin\Debug\New_DLL_Test.dll" Alias "Msg" (ByVal p As Long) As Integer

Function Disp()
   MsgBox x
End Function

Sub AddResult(ByVal p As Long)
    Dim x As Long   
    x = Result(p)
    Debug.Print x
End Sub

Sub testnow_Click()
    Call AddResult(AddressOf Disp)
End Sub
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;


namespace New_DLL_Test
{
    [Guid("f1286974-0f1a-466c-8389-dd1ab7e3eed2"), InterfaceType(ComInterfaceType.InterfaceIsDual)]
    interface Msginterface
    {
        int Msg;
    }
    public unsafe class MsgProcess
    {
        public int Msg(int* p)
        {
           return add(p,1);
        }
        public int add(int* p, int j)
        {
            return j+1;
        }
    }

}

VBA declare函数允许您访问从DLL导出的stdcall函数。COM可见类和接口是完全不同的。尽管这两个方法可以一起工作,但作为非托管导出的函数可以返回com可见对象。或者,每种方法都可以独立使用

从VBA调用静态C#函数 如果您希望以这种方式编写VBA代码,并像这样访问DLL,则需要从C#项目创建非托管导出。我相信有两种方法可以做到这一点。一个是手动创建一个包装在管理C++中导出函数。另一种方法是使用编译时构建任务和类库

使用VBA中的COM可见C#对象
要通过COM互操作使用C#类,需要使用regasm.exe注册C#程序集,然后使用CreateObject函数在VBA中创建对象。类和接口都需要是COM可见的

没有任何评论的否决票?那没用。这是一个我感兴趣的话题,所以我很想知道我的方法是错误的还是更好的。我应该对这个问题投反对票,而不是对答案投反对票。回顾一下这个问题,虽然不清楚,但得到了很好的回答。当时的答案似乎不完整,因为我正在寻找一个涵盖集成其他方面的答案,比如线程。