2

I'm trying to figure out how to solve this. I tried many things that I saw on internet but with no success. I tried: to use regasm, compile target as x86, dumpbin dll /t:dll.tlb, change the version of Framework etc.

I have two machines (M1 and M2) both with windows 7 64 and VS2012. When I develop a COM in M1, it runs fine in VBA of M1. But it doesn't work for M2 (Error 429). Then, if I go to M2 and write a new COM, it works fine in VBA of M2, but not for M1.

It seems that VS2012 is performing a "hidden" registration step that I can't see. Does someone know how to find that?

Many thanks! Below is my "COM Hello World". I'm using Register for COM interop as well.

UPDATE:

If I run:

C:\windows\Microsoft.NET\Framework\v4.0.30319\regasm TesteLib.dll /TesteLib.tlb 

the 429 error disappears. But now, instead of error 429, I'm getting "error -2147024894 (80070002) Automation Error" in the same line.

I followed the solution from Can't instantiate a COM object written in C# from VBA (VB6 ok) to create a Excel.Exe.Config inside EXCEL.exe folder and my program runs fine now. But I think that I can't perform this on client machines. Is there an alternative to that?

Also, it works ok in VB6 (without the need to perform the REGASM).

.net side

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace TesteLib
{
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [Guid("c6b093c6-f568-4962-8955-795fc14f34bb")]
    [ComVisible(true)]
    public interface ClassInt1
    {
        int sum(int a, int b);
    }

    [ClassInterface(ClassInterfaceType.None)]
    [Guid("19ff9b41-8652-4012-ac55-c1a1d8f18cbb")]
    [ComVisible(true)]
    [ProgId("TesteLib.Class1")]
    public class Class1 : COMException, ClassInt1
    {
        public int sum(int a, int b)
        {
            return a + b;
        }
    }

}

VBA side

Sub t()
    Dim r As TesteLib.Class1
    Set r = New TesteLib.Class1 'Run-time error '429': ActiveX component can't create object
    MsgBox r.Sum(35, 51)
End Sub
4

1 回答 1

3

现在它正在工作!

我需要使用带有选项 /codebase 的 REGASM 注册 DLL

C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /codebase TesteLib.dll 

当我包含选项 /codebase 时,它​​会生成一个警告,但它可以工作:RegAsm 警告:使用 /codebase 注册未签名的程序集可能会导致您的程序集干扰可能安装在同一台计算机上的其他应用程序。/codebase 开关旨在仅用于已签名的程序集。请给您的程序集起一个强名称并重新注册

然后,在 VS2012 中,我标记了选项 Project Properties > Signing > Sign the assembly > New... 并运行 REGASM。警告消失了,现在一切似乎都很好:)

谢谢!

于 2013-09-24T15:01:01.413 回答