Click here to Skip to main content
15,897,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a vb.net windows application. It has a form with a Status Bar that is used to provide the user with processing status (e.g. "processing record x of x").

I want to call a DLL project that is referenced and will do all the processing. I want the DLL to pass back to the Windows Application Form Status Bar the processing status (e.g. "processing x of x").

However, I do not know how to pass the Forms Name as a reference to the Dll Project.

I've tried this:

Window App:

returnvalue = MyProcess.Start(Me)

DLL Project:

Class Name is MyProcess

Public Function Start(frm as Form) as Boolean

However, in the dll project Form is not recognized. I've tried adding Imports.Windows.System.Form - but can't do that unless I actually add a form.

Help needed. thanx
Posted

BTW, have you added reference to Windows.System.Form in your DLL project?!
[Just a quick guess, more details required to be put in your question]
 
Share this answer
 
As I said in my first post - I have added the Imports.Windows.System.Form in the DLL Project. As a matter of fact, .net would not let me add Imports.Windows.System.Form unless I actually added a form to the dll project - which eventually I did just to get past that step.

To simply try and make this work, I changed the control in the Windows App from a status bar to a Text Box. The full code now reads:

Windows App:

ReturnValue = MyProcess.Start(me)

Dll Project:
Class Name is MyProcess

Imports.Windows.System.Form
'I had to actually add a form to get this Imports entered

Public Function Start(frm as Form) as Boolean

For x = 1 to 1000
frm.TextBox1.Text = x
Next X

Start = True

End Function

In the DLL Project - intellisense underlines TextBox1 as error. I can't get past this step. I can't build the DLL Project because of this error. Therefore this is not working. I have to believe there is some way to do this - simply updating a Windows App Textbox with status from a DLL Project process in .net. I think I am missing something. Appreciate any help/Ideas.
 
Share this answer
 
Here is my latest try. This is passing the value of x back to my Windows App textbox - however only the last x value (1000). I want to get back each x value as its processed. I put the vbcrlf in to see if it will post back each x value. Wondering if BackgroundWorker would be better to use for what I'm looking for.


C++
Window App:

Imports MainDLL

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myMainDll As New MainDLL.Class1

        myMainDll.mytb = Me.TextBox1
        myMainDll.MyProcess()

    End Sub
End Class

Dll Project(MainDll):

Imports System.Windows.Forms
Public Class Class1

    Private m_tb As TextBox
    Public Property mytb() As TextBox
        Get
            Return m_tb
        End Get
        Set(ByVal tbname As TextBox)
            m_tb = tbname
        End Set
    End Property

    Public Function MyProcess() As Boolean
        Dim x As Integer

        For x = 1 To 1000
            m_tb.Text = (x).ToString & vbCrLf
        Next
        MyProcess = True
    End Function
End Class
 
Share this answer
 
from the information that you have given I would approach this differently than the way you are trying.

I have assumed you are processing data in a datatable or something similar and that on your form you have two labels to store the total records to be processed and the current record that you are processing.

If the processing of the each record is intensive I would also look at using threads.

dim ProcessRecordNo as integer = 0
NoRecordsLabel.text = dt.rows.count

for each row as datarow in dt.rows
  ProcessRecordNo +=1
  RecordXofYLabel.text = ProcessRecordNo

  'here you call the dll to do the processing

next
 
Share this answer
 
Rather than using a form as a parameter (and note that your form parameter is a generic form, not the specific form subclass that you're working with in your EXE), have you considered declaring your parameter as status bar or progress bar or whatever object type you're actually trying to update from within the DLL?
 
Share this answer
 
Issue is resolved. Apparently I was making it much harder than it really was. Below is the code for the Windows App and the Main DLL. This was my test, it worked and now I can put it into real action. My Main DLL will actually be processing large XML files into a database. The Windows App will pass to the Main DLL the XML file(s) the user chooses, the database connection variable, a ToolStripStatusLabel for progress update similar to the TextBox update below in my test and a TextBox for error information that might be encountered. Can't wait to test the real thing out.

Window App

VB
Imports MainDLL

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myMainDll As New MainDLL.Class1

        myMainDll.MyProcess(Me.TextBox1)

    End Sub

End Class


Main DLL

VB
Imports System.Windows.Forms

Public Class Class1

    Public Function MyProcess(ByRef m_tb As TextBox) As Boolean
        For x = 1 To 1000
            m_tb.AppendText(x.ToString & Environment.NewLine)
            Application.DoEvents()
        Next

    End Function
End Class
 
Share this answer
 
Comments
Marc A. Brown 8-Oct-10 13:19pm    
Yep, that's what I was trying to say in my answer above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900