在调用dll时打开表单。 [英] Opening a form when calling a dll.

查看:55
本文介绍了在调用dll时打开表单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的我正在开展一个项目,要求我们提交dll用于通话。



目前所有的调用都来自用VB6编写的exe文件,是的,我们正在升级。我一直在玩创建dll,并且实际上只是为了练习而做基本的事情。



实现是当前程序调用其他表单为不同的任务打开。选择该任务时,需要调用不同的表单。



我创建了一个小程序,它只是做数学函数。主窗体允许您选择要执行的数学函数。调用另一个允许您输入数据的表单。单击一个按钮调用DLL来执行该功能。很简单。



我想做的是让主窗体调用dll,它将打开输入表单并进行计算。这是关于我们最终将要为其他程序做些什么的想法。



来自主表单的电话:



Okay I am working on a project that is requiring us to submit dll's for calls.

Currently all the calls are made from the exe file that was written in VB6, yes we are upgrading. I have been playing around with creating dll's and actually have that part of it down just doing basic things for practice.

The realization is that the current program calls other forms to open for the different tasks. the different forms need to be called when that task is selected.

I have created a small program, it just does math functions. The main form lets you select what math function you want to perform. that calls another form that lets you enter the data. clicking on a a button calls the dll to perform the function. pretty simple.

What I would like to do is have the main form call the dll which will open the form for input and do the calculation. Which is on the idea of what we are going to have to do for the other program eventually.

The call from the Main form:

Private Sub btnAdd_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        frmadd.ShowDialog() ' calls the add 
    End Sub





输入数据表格:输入2个数字按钮点击添加(这是调用dll的地方)他们和关闭表单的关闭按钮。





Inputting data form: Input 2 numbers button click adds(this is where the dll is called) them and a close button to close form.

Imports Multiply1
Public Class frmadd

Private Sub frmadd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim Adding As New Multiply1.MyAdd

        txtAddAns.Text = Adding.AddMyValues(CDbl(txtbox1.Text), CDbl(txtbox2.Text)).ToString
    End Sub

    Private Sub btndone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndone.Click
        Me.Close()

    End Sub
End Class





这个代码为dll





This the code for dll

Public Class MyAdd

    Public Function AddMyValues(ByVal Value1 As Double, ByVal Value2 As Double)

        Dim Result As Double

        Result = Value1 + Value2

        Return Result

    End Function

End Class





我读过几篇不同的文章但他们没有做的一件事就是展示如何创建表单然后让dll调用它。也许我错过了一些简单但我无法看到它。



Scott



I have read several different articles but the one thing they don't do is show how to create the form then have have the dll call it. Maybe I am missing something easy but I just can't see it.

Scott

推荐答案

如果表单在应用程序中定义,然后您无法直接从DLL创建它。



另一方面,您的代码似乎调用DLL函数从第二个表单执行添加,直接支持,只要您添加适当的引用即可应用程序项目。



顺便说一句,DLL可以直接创建它定义的表单或者它直接引用的程序集中的任何公共表单。



您还可以通过将信息传递给DLL(接口,回调函数...)或使用反射或其他方法(如 Unity应用程序块 [ ^ ]
If the form is defined in the application, then you cannot directly create it from the DLL.

On the other hand, your code seem to call the DLL function to do the addition from the second form which is directly supported provide that you add the appropriate reference to your application project.

By the way a DLL can directly create forms it defined or any public forms in assemblies it reference directly.

And you can also indirectly create forms by passing information to the DLL (interface, callback function...) or by using reflection or some other means like Unity application block[^]


好吧,因为我得到了一个检查,并且不得不对这个问题进行更广泛的研究,这不是一个很容易回答,但毕竟我不得不进行的研究会认为这里有一个人可以来找你p答案。



答案是,似乎无法调用dll并打开dll中调用的表单。表单可以是另一种形式甚至是dll但dll不能显示表单。不是我发现的。
Well since I got a down check and have had to do even more extensive research on this question and it wasn't an easy answer to find but after all the research I have had to perform one would think that 1 person here could come up with the answer.

The answer is it doesn't appear to be possible to call a dll and open an form called in the dll. A form can another form or even a dll but the dll can't show a form. Not from what I have found out.


这篇关于在调用dll时打开表单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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