DLL插件 [英] DLL Plugin

查看:84
本文介绍了DLL插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助!

我正在将使用VB6开发的软件转换为VB.Net.在某些更改方面,我遇到了一些困难,因为这是最糟糕的情况,我似乎无法正常工作.我在整个互联网上都发现了这种情况,但是我测试的每个选项都失败了.

我有一个VB.Net exe,它基于所选的树节点从表中读取dll和类名,并使用CreateObject()加载dll. dll包含我根据传递的参数调用的形式和函数,并且在退出函数时将值传递回去,在该位置我要么不执行任何操作,要么根据返回的值执行某些操作.这在VB6中效果很好,是应用程序基础架构的核心.下面是代码.在此先感谢.

VB6 exe代码:

Help!!

I am in the process of converting our software that was developed using VB6 to VB.Net. I have had some difficulties with some of the changes bu this has been the worste and I can''t seem to get this working. I have found pieces of this all over the internet but every option I test, fails.

I have a VB.Net exe that reads the dll and class name from a table based on the tree node selected and loads the dll using CreateObject(). The dll contains forms and functions that I call based on the parameters that are passed and, upon exiting a function, passes a value back where I either do nothing or do something based on the returning value. This works great in VB6 and is the core of the applications'' infastructure. Below is the code. Thanks in Advance.

VB6 exe Code:

PDLL = lrsLoad!DLL_ID & "." & lrsLoad!DLL_CLASS

    'use a generic object variable
    Dim objPlugIn As Object
    
    'Variable holds plug-ins response
    Dim strResponse As String
    
    'Call by prog ID. THis can be passed as ANY string whether stored in a database, typed, or Createed in code
    
    'The prog ID has the following format:
    [Project Name].[Class Name]
    Set objPlugIn = CreateObject(PDLL)
    
    'Call the generic entry proceedure
   strResponse = objPlugIn.Edit(sIniFile, sDBPath, sDataSrc, sDataBase, sDBConnType, usus, pwpw, PDPD, ID, APPTYPE, "EDIT", V1, V2)   
    
    If strResponse = "1" And APPTYPE = "M" Then
        frmMain.lsvMain_Click
        Exit Sub
    ElseIf strResponse = "2" And APPTYPE "M" Then
        Exit Sub
    End If


DLL代码(收集信息,打开frmConfig对话框,用户执行功能并选择确定",然后控件返回到exe).


DLL Code (Gathers info, Opens the frmConfig Dialog, the user performs a function and selects OK and the control goes back to the exe)

Public Function Edit(sINIFile As String, sDBPath As String, sDataSrc As String, sDataBase As String, sDBConnType As String, usus As String, pwpw As String, pdpd As String, ID As String, AppType As String, APPEVENT As String, V1 As String, V2 As String

  'Set All Configuration Data
  frmConfig.txtCD = V1
  frmConfig.dtpRecDT = lrsLoad!CTRK_REC_DT
  frmConfig.dtpEstStartDt = lrsLoad!CTRK_EST_START_DT
  frmConfig.dtpStartDt = lrsLoad!CTRK_START_DT
  frmConfig.dtpEstEndDt = lrsLoad!CTRK_EST_COMP_DT
  frmConfig.dtpEndDt = lrsLoad!CTRK_COMP_DT
  frmConfig.dtpRevDt = lrsLoad!CTRK_REV_DT
  frmConfig.Caption = "Configuration Tracking - " & lrsLoad!CTRK_TRACK_ID

  Screen.MousePointer = vbDefault
  frmConfig.Show vbModal

  Edit = ADODataInfo.txtDllResp

Exit Function

推荐答案

VB6代码使用CreateObject创建您在VB6中编写并在计算机上注册的COM类的实例. VB.NET可以做同样的事情,但这不是最佳解决方案.

您要做的实际上是创建一个插件系统.该代码可以扫描目录以查找插件并动态加载它们,并像通过VB6一样通过COM进行操作.

您显然正在寻找的是一个插件框架.您可以在本文 [这一个 [^ ].
The VB6 code uses CreateObject to create an instance of a COM class that you wrote in VB6 and registered on the machine. VB.NET can do the same thing, but it''s not the optimal solution.

What you''re doing is essentially creating a plugin system. The code can scan a directory for plugins and dynamically load them, with going through COM to do it like you had to in VB6.

What you''re apparently looking for is a plug-in framework. You can read up on them in this article[^] and this one[^].


这篇关于DLL插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆