C++ using C# DLL. Problem with InvokeHelper

1.1k Views Asked by At

I have a c# dll, really simple:

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;
        }
    }
}

And I want my C++ app (VC6) to use it. So I built my dll with the option "set visible to com" enabled. I regasm the DLL, so I have the tlb file. Then I imported the tlb in the IDE, It generated a .h & .cpp file, exactly like it should.

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

The problem is now when I call the method, it just .. does not thing, giving me a wrong output (it gives the value of result before the call, like if there is a try catch inside the InvokeHelper)

Why isn't it working? :(

Thank you very much!

1

There are 1 best solutions below

4
On

Did you call CoInitialize before trying to use the COM object?