C ++使用C#DLL。 InvokeHelper问题

时间:2011-02-17 16:58:15

标签: c# c++ dll vc6

我有一个c#dll,非常简单:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassTestPourCPP
{
    [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDual)]
    public class MainClass
    {
        public int GiveInt2()
        {
            return 2;
        }
    }
}

我希望我的C ++应用程序(VC6)能够使用它。所以我用启用了“set visible to com”选项构建了我的dll。 我诅咒DLL,所以我有tlb文件。 然后我在IDE中导入了tlb,它生成了一个.h& .cpp文件,完全像它应该的那样。

long _MainClass::GiveInt2()
{
    long result;
    InvokeHelper(0x60020004, DISPATCH_METHOD, VT_I4, (void*)&result, NULL);
    return result;
}

现在问题是当我调用方法时,它只是..不是东西,给我一个错误的输出(它在调用之前给出了结果的值,就好像在InvokeHelper中有一个try catch)

为什么不工作? :(

非常感谢!

1 个答案:

答案 0 :(得分:1)

在尝试使用COM对象之前,您是否曾致电CoInitialize

相关问题