好的,我的标题可能不够清晰。我使用的应用程序可以开发VB6宏。这个宏需要使用我也开发的.NET DLL。当我在x86模式下启动应用程序并尝试运行宏时,它工作正常,我可以访问类的方法和所有内容。
但是当我在x64模式下执行相同操作时,我收到错误:"Automation server can't create object"
真正奇怪的是,我不使用任何 x86 unnmanaged COM dll ,这将是x64架构的问题。当我这样做时:"Dim myClass as new MyClass.App"
它正在工作但是当我调用例如myClass.Start()
方法时,我收到此错误。我尝试在我的MsgBox('hello world')
方法中使用Start
,以确保它与我的代码无关,但仍然没有运气。我使用TLB
文件将我的宏链接到我的班级。
我尝试使用RegAsm
注册我的DLL,但它仍然无法在x64中运行。有没有办法生成TLB
的x86和x64版本?然后我会添加两个引用,如果x64版本在Start方法上抛出错误,我只需调用x86方法(不是一个完美的解决方案,但仍然......)。
知道如何解决这个问题吗?
答案 0 :(得分:1)
正如汉斯所说,我需要使用64位版本的Regasm.exe。即使我已经尝试在安装后手动启动RegAsm,但它无法正常工作。首先,我在项目的后期构建事件中添加了:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe" "$(TargetPath)"
这就是Debug版本的诀窍。奇怪的是,AnyCPU版本在我的x64应用程序上工作正常,在调试模式下,当我创建我的安装项目时它开始崩溃(不知道为什么......)。但是这个改变在安装应用程序时并没有解决我的问题,所以我在" Commit"我的自定义操作(基于这篇文章:Regasm- 64bit or 32bit though windows installer in visual studio):
Public Overrides Sub Commit(savedState As System.Collections.IDictionary)
MyBase.Commit(savedState)
'Check if we're on a x64 OS
If Environment.Is64BitOperatingSystem Then
'Get the Windows dir on the current computer
Dim winDir As String = New IO.DirectoryInfo(Environment.SystemDirectory).Parent.FullName
'Define the path to regasm for x64 machines
Dim regasmPath As String = IO.Path.Combine(winDir, "Microsoft.NET", "Framework64", System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion, "RegAsm.exe")
If File.Exists(regasmPath) Then 'Si le chemin existe, on enregistre la DLL
'Get the location of our DLL
Dim componentPath As String = GetType(Installer).Assembly.Location
'Executes regasm
System.Diagnostics.Process.Start(regasmPath, "/codebase """ & componentPath & """")
End If
End If
End Sub
我从原始文章中改变的是RegAsm的路径。由于我的设置是x86,因此RuntimeEnvironnment的目录指向" Microsoft.NET \ Framework ..."路径不是" Framework64"这是打败我的行动的目的(它已经注册为32位COM互操作),所以我尝试获得RegAsm的x64版本并运行它。