《VB.NET通过VB6 ActiveX DLL调用PowerBasic及FreeBasic动态库》使用的Activex DLL公共对象是需要先注册的。https://blog.csdn.net/weixin_45707491/article/details/132437502?spm=1001.2014.3001.5501

Activex DLL事前注册,一次多用说起来也不是啥大问题,但不能更改到其它文件夹,否则程序找不到会出错,改地方必须先取消注册,然后再注册。

用个简单办法:

每次运行程序时由程序本身注册,每次退出程序时由程序本身取消注册。

那就给项目加个模块:

Module Module1
    Declare Function DllRegisterServer Lib "MBFIE3PBnFB.dll" Alias "DllRegisterServer" () As Long
    Declare Function DllUnregisterServer Lib "MBFIE3PBnFB.dll" Alias "DllUnregisterServer" () As Long
End Module

Application的sub new()中调用函数注册COM组件:

        Public Sub New()
            MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.ApplicationDefined)
            Me.IsSingleInstance = false
            Me.EnableVisualStyles = true
            Me.SaveMySettingsOnExit = True
            Me.ShutdownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
            Dim dReturn As Double
            dReturn = DllRegisterServer()
        End Sub

程序关闭窗体并退出时取消注册:

    Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        Dim dReturn As Double
        dReturn = DllUnregisterServer()
        dReturn = DllUnregisterServer()
        dReturn = DllUnregisterServer()
    End Sub

进入程序注册一次,退出程序取消三次,确保不留痕迹。因为编辑时没有注册,所以提示有红波浪线,但编译后程序运行正常,因为程序运行前会即时注册。

对《VB.NET通过VB6 ActiveX DLL调用PowerBasic及FreeBasic动态库》的改进-LMLPHP

08-24 18:01