这个问题一直让我头疼几天,我找不到原因。我很确定这是我的机器特有的环境问题,但它仍然会导致测试问题。64位类型库和32位类型库不同步
我使用Visual Studio 2010 Professional在C#中创建了一个DLL。第一版在下面;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace TestCOM
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ProgId("TestCOM.Class1")]
[System.Runtime.InteropServices.Guid("803A1B2F-1CDA-4571-9084-87500388693B")]
public class Class1
{
public void showMessage()
{
MessageBox.Show("Hello from TextCom");
}
}
}
这个程序集编译得很好,一切都很好。我运行以下脚本将其注册为COM对象(首先是32位,然后是64位);
C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe TestCOM.dll /codebase /nologo /tlb:TestCOM32.tlb
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe TestCOM.dll /codebase /nologo /tlb:TestCOM64.tlb
然后用下面的脚本来测试它;
dim tc
set tc = CreateObject("TestCOM.Class1")
tc.showMessage()
我使用csript测试脚本,所以可控制它使用位深度 - I具有32位与64位的一次测试,并一次。到目前为止,一切都很好。
现在,当我修改原来的组件添加功能,如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace TestCOM
{
[ClassInterface(ClassInterfaceType.AutoDual)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ProgId("TestCOM.Class1")]
[System.Runtime.InteropServices.Guid("803A1B2F-1CDA-4571-9084-87500388693B")]
public class Class1
{
public void showMessage()
{
MessageBox.Show("Hello from TextCom");
}
public void HelloWorld()
{
MessageBox.Show("Hello World!!");
}
}
}
修改之前,我注销使用“regasm /注销”库并报告所有类型的未注册成功。
当我注册库时,现在有了更改,原始测试脚本完美地工作。如果我扩展测试脚本以调用新的HelloWorld函数;
在32位脚本中,它完美地工作。 在64位脚本,它抱怨TestCOM.Class1对象不存在这样的功能
我试过这种方式我可以,但我无法确定为什么新功能可用于32位呼叫者,但不是64位呼叫。
我在做什么错?是否有缓存的地方我不知道的64位的东西,或需要更改的注册表设置?
要清楚; 1.构建组件使用 2.寄存器regasm,一次为32,一次用于64 3.测试使用脚本 - 一切正常 4.取消注册库 5.进行修改,重建 6.注册为每2步 7 。测试工作在32位,但不是64. Wtf?
你绝对的传说。 看来,出于某种原因,dll的早期版本的副本是在C:\ WINDOWS \ SYSTEM32 删除该副本立即解决问题,无需重新注册任何东西,等等。 Thankyou - 我从来没有想过使用procmon来看看发生了什么。 最后一个问题 - 你是说我不应该指定一个GUID?我总是被告知你必须? – DFriend 2013-03-05 15:04:28