将 vb6 标准 exe 转换为 activex exe 的最佳实践是什么?
我有一个遗留的大型 vb6 编辑器,其中包含大量第 3 方库和控件,最近需要将其设置为多线程,以便我可以独立于主编辑器窗体运行其他一些窗体。 基本上,除了通过单击主页上的按钮来运行其他表单之外,这些其他表单和主编辑器之间的通信量最少。
因此,通过大量谷歌搜索,我找到了一种方法,通过将当前应用程序设置为 activex exe 并添加一个设置为全局多用途的类来将当前应用程序转换为多线程应用程序以允许这种情况发生。 现在,在通过调试模式进行编辑和测试时,我发现当我退出时,有时会发生很多奇怪的崩溃。
'main.frm - button click call
'On the button click, create a new object
Set obj = CreateObject("MyApp.clsThread")
Call obj.NewThread
'clsThread
' Create a new form and load it to run on a new thread
Public Sub NewThread()
Dim frm As Object
Set frm = New frmDogbert
Load frmDogbert
frm.show
Set frm = Nothing
End Sub
那么,当我这样做时,我绝对必须知道什么,即潜在的问题等?因为我担心该应用程序似乎变得更加不稳定。 或者有更好的方法来做到这一点吗?
更新:
我没有强行将我的应用程序破解为伪多线程应用程序,而是听取了这里好人的建议,并将组件重构为标准 exe,并将我的应用程序恢复为标准 exe 并通过 shell 调用它们。 效果很好:)
谢谢
i have a legacy massive vb6 editor with plenty of 3rd party libraries and controls and recently there is a need to set it up to make it multi thread so i can run a few other forms independently from the main editor form. Basically there's minimum communication between these other forms and the main editor except for running the other forms on a click of a button from the main page.
So from a lot of googling i found a method which converts the current app into a multi threading one by setting it up as an activex exe and adding a class set to global-multi-use to allow this to happen. Now while doing editing and testing via debugging mode, i found that when i exit a lot of weird crash will happen sometimes.
'main.frm - button click call
'On the button click, create a new object
Set obj = CreateObject("MyApp.clsThread")
Call obj.NewThread
'clsThread
' Create a new form and load it to run on a new thread
Public Sub NewThread()
Dim frm As Object
Set frm = New frmDogbert
Load frmDogbert
frm.show
Set frm = Nothing
End Sub
So what do i absolutely must know when i do this,i.e. potential problems,etc?, as i'm fearing that the app seems to be getting more unstable. Or is there a better way to do this?
Updates:
Instead of forcefully hacking my app into a pseudo multithreading app, i've taken the advice from the good people here and refactor out the component into standard exe and reverted back my app to a standard exe and call them via shell. Works beautifully :)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Visual Basic 6 本身并不是多线程。 ActiveX EXE 和 ActiveX DLL 之间的多任务行为差异仅在从另一个 VB6 EXE 引用时才会显现出来。 从 ActiveX EXE 中定义的全局多用途类实例化的对象在其自己的上下文中运行。 从 ActiveX DLL 实例化的对象在调用 EXE 的上下文中运行。
现在,多线程可以侵入 VB6,但它非常敏感,并且有很多禁忌(例如,您不能使用 IDE 中的停止按钮来停止调试会话,否则程序将崩溃)。
ActiveX EXE 的优点在于生成一个单独但相关的实例,该实例可以单独运行而无需停止主程序。 根据您的简短描述,我想说您最好的办法是保持 EXE 不变,但将更多的表单/模块/类保存到单独的 EXE 中,并让原始 EXE 引用 ActiveX EXE。
请注意,您不必编译为 .EXE,您可以将扩展名更改为 .DLL,它仍然是一个 activeX EXE。 这样做是为了防止用户错误地自行运行 ActiveX EXE。
Visual Basic 6 is not multi threading in of itself. The difference in the multi-tasking behavior between a ActiveX EXE and a ActiveX DLL is only apparent when referenced from another VB6 EXE. Objects instantiated from a Global Multi-Use Class defined in a ActiveX EXE run in their own context. Object instantiated from a ActiveX DLL are run in the context of the calling EXE.
Now multi-threading can be hacked into VB6 but it is very touchy and has a lot of don't (for example you can't use the stop button in the IDE to stop a debugging session or the program will crash).
What a ActiveX EXE is good is for spawning a separate but related instance that can run separately without halting the main program. Based on your brief description I would say your best best is to keep your EXE as is but more the forms/modules/classes to a separate EXE and have the original EXE reference the ActiveX EXE.
Note that you don't have to compile down to .EXE you can change the extension to .DLL and it is still a activeX EXE. You do this so that the user doesn't mistakely run the ActiveX EXE by itself.
你能稍微澄清一下这个问题吗? 我不明白为什么需要多线程? 为什么不能只显示非模式表单,那么它们将同时可见并响应。 除非您在主窗体中始终运行一些后台处理,否则从您的问题来看这听起来不太可能,因为它会锁定主窗体以及其他窗体。
Melaos 说: 嗯,主编辑器 frm 是这里的主要内容,我需要允许用户运行附加表单来执行其他一些操作,例如将内容上传到我们的服务器并将视频文件转换为其他格式。 而这些形式使用shell来调用其他exe。 而且运行时间需要相当长的时间。
在这种情况下,我建议将其他形式制作成单独的 EXE,而不是使用多线程,因为这很困难。 您说从主窗体到子窗体几乎没有通信 - 它只是显示它们。 因此,您甚至不需要将子窗体制作为 ActiveX EXE。 只需将它们设为标准 EXE 并从主窗体中对它们进行脱壳即可。
Can you clarify the question a bit? I don't understand why it needs to be multi-threaded? Why can't you just display the forms non-modal, then they will all be visible and responsive at the same time. Unless you have some background processing operating all the time in your main form, which sounds unlikely from your question as it would lock up the main form as well as the others.
Melaos says: Well the main editor frm is the main thing here and I need to allow the user to run additional forms to do some other stuff like uploading things to our server and convert video files to other formats. And these forms use shell to call other exes. And the running time takes quite a while.
In that case I recommend making the other forms into separate EXEs rather than use multithreading, which is difficult. You say there's little communication from the main form to the subforms - it just shows them. Therefore you don't even need to make the subforms ActiveX EXEs. Just make them standard EXEs and shell them from the main form.